For Development HEAD DRAFTSearch (procedure/syntax/module):

Next: , Previous: , Up: Library modules - Utilities   [Contents][Index]

12.90 util.record - SLIB-compatible record type

Module: util.record

This module provides a Guile and SLIB compatible record type API. It is built on top of Gauche’s object system.

See also gauche.record - Record types, which provides a convenience macro define-record-type.

Function: make-record-type type-name field-names

{util.record} Returns a new class which represents a new record type. (It is what is called record-type descriptor in SLIB). In Gauche, the new class is a subclass of <record> (see gauche.record - Record types).

type-name is a string that is used for debugging purposes. It is converted to a symbol and set as the name of the new class. field-names is a list of symbols of the names of fields. Each field is implemented as a slot of the new class.

In the following procedures, rtd is the record class created by make-record-type.

Function: record-constructor rtd :optional field-names

{util.record} Returns a procedure that constructs an instance of the record type of given rtd. The returned procedure takes exactly as many arguments as field-names, which defaults to '(). Each argument sets the initial value of the corresponding field in field-names.

Function: record-predicate rtd

{util.record} Returns a procedure that takes one argument, which returns #t iff the given argument is of type of rtd.

Function: record-accessor rtd field-name

{util.record} Returns an accessor procedure for the field named by field-name of type rtd. The accessor procedure takes an instance of rtd, and returns the value of the field.

Function: record-modifier rtd field-name

{util.record} Returns a modifier procedure for the field named by field-name of type rtd. The modifier procedure takes two arguments, an instance of rtd and a value, and sets the value to the specified field.

(define rtd (make-record-type "my-record" '(a b c)))

rtd ⇒ #<class my-record>

(define make-my-record (record-constructor rtd '(a b c)))

(define obj (make-my-record 1 2 3))

obj ⇒ #<my-record 0x819d9b0>

((record-predicate? rtd) obj)  ⇒ #t

((record-accessor rtd 'a) obj) ⇒ 1
((record-accessor rtd 'b) obj) ⇒ 2
((record-accessor rtd 'c) obj) ⇒ 3

((record-modifier rtd 'a) obj -1)

((record-accessor rtd 'a) obj) ⇒ -1

Next: , Previous: , Up: Library modules - Utilities   [Contents][Index]

For Development HEAD DRAFTSearch (procedure/syntax/module):