[plt-scheme] define-syntax question

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jun 26 22:51:42 EDT 2003

On Jun 26, Michael Vanier wrote:
> I'm trying to come up with a scheme equivalent for a restricted
> version of common lisp's "label" construct, but I'm getting an error
> I don't understand.  Here is my code:
>   (define-syntax label
>     (syntax-rules ()
>       (((_ f (lambda (p1 p2 ...) e)) a1 a2 ...)
>        (letrec ((f (lambda (p1 p2 ...) e)))
>          (f a1 a2 ...)))))

Looks like a case of bad parens, shouldn't that be

  (define-syntax label
    (syntax-rules ()
      ((_ f (lambda (p1 p2 ...) e) a1 a2 ...)
       (letrec ((f (lambda (p1 p2 ...) e)))
         (f a1 a2 ...)))))


Even that is very likely not right -- do you really want to have a
`lambda' as part of the pattern?  If so, you should add it to the
first syntax-rules argument.  But that doesn't make much sense, so it
is probably better to match on all values:

  (define-syntax label
    (syntax-rules ()
      ((_ f func a1 a2 ...)
       (letrec ((f func))
         (f a1 a2 ...)))))

but that doesn't look like something useful which gets back to the
question of what exactly is CL's `label'?  AFAIK, it doesn't have one.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.