Hi guys,
I’ve been interested in having a macro build a series of defines. So I decided 
to start small, trying to get to a macro that would do something like the 
following to begin with:

>(foo 3)
(define foo1 1)
(define foo2 2)
(define foo3 3)

I start with a macro that appears to do a single define:

(require (for-syntax racket/syntax))

(define-syntax (_foo stx)
  (syntax-case stx ()
    [(_ n) (with-syntax ([id (format-id stx "foo~a" (syntax-e #'n))])
             #'(define id n))]))


And this appears to work for (_foo 3) for instance.

Then I create a macro that calls this macro:

(define-syntax (foo stx)
  (syntax-case stx ()
    [(foo n0) #'(_foo n0)]
    [(foo n0 n ...) #'(begin
                      (_foo n0)
                      (foo n ...))]))

thinking that I could do something like (foo 1 2 3) as an intermediary step.  
So I test it with (foo 3) for instance, expecting it to define foo3 and the 
macro debugger tells me that it’s created (define foo3 3), but that foo3 is 
bound as foo3.0, which is a mystery to me as I thought building the id using 
with-syntax and format-id  would have sorted the binding for this.

Looks like I’m at a learning moment…. any explanation why executing (_foo 3) at 
the real works and (foo 3) does not?

Thanks!
-Kevin

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to