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

vasil vasil.s.d at gmail.com
Fri Aug 7 11:51:54 EDT 2009


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)



> foo-bar
1
>


Vasil

> Suppose I have the following:
> 
> (define global "foo")
> 
> (define-macro (magic ...))
> 
> (magic "bar" 1); <-- I want this to expand to (define foo-bar 1)
> 
> 
> 
> How can I make this happen? The macro needs to access the value of
> "global", but it can't at compile time; if the macro outputs some code
> that takes advantage of things at run time, I can get to:
> 
> (define (string->symbol (string-append "foo" "-" "bar")) 1)
> 
> but this, of course, tries to define a function string->symbol rather
> than what I want.
> 
> Thanks!
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
> 




More information about the Gambit-list mailing list