[plt-scheme] Unhygienic macro not needed?

From: Laurent (laurent.orseau at gmail.com)
Date: Fri Nov 20 08:57:19 EST 2009

Hi all,

Still having difficulties with (hygienic) macros...

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)))

As I dislike code repetitions, I want to make a macro that could generate
either f1 or f2 or any function that has a body between the `let' and the
`(baz'.
I want the generated code to be as fast as without using macro. This (as I
understand it) is the case for `define-syntax' et al.

Since `bar' has some arguments that are defined inside the function, my
first (probably bad) guess was to use an unhygienic macro with
`define-macro'. That was simple and worked. However my code was quite slower
so I suspect the transformation is not syntactic but is rather done on the
fly with an eval. And I don't want to be beaten to death by hygienic macro
programmers either.

So what is the correct way to (generically) compress this code without
losing run-time, i.e. to have a syntactical transformation?
Is it possible to define an hygienic macro without loss of genericity?
Is there a hygienic macro programming style  that I could automatically use?

Thanks,
Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20091120/5130a1b3/attachment.html>

Posted on the users mailing list.