Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.
|Page Name:||record properties|
Record properties are a way to attach arbitrary information to record types and/or instances. The interface to record properties has three parts:
- The module srfi-99-records-inspection exports the procedure make-rtp that creates new record property accessors.
- A property is attached to a record type using the special keyword argument #:property of make-rtd, followed by a property accessor generated by make-rtp and a property value.
- A property is accessed by calling the property accessor generated using make-rtp on a record instance and/or a record type descriptor.
Creating Record Property Accessors
A record property accessor is created with a call to make-rtp or using the shorthand syntax define-record-property:
(make-rtp [default any? #f]) => procedure? (define-record-property name [default any? #f])
The result is a procedure that can be used to access the new record property with the given default value.
Accessing Record Properties
A record property accessor accepts two arguments, some value and a record type descriptor:
(rtp [v any?] [rtd rtd? (record-rtd v)]) => any?
The record type descriptor can be omitted if the value passed as the first argument is an instance of a transparent record.
The accessor looks up the property value for the given record type (or any of its parents) when it is called. If it doesn't find a value it resorts to the default specified when the record property was created. The value is then applied to v to obtain the result of the accessor call.
Default property values passed to make-rtp which are not procedures are implicitly converted to procedures constantly returning the default value.
Property values passed to make-rtd which are not procedures or symbols are implicitly converted to constant generators like property default values. Symbols are implicitly converted to accessor procedures for the field of the same name in the new record type to which the property is attached.
Listing Record Properties
The record properties attached directly to a type descriptor can be retrieved using
(rtd-properties [rtd rtd?]) => (listof procedure?)
and all record properties attached to a type descriptor or its parents can be retrieved using
(rtd-all-properties [rtd rtd?]) => (listof procedure?)