Implement ellipsis escaping, as per R7RS #711
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Section 4.3.2 of R7RS (page 23 of the PDF), it is said that a can be one of:
(<element> ...)
(<element> <element> ... . <template>)
(<ellipsis> <template>)
#(<element> ...)
Number (3) is an escaping pattern. Inside ir, ellipses are treated like a symbol, and not like the syntax-rules ellipsis. And that template must have only two elements.
(<ellipsis> <template>)
should be transformed into
<template>
but protecting the ellipses (they have no special meaning there).
So
but the ellipses on the right side are ignored by
syntax-rules
.The implementation is:
(... a b)
)(mbe:subst-ellipsis expr ell new-ell)
will go throughexpr
, and substitute only the sublists that match the form of an escaping ellipsis, doing the appropriate transform. However, inside the subtemplate, the ellipses will be transformed into a symbol which is internal to MBE, produced by gensym (so no match will be possible). This is infind-clause
find-clause
syntax-rules
calls the internal MBE procedurecheck-wrong-ellipsis-escape
let-syntax
also does that.Some tests, including the example in R7RS, were added.
Fix #704