[plt-scheme] Unhygienic macro not needed?

From: Joe Marshall (jmarshall at alum.mit.edu)
Date: Fri Nov 20 10:55:09 EST 2009

On Fri, Nov 20, 2009 at 5:57 AM, Laurent <laurent.orseau at gmail.com> wrote:
>
> I have the following (simplified) code :
>
> (define (f1 x)
>   (let ([y (foo x)])
>     (bar x y y)
>     (plop y x y)
>     (baz x y)))
>
> (define (f2 x)
>   (let ([y (foo x)])
>     (baz x y)))

(define (wrapper receiver)
  (lambda (x)
    (let ((y (foo x)))
      (receiver x y)
      (baz x y))))

(define f1
   (wrapper
     (lambda (x y)
         (bar x y y)
         (plop y x y) )))

(define f2
   (wrapper
      (lambda (x y) #f)))



>
> And I don't want to be beaten to death by hygienic macro
> programmers either.

<jrm puts the club away, starts whistling and tries to look innocent>


> Is there a hygienic macro programming style  that I could automatically use?
> The programming style is then to turn "free" variables in unhygienic macros
>  into identifiers that are bound to one given in the macro call.

Yes!  This has the important advantage over the non-hygienic form: you
don't get `magic variables' appearing out of nowhere.  Every variable that
you can access in the body of the macro is explicitly mentioned in the
code at the macro call site, and you can rename them at will if you like.

-- 
~jrm


Posted on the users mailing list.