scsh-users
[Top] [All Lists]

Re: Dirty macros with define-syntax? Re: An Advanced Syntax-Rules Primer

To: scsh-news@zurich.ai.mit.edu
Subject: Re: Dirty macros with define-syntax? Re: An Advanced Syntax-Rules Primer for the Mildly Insane
From: Al Petrofsky <al@petrofsky.org>
Date: 04 Mar 2002 21:10:34 -0800
Organization: The Vegetable Liberation Front
karttu@walrus.megabaud.fi (Antti Karttunen) writes:

> How do I recreate the effect of dirty macro basque given in
> defmac1.scm using only define-syntax ?  That is, I need the free
> reference to B inside the macro body/template to refer to the
> closest lexically enclosing binding of B [in the macro use]

You don't.  There are devious ways to write unhygienic macros with
syntax-rules, but you can't break referential transparency.  You'll
probably have to pass B as an argument to basque.  If you provide some
detail about why you don't want to do that, then perhaps someone can
propose a solution appropriate to the situation.

> (define B '((humpty . dumpty) (tilleri . talleri) (pilleri . hilleri)))
> 
> (define-syntax basque
>    (syntax-rules ()
>       ((basque arg)
>         (assq arg B))))
> 
> (define (test_it W)
>   (let ((B '((tilleri . tyllero) (humpty . hummingbird) (pilleri . pallero))))
>    (basque W)))

The sick and fragile solution would be to redefine let so that it
pseudo-unhygienicly binds basque to a macro that refers to the B that
let is binding.

-al

<Prev in Thread] Current Thread [Next in Thread>