[Top][All Lists]

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

Re: [Chicken-users] macro systems and chicken (long)

From: Alaric Snell-Pym
Subject: Re: [Chicken-users] macro systems and chicken (long)
Date: Sat, 12 Apr 2008 23:11:09 +0100

On 9 Apr 2008, at 11:31 am, felix winkelmann wrote:

(use riaxpander)

(define-macro (my-assert test error)
       `(if (not ,test) (error ,error)))

(define-syntax foo
       (syntax-rules ()
               ((_ x) (let ((tmp x)) (my-assert x "failed")))))

(macroexpand '(let ((x 1)) (foo x)))

In this case the hygiene is actually circumvented: riaxpander
runs before the normal macro-expansion (the expansion of
low-level macros happens afterwards which makes this
work). Referential transparency requires that bindings that
are introduced by a hygienic macro may not be accessible by
name alone by other macros (context is required as well).
(Now, I believe this is the correct wording, but I may be wrong)

I've looked a little deeper into this - riaxpander includes a (re-)
definition of define-macro in terms of syntactic closures. It's still
unhygienic, nonetheless - the synclos provide it with the ability to
do hygienic renaming, which it merrily throws away - but it *is*
converted under the hood to a synclo macro, and expanded along with
all the other synclo macros, rather than in a second phase.

(define-syntax define-macro
  (syntax-rules ()
    ((_ (id . llist) . body)
     (define-syntax id
  (lambda (exp env)
    (apply (lambda llist . body) (cdr exp))))))
    ((_ id expander)
     (define-syntax id
  (lambda (exp env)
    (apply expander (cdr exp))))))))

Now, what would be neat is to hack the define-macro synclo macro a
bit so that it lets you get at the environment object, so that one
can make use of the nice argument list parsing that define-macro
gives you, while using an sc-macro-expander (so things are in the
environment of the macro by default, so hygienic) and access to the
environment so things can be closed into the environment of the
caller where required, thus basically extending sc-macro-expander a
little to do basic argument-list-style decomposition of the form.
Which should be trivial, having read the above - I'll give it a go if
I get a minute...



Alaric Snell-Pym

reply via email to

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