[r6rs-discuss] Why can ... and _ not be literals?
On Sun, 24 Jun 2007, David Van Horn wrote:
> It is compatible in the case of ellipsis; R5RS (4.3.2) states "It is an
> error for ... to appear in <literals>." As far as I can tell, underscore
> is not distinguished in any way (so this is an incompatible change and
> legacy code will break in this case).
My error. Even more embarrassingly, trying to use ... as a literal in my
own expander does not work either. There are advantages in doing so, though.
Here is the germ of a simple pattern matcher (not tested):
(define-syntax matches?
(syntax-rules (...)
((_ x ())
(null? x))
((_ x (y ...))
(and (list? x)
(forall? (lambda (z) (matches? z y))
x)))
((_ x (y . z))
(and (pair? x)
(matches? (car x) y)
(matches? (cdr x) z)))
((_ x id) #t)))
(matches? '((1 2) (3 4 5))
((x ...) ...)) ==> #t
It seems a pity to force someone to use syntax-case for this kind of thing
when syntax-rules would otherwise be adequate.
Andre
Received on Sun Jun 24 2007 - 21:40:28 UTC
This archive was generated by hypermail 2.3.0
: Wed Oct 23 2024 - 09:15:01 UTC