SRFI-99
Author
Repository
https://chust.org/repos/chicken-srfi-99
Requirements
None
Provided Modules
The extension consists of a single library, srfi-99, that provides a number of public modules.
srfi-99
A convenience module that re-exports the bindings from all the other modules so that
(import srfi-99)
works as expected.
srfi-99-records
A convenience module that re-exports the bindings from all the other srfi-99-records-... modules.
srfi-99-records-procedural
The procedural interface to record type descriptors.
[procedure] (make-rtd NAME FIELDS [[#:parent] PARENT #f] [#:uid UID (gensym NAME)] [#:sealed SEALED? #f] [#:opaque OPAQUE? #f] [#:property RTP VALUE] ...)Create a new record type descriptor.
[procedure] (rtd? V)Test whether V is a record type descriptor.
[procedure] (rtd-constructor RTD [FIELDS])Obtain a constructor procedure for records of the type described by RTD, optionally restricting the FIELDS to be initialized.
[procedure] (rtd-predicate RTD)Obtain a predicate procedure for records of the type described by RTD.
[procedure] (rtd-accessor RTD NAME)Obtain an accessor procedure for the field called NAME in records of the type described by RTD. If the field is mutable, the accessor procedure has an attached SRFI-17 setter.
[procedure] (rtd-mutator RTD NAME)Obtain a mutator procedure for the mutable field called NAME in records of the type described by RTD.
srfi-99-records-inspection
Access to reflective information about records.
[procedure] (record? V)Test whether V is some kind of record.
[procedure] (record-rtd V)Obtain the record type descriptor corresponding to V's type or return #f if V is not an instance of a transparent record type.
[procedure] (rtd-name RTD)Determine the descriptive name of a record type.
[procedure] (rtd-uid RTD)Determine the unique identifier used to tag instances of a record type.
[procedure] (rtd-sealed? RTD)Test whether a record type is sealed and cannot have subtypes.
[procedure] (rtd-opaque? RTD)Test whether a record type is opaque and cannot be extracted from instances using record-rtd.
[procedure] (rtd-parent RTD)Determine the parent type descriptor of RTD.
[procedure] (rtd-field-names RTD)Compute a vector of fields defined directly by RTD.
[procedure] (rtd-all-field-names RTD)Compute a vector of fields defined by RTD or its supertypes.
[procedure] (rtd-field-mutable? RTD NAME)Test whether the field called NAME in records of type RTD is mutable.
[procedure] (make-rtp [DEFAULT #f])Create a new record property accessor.
[procedure] (rtd-properties RTD)Compute a list of record properties attached directly to RTD.
[procedure] (rtd-all-properties RTD)Compute a list of all record properties attached to RTD or its supertypes.
srfi-99-records-syntactic
Syntactic sugar to facilitate the definition of record types.
[syntax] (define-record-type (RTD OPTION ...) CONSTRUCTOR PREDICATE FIELD ...)[syntax] (define-record-type RTD CONSTRUCTOR PREDICATE FIELD ...)
Defines a new record type RTD, optionally passing a set of OPTIONs to make-rtd. The record has fields described by the given FIELD specifications.
If CONSTRUCTOR is not #f, a constructor procedure for the new record type is defined using define-record-constructor, if PREDICATE is not #f a predicate procedure for the new record type is defined using define-record-predicate.
Accessors and mutators for the record type's fields are defined using define-record-field.
[syntax] (define-record-constructor RTD (NAME FIELD ...))[syntax] (define-record-constructor RTD NAME)
[syntax] (define-record-constructor RTD #t)
Defines NAME as a constructor procedure for instances of RTD, optionally restricting the set of initialized FIELDs.
If the only argument is #t, the name is formed by prepending make- to RTD.
[syntax] (define-record-predicate RTD NAME)[syntax] (define-record-predicate RTD #t)
Defines NAME as a predicate procedure for instances of RTD.
If the only argument is #t, the name is formed by appending ? to RTD.
[syntax] (define-record-field RTD (NAME ACCESSOR MUTATOR))[syntax] (define-record-field RTD (NAME))
[syntax] (define-record-field RTD (NAME ACCESSOR))
[syntax] (define-record-field RTD NAME)
Defines accessor and possibly mutator procedures for the field NAME in instances of RTD.
If the accessor name is not specified (in the second or fourth form), it is formed by appending RTD, - and NAME. If the mutator name is not specified (in the second form), it is formed by appending RTD, -, NAME and -set!.
[syntax] (define-record-property RTP [DEFAULT])Defines a new record property accessor RTP, optionally passing a DEFAULT to make-rtp.
[syntax] (define-record-printer (RTD . ARGS) . BODY)[syntax] (define-record-printer RTD EXPR)
Defines a record printer for direct instances of RTD.
In contrast to the built-in form of this macro provided by the CHICKEN standard library, RTD is interpreted as an identifier bound to a record type descriptor, not as the unique identifier used to tag instances of the record type.
srfi-99-variants
Syntactic sugar to facilitate the definition of variant types.
[syntax] (define-variant-type (RTD OPTION ...) PREDICATE (VARIANT FIELD ...) ...)[syntax] (define-variant-type RTD PREDICATE (VARIANT FIELD ...) ...)
Defines a new record type RTD, optionally passing a set of OPTIONs to make-rtd. The record has no fields.
If PREDICATE is not #f a predicate procedure for the new record type is defined using define-record-predicate.
Variant subtypes of RTD are defined using define-variant-constructor for each VARIANT clause.
[syntax] (define-variant-constructor RTD (VARIANT FIELD ...))Defines a constructor for a new variant subtype of RTD. The subtype has the given immutable FIELDs and the constructor initializes all fields of the record.
The variant subtype is sealed and it is opaque iff RTD is opaque. The UID of the subtype is formed by appending the UID of RTD, - and VARIANT.
The record type descriptor of the variant subtype is attached to the constructor VARIANT as extended procedure data.
[syntax] (variant-case RTD V ((VARIANT FIELD ...) . BODY) [(else . BODY)])The form first ensures that V is indeed an instance of RTD, raising a type error otherwise.
Each VARIANT designates a variant subtype constructor, each FIELD is an identifier to be bound to the corresponding, identically named field of the variant instance. If any of the variant clauses matches the type of V, the corresponding BODY is evaluated and the result is returned from the variant-case form.
If none of the variant clauses match the type of V, the else clause's BODY is evaluated instead. If no else clause is present either, an error is raised indicating that no matching variant was found.
Official Documentation
The SRFI-99 standard document describes the basic functionality. The repository site documents extensions provided by this implementation.
License
Copyright (C) 2011 Thomas Chust <chust@web.de>. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.