[R6RS] syntax-case

Manuel Serrano Manuel.Serrano
Wed Apr 13 02:44:05 EDT 2005


> It's not more powerful for writing syntactic extensions, where one has
> to wrap the output in a syntax form anyway, and it's less powerful there
> since you have to do the mapping explicitly, as your examples illustrate.
> 
> > > (define-syntax let
> > >   (syntax-rules ()
> > >     ((_ ((x e) ...) b1 b2 ...)
> > >      ((lambda (x ...) b1 b2 ...) e ...))))
> > This example should be written:
> >
> >   (match-case x
> >     ((?- ?bindings . ?body)
> >      `((lambda ,(map car bindings) , at body) ,(map cadr bindings))))
> 
> So you have to do the mapping explicitly.  I certainly prefer not to
> have to do so.
Why? Why is it an problem to explicit the mapping? Personally I prefer
the explicit mapping because I prefer to have *all* Scheme for computing
the outputs. To me, this is one of the beauty of Scheme, I can use
Scheme to macro-expand Scheme. This is something I whish I had each time
I write a CPP macro!

> > >  Here's how I might write something similar using syntax-case in Chez Scheme.
> > > 
> > > (define-syntax +
> > >   (lambda (x)
> > >     (import scheme) ; so we can use the built-in +
> > >     (syntax-case x ()
> > >       [(_) 0]
> > >       [(_ x) #'x]
> > >       [(_ x y)
> > >        (and (integer? (datum x)) (integer? (datum y)))
> > >        (+ (datum x) (datum y))]
> > >       [(k x m ...) #'(+ x (k m ...))])))
> > How is the macro expansion prevented from falling into a infinite loop
> > while expansing (+ x y) (due to the last clause that introduces a new
> > (+ ...)). I'm missing something here.
> 
> The (import scheme) makes the built-in + visible, so that the two
> occurrences of + in the syntax-case form refer to the built-in +.
> The macro plucks the keyword identifier out of the input (as k) to use
> for recursion.
I thought that the built-in + was only used in
  (+ (datum x) (datum y))

I still don't understand why the + of 

> > >       [(k x m ...) #'(+ x (k m ...))])))

is not treated as a macro and macro-expansed using the + syntax.

BTW, up to now only Mike's has expressed an opinion about unified
pattern matching, I would really love to read you all in order to
decide is I keep going or if I give up.

-- 
Manuel


More information about the R6RS mailing list