Title

ERR5RS Record Syntax (reduced)

Author

John Cowan, Will Clinger

Status

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 srfi-131@nospamsrfi.schemers.org. To subscribe to the list, follow these instructions. You can access previous messages via the mailing list archive.

Abstract

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 SRFI 9 or R7RS-small. It is forward compatible with SRFI 99.

Issues

No issues at present.

Rationale

Implementations of Scheme that provide only syntax-rules macros cannot currently implement the syntactic layer of SRFI 99. Three features make a syntax-rules implementation impossible:

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 syntax-rules implementation such as the sample implementation can provide all the other features of SRFI 99's syntactic layer.

Specification

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> ...):

These are not explicit in SRFI 99's syntactic layer section, but can be inferred from its description of the procedural layer.

Implementation

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.

Copyright

Copyright (C) John Cowan, Will Clinger (2015). 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 "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.


Editor: Arthur A. Gleckler