[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Getting a macro to see a runtime form?
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] Getting a macro to see a runtime form? |
Date: |
Thu, 5 Jan 2006 23:28:10 +0100 |
On 1/5/06, Reed Sheridan <address@hidden> wrote:
> I'm trying to write a macro that translates a list into a procedure.
> Here's a very simplified version of my code:
>
> (define spec '(foo))
>
> (define (process-spec spec)
> (if (pair? spec)
> '(lambda x x)
> (error "oops")))
>
> (define-macro (spec->proc a-spec)
> (process-spec a-spec))
>
> #> ((spec->proc (foo)) 33)
> (33)
> #> (spec->proc spec)
> Error: during expansion of (spec->proc ...) - oops
>
> Is there any way to evaluate a-spec at macroexpansion time, or a
> clever workaround to avoid the problem, without putting the
> specification itself in the call to spec->proc?
>
Anything that you wrap in `(eval-when (compile) ...)' will be evaluated
at compile-time. You also can use `eval' inside a macro-expander, of course
(if you want to).
Can you tell more about the specific use of this facility? Where
should the specs be defined, for example?
cheers,
felix