[Top][All Lists]

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

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

From: Will M Farr
Subject: Re: [Chicken-users] Explicit Renaming Macros Help/Tutorial?
Date: Sun, 7 Jun 2009 19:35:22 -0400


I don't have a good answer for a tutorial on explicit renaming macros, but I do notice that there is a mistake in the code you're using even with a fully-functional syntax-rules implementation:

On Jun 7, 2009, at 7:26 PM, Jack Trades wrote:
(define-syntax def
  (syntax-rules (*args)
    ((def (name arg ((opt val) ...) *args) body ...)
(define (name arg #!optional (opt val) ... #!rest args) body ...))))

You use 'args in the output of the macro, but this does not appear in the pattern. Therefore it's a "free" variable, and, according to syntax-rules rules, refers to the binding for 'args that was in effect when the 'def syntax was defined. Thus, you get an "args is unbound" error for the test:

(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.

If you want to produce the symbol 'args in the context of the body of the def form, you will need to use explicit renaming, syntax-case, or some other un-hygienic macro system. (The reason is that you are introducing a name, 'args, which does not come into the macro through parts of the pattern, but you want it to refer to bindings that do come in as part of the pattern. That is the definition of "breaking hygiene.")

Good luck with your search for an ER-macro tutorial.


Attachment: PGP.sig
Description: This is a digitally signed message part

reply via email to

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