[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
proposals for R5RS (sorry)
I realize that it is too late to propose major new features for
R5RS, but I want the R5RS to fix two bugs in the design of the
high-level macro system described in the appendix to R4RS:
1. Many macro-defining macros that I have wanted to write do
not work in the R4RS system because ellipses in the macro
to be defined are expanded when the defining macro is
transcribed. (An example appears below.)
2. The QUASIQUOTE macro cannot be written in the high-level
macro system of R4RS because it does not support vectors
as full-fledged patterns.
This message proposes two fixes, one for each bug, that I would
like to see adopted by the R5RS. Both fixes consist of tweaks
to the syntax of patterns and templates, together with whatever
prose is necessary to explain the semantics of those tweaks.
Although these tweaks are new features, they do not add any new
procedures or expression types so I think it is fair to consider
them bug fixes.
Vector patterns were in fact a part of a draft of the R4RS
appendix but were excluded because I feared that they would
encourage weird syntaxes using vectors, and it seemed more
conservative to leave them out of the R4RS and to add them
back later if we found that they were needed. I did not
realize at the time that they were needed by QUASIQUOTE.
Indeed I don't think many of us realized at the time that
the high-level macro system has enough power to define macros
as complex as QUASIQUOTE.
William Clinger
PROPOSAL 1: An escape syntax for templates.
Add the production
<template> --> (::: <template>)
If a <template> of the form (::: <template>) occurs as a subtemplate
on the right side of a <syntax rule>, then all ellipses that occur
within the <template>, and all occurrences of the ::: symbol itself,
will be transcribed as if they were ordinary identifiers. This
allows a macro to expand into expressions that contain ellipses, or
ellipses escaped by the ::: symbol. Pattern variables that occur
within the <template> will still be expanded.
The following example would not work without the ::: escape, because
the ellipses that occur within the DO-AUX macro would be interpreted
when the DO macro is transcribed, causing an error.
(define-syntax do
(syntax-rules ()
((do (?bindings0 ...) ?clause0 ?body0 ...)
(letrec-syntax
((do-aux
(::: (syntax-rules ()
((do-aux () ((?name ?init ?step) ...) ?clause ?body ...)
(letrec ((loop (lambda (?name ...)
(cond ?clause
(else
(begin ?body ...)
(loop ?step ...))))))
(loop ?init ...)))
((do-aux ((?name ?init ?step) ?todo ...)
(?bindings ...)
?clause
?body ...)
(do-aux (?todo ...)
(?bindings ... (?name ?init ?step))
?clause
?body ...))
((do-aux ((?name ?init) ?todo ...)
(?bindings ...)
?clause
?body ...)
(do-aux (?todo ...)
(?bindings ... (?name ?init ?name))
?clause
?body ...))))))
(do-aux (?bindings0 ...) () ?clause0 ?body0 ...)))))
PROPOSAL 2: Vectors as patterns.
Add the productions:
<pattern> --> #(<pattern>*)
| #(<pattern>* <pattern> <ellipsis>)
<template> --> #(<template element>*)
Delete the production:
<pattern datum> --> <vector>