[plt-scheme] macros that need to eval

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Jan 28 07:45:35 EST 2003

On Jan 28, Doug Orleans wrote:
> Here's a riddle: is there a way to write a macro that needs to
> evaluate one of its arguments at expansion time-- without using
> eval?
> 
> For example, can you write a macro arity-thunk such that
>     (arity-thunk 4 (newline))
> expands into
>     (lambda (x1 x2 x3 x4) (newline))
> ?  (The parameters don't have to be named that way; they could be
> generated temporaries.)

I think that requiring that

    (arity-thunk (* 2 2) (newline))

would be a better question.  If not, then you can just look at the
contents of the syntax object -- except that's a limited of form
cheating -- relying on the fact that there is a number there and not
something like the original string or you'd have to parse "#b100".

And if that *is* the case, then my guess is that Matthew is going to
be proud if your attempts at making this work will all fail -- and I'm
now convinced that this is for a good reason...  Would you want this:

  (let ((x 4))
    (arity-thunk x (newline)))

to expand to the same thing?  How about this:

  (arity-thunk (read) (display x4))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.