[plt-scheme] Expanding into top-level

From: David Van Horn (dvanhorn at cs.uvm.edu)
Date: Fri May 9 12:52:14 EDT 2003

Paul Steckler wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> I have a syntax-rules macro that expands into a top-level 
> definition, something like
>   (define-syntax foo
>     (syntax-rules ()
>       [(_ name e1 e2)
>        (define name (bar e1 e2))]))
> Except I don't really want to define `name', I want 
> to define `name-prime'.  How can I build an identifier 
> and still have a top-level definition?
> -- Paul (who doesn't know the macro system as well as he should)

There may be a better way than this, but it works...

(define bar +)

(define-syntax (foo stx)
  (syntax-case stx ()
    [(_ name e1 e2)
              (symbol->string (syntax-object->datum #'name))
         (bar e1 e2))]))

(foo name 1 2)
name-prime ; -> 3


Posted on the users mailing list.