SRFI-99

Update of "record properties"
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: 13594f9d2181f6b4db9d99f89c34aa23eb0913ce
Page Name:record properties
Date: 2015-02-06 01:23:28
Original User: murphy
Parent: 12d5ab155acdec6486aff19b8788b82231fd0115
Content

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:

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?)