[plt-scheme] macros that need to eval
At Tue, 28 Jan 2003 07:45:35 -0500, Eli Barzilay wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> 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".
I don't know whether it's cheating. If `arity-thunk' expects a literal
number after `arity-thunk', that seems fine to me. That doesn't seem
like evaluation any more than detecting a keyword.
> Would you want this:
>
> (let ((x 4))
> (arity-thunk x (newline)))
>
> to expand to the same thing?
This is definitely not the sort of thing I would encourage. :)
Matthew