ERR5RS Record Syntax (reduced)
John Cowan, Will Clinger
This SRFI is currently in final status. Here is an explanation of each status that a SRFI can hold. To provide input on this SRFI, please send email to
firstname.lastname@example.org. To subscribe to the list, follow these instructions. You can access previous messages via the mailing list archive.
This SRFI is a reduced version of the SRFI 99 syntactic layer
that can be implemented with syntax-rules without requiring
low-level macros. Like SRFI-99's syntax layer, it is backward
compatible with the
define-record-type macro from
or R7RS-small. It is forward compatible with
No issues at present.
Implementations of Scheme that provide only
macros cannot currently implement the syntactic layer of SRFI 99. Three
features make a
syntax-rules implementation impossible:
#t as the constructor name,
which is equivalent to specifying the type name prefixed by
#tas the predicate name, which is equivalent to specifying the type name suffixed by ?.
Specifying a field spec as either an identifier or a parenthesized
identifier, which are equivalent to specifying an accessor name equivalent
to the type name followed by
- followed by the field name,
and (in the latter case) a mutator name equivalent to the type name
- followed by the field name followed by
All of these features violate macro hygiene by introducing identifiers
into the code which don't appear in the macro call, which is why
syntax-rules will not suffice to implement them.
However, they are only notational and can be replaced by explicit equivalents in user code.
By eliminating them, as in this SRFI, a pure
implementation such as the sample implementation can provide all the
other features of SRFI 99's syntactic layer.
The syntactic layer consists of R7RS define-record-type extended with single inheritance and mechanisms for abstract record types.
The syntax of a record-type definition is:
<definition> -> <record type definition> <record type definition> -> (define-record-type <type spec> <constructor spec> <predicate spec> <field spec> ...) <type spec> -> <type name> -> (<type name> <parent>) <constructor spec> -> #f -> <constructor name> -> (<constructor name> <field name> ...) <predicate spec> -> #f -> <predicate name> <field spec> -> (<field name> <accessor name>) -> (<field name> <accessor name> <mutator name>) <parent> -> <expression> <type name> -> <identifier> <constructor name> -> <identifier> <predicate name> -> <identifier> <accessor name> -> <identifier> <mutator name> -> <identifier> <field name> -> <identifier>
The semantics of a record type definition is the same as in R7RS-small (or SRFI 9, except that record types are generative). The record type definition macro-expands into a cluster of definitions that:
A record type definition extends R7RS-small with the following additional options:
When a constructor spec is of the form
(<constructor name> <field name> ...):
define-record-typeform, or any of its ancestors' field names.
These are not explicit in SRFI 99's syntactic layer section, but can be inferred from its description of the procedural layer.
The sample implementation, a single-file R7RS library, is in the code repository of this SRFI. It was written by Will Clinger. It is built on top of the procedural parts of SRFI 99.
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 "AS IS", 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.