[plt-scheme] hygienic macros
Bruce Hauman wrote:
> I am not sure what Eli is getting at. However, it seems that as written
> _rand_ gains little from being a macro in Scheme. It would be better as
> a procedure in this instance.
If by _rand_ you mean the macro Michael called 'pick', then it does need to
be a macro. If it were a procedure, then all the expression choices it is
provided with would be evaluated when it is called, even if only one of the
resulting values is returned. That probably isn't what's wanted.
> To take advantage of the fact that ideally the macros are expanded at
> load-time. It would be really nice for the macro to yield the _syntax_
> of the random choice rather than _code_ that picks the random choice.
>
> Something like this:
>
> (define-syntax rand-pick
> (lambda (stx)
> (syntax-case stx ()
> ((_ exp1 exprs ...)
> (let ((stx-list (syntax-e (syntax (exp1 exprs ...)))))
> (list-ref stx-list (random (length stx-list))))))))
The problem with this is that although each time you loaded the program, you
would get a random choice expanded into the code, that choice wouldn't
change while the program was running. That's a cool concept, but I doubt
it's what the original example was getting at. Sorry to be a spoilsport!
Anton