[r6rs-discuss] Why can ... and _ not be literals?

From: David Van Horn <dvanhorn>
Date: Tue, 26 Jun 2007 14:55:48 -0400 (EDT)

On Tue, 26 Jun 2007, David Van Horn wrote:
> On Sun, 24 Jun 2007, AndrevanTonder wrote:
> > There are advantages in [allowing ... as a literal], 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.
>
> Agreed.

Restrictions on literals also seems to preclude macros such as Oleg
Kiselyov's id-eqv?? (described in his article on c.l.s "How to write
symbol? with syntax-rules").

   http://groups.google.com/group/comp.lang.scheme/msg/01681128dee9fd5d

   For a macro id-eqv??, the identifiers are equivalent if they refer to
   the same binding (or both identifiers are unbound and have the same
   spelling). Thus macro id-eqv?? can find two identifiers equivalent even
   if they have different colors.

   (define-syntax id-eqv??
     (syntax-rules ()
       ((id-eqv?? a b kt kf)
         (let-syntax
           ((test (syntax-rules (a)
                 ((test a) kt)
                 ((test x) kf))))
           (test b)))))

In the case of (id-eqv?? ... ... 'yes #f), the macro instance is
transcribed into a let-syntax expression whose syntax-rules subexpression
includes ... in the list of literals, which is a syntax violation in the
current draft (R5.95RS) and "an error" in R5RS. So restricting the
allowable literals in syntax-rules makes it impossible to write macro
generating macros parameterized by arbitrary literals.

David
Received on Tue Jun 26 2007 - 14:55:48 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC