[gambit-list] maco to call define w/ varaible name created dynamically

Marc Feeley feeley at iro.umontreal.ca
Fri Aug 7 12:00:31 EDT 2009


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