[plt-scheme] How to let a new symbol (created in _syntax-case_) visible at top level ?
ok , i don't really understand macros , so this is a blind hack and it
seems to work
(require scheme)
(define-syntax defsymbol
(λ (stx)
(syntax-case stx ()
[(k name val)
(with-syntax
([new-name
(datum->syntax #'k
(string->symbol
(string-append
"nv-" (symbol->string (syntax->datum #'name)))))])
#'(define new-name val))])))
(defsymbol biz 4)
nv-biz
On 11/4/08, Andre Mayers <andre.mayers at usherbrooke.ca> wrote:
> #lang scheme
> (define-syntax defsymbol
> (λ (stx)
> (syntax-case stx ()
> [(_ name val)
> (with-syntax
> ([new-name
> (string->symbol
> (string-append "nv-" (symbol->string (syntax->datum
> #'name))))])
> (datum->syntax
> #f
> (list #'define (syntax->datum #'new-name) #'val)
> #f))])))
>
> (defsymbol biz 4)
>
> nv-biz
> ==>
> expand: unbound identifier in module in: nv-biz
>
> I am pretty sure that I am not the first to ask the question but I can't
> find the answer.
>
>
> André Mayers, Ph.D., M. Ps.
> professeur agrégé
> Département d'informatique
> Université de Sherbrooke
> Sherbrooke (Québec) Canada J1K 2R1
> tél: +1 819-821-8000 poste 62041
> fax: +1 819-821-8200
> andre.mayers at usherbrooke.ca
> http://www.dmi.usherb.ca/~amayers
>
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>