chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Explicit Renaming Macros Help/Tutorial?


From: Jack Trades
Subject: Re: [Chicken-users] Explicit Renaming Macros Help/Tutorial?
Date: Sun, 7 Jun 2009 19:26:30 -0400

On Sun, Jun 7, 2009 at 7:08 PM, John Cowan <address@hidden> wrote:
Jack Trades scripsit:

> I managed something similar in Chicken 3 + syntax-case (with an extra level
> of parens around optional arguments) but cannot figure how to do the same in
> Chicken 4.  I can't find any documentation (at least that I can understand)
> on explicit renaming macros.  The Chicken 3 code I had is below, but it
> doesn't work in 4.
>
> (use syntax-case)
> (define-syntax def
>   (syntax-rules (*args)
>     ((def (name arg ... ((opt val) ...) *args) body ...)
>       (define (name arg ... #!optional (opt val) ... #!rest args) body
> ...))))

If your macro is defined in syntax-rules, there should be no need to use
explicit renaming at all.  The above code should just work in Chicken
4 after you remove the "(use syntax-case)".  If not, there is a bug in
the Chicken 4 implementation of syntax-rules, which would not surprise
anybody too much.


Segment matching is not implemented in the Chicken 4 implementation of syntax-rules (I get an error saying just that).  When this question came up a while back Felix told me that it would not be trivial to implement and suggested I use explicit renaming.

If I remove the '...' after arg like so...

(define-syntax def
  (syntax-rules (*args)
    ((def (name arg ((opt val) ...) *args) body ...)
      (define (name arg #!optional (opt val) ... #!rest args) body ...))))

and test it with...

(def (a x ((y 2) (z 3)) *args) (apply + (append (list x y z) args)))

Besides the fact that it only works for a single required argument (and I'd have to write 30+ patterns to support only up to 10 arguments), I get the following error about 'args' being unbound.

Warning: the following toplevel variables are referenced but unbound:
  args (in a)

Jack Trades

reply via email to

[Prev in Thread] Current Thread [Next in Thread]