Title

Splicing binding constructs for syntactic keywords

Author

Marc Nieper-Wißkirchen

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

Abstract

Splicing binding constructs for syntactic keywords are versions of let-syntax and letrec-syntax that can be used in a definition context in the same way as begin.

Rationale

The R7RS defines two binding constructs for syntactic keywords, namely let-syntax and letrec-syntax. Both are equivalent to their R5RS versions and are expressions.

The R6RS versions of let-syntax and letrec-syntax are equivalent to the R5RS/R7RS version when they are not in a definition context. In a definition context, however, the R6RS versions splice their body forms in the enclosing definition context.

In some sense, the R6RS splicing versions are more fundamental than the R5RS/R7RS non-splicing versions as one can easily define the non-splicing versions by way of a syntax-rules macro in terms of the splicing versions. Moreover, the non-splicing versions can also be defined by way of a syntax-rules macro in terms of the local define-syntax.

On the other hand, the splicing versions cannot be defined through the non-splicing versions or define-syntax.

The usefulness of the splicing versions seems to be non-controversial. For example, SRFI 148's em syntax would become unnecessary.

Thus, this SRFI proposes splicing versions of let-syntax and letrec-syntax for R7RS under a different name. Note, however, that, in some corner cases, the splicing versions cannot be a drop-in replacement for the non-splicing forms (only that the non-splicing forms can be defined as derived syntax in terms of the splicing forms).

Examples

The following examples show the difference between the non-splicing and splicing behavior.

This expression evaluates to let-syntax:

(let ((x 'let-syntax))
  (let-syntax ()
    (define x 'splicing-let-syntax)
    #f)
  x)

This expression evaluates to splicing-let-syntax:

(let ((x 'let-syntax))
  (splicing-let-syntax ()
    (define x 'splicing-let-syntax)
    #f)
  x)

For more examples, see the test suite that comes bundled with this specification.

Specification

Syntax

(splicing-let-syntax ((〈keyword〉 〈transformer spec〉) ...) 〈form〉 ...)

Like (let-syntax ((〈keyword〉 〈transformer spec〉) ...) 〈form〉 ...) except that in a definition context, the forms 〈form〉 ... are spliced into the enclosing definition context (in the same way as for begin).

Note: The R6RS version is a bit more restricted. There, in a definition context, the forms 〈form〉 ... all have to be definitions and, in an expression context, the forms 〈form〉 ... all have to expressions.

(splicing-letrec-syntax ((〈keyword〉 〈transformer spec〉) ...) 〈form〉 ...)

Like (letrec-syntax ((〈keyword〉 〈transformer spec〉) ...) 〈form〉 ...) except that in a definition context, the forms 〈form〉 ... are spliced into the enclosing definition context (in the same way as for begin).

Note: The R6RS version is a bit more restricted. There, in a definition context, the forms 〈form〉 ... all have to be definitions and, in an expression context, the forms 〈form〉 ... all have to expressions.

Implementation

A portable R7RS implementation of the binding constructs described here is not possible.

The splicing binding constructs as described here are at least provided by Chibi Scheme, Chez Scheme, and Racket.

A Chibi Scheme implementation (.tgz, Github) together with a SRFI 64 test suite is bundled with this specification.

Acknowledgements

The constructs described here aren't new but go back to the R4RS/R5RS (in the non-splicing version) and the R6RS (in the splicing version). Thanks go to the editors of the (revised) reports on the algorithmic language Scheme.

Copyright

Copyright © Marc Nieper-Wißkirchen (2020).

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 (including the next paragraph) 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