[gambit-list] maco to call define w/ varaible name created
lowly coder
lowlycoder at huoyanjinjing.com
Sun Aug 9 21:08:43 EDT 2009
Exactly what I needed. Thanks!
On Fri, Aug 7, 2009 at 9:00 AM, Marc Feeley<feeley at iro.umontreal.ca> wrote:
>
> On 7-Aug-09, at 11:51 AM, vasil wrote:
>
>> May be you need this:
>>
>> (define-macro (define-at-expand-time-and-runtime . body)
>> (eval `(define , at body))
>> `(define , at body))
>>
>> (define-at-expand-time-and-runtime global "foo")
>>
>> (define-macro (magic name value)
>> `(define ,(string->symbol (string-append global "-" name)) ,value))
>>
>> (magic "bar" 1)
>
>
> Here's a stylistic improvement on your idea. The advantage is that the
> nature of the expression is more apparent (for example you can grep for
> "(define global" to find the definition of global).
>
> Marc
>
> (define-macro (at-expand-time-and-runtime expr)
> (eval expr)
> `,expr)
>
> (at-expand-time-and-runtime
> (define global "foo"))
>
> (define-macro (magic name value)
> `(define ,(string->symbol (string-append global "-" name)) ,value))
>
> (magic "bar" 1)
>
>
More information about the Gambit-list
mailing list