> On Apr 3, 2018, at 2:31 PM, Kevin Forchione <lyss...@gmail.com> wrote:
> 
> Hi Guys,
> Does anyone have an analogous example for let-syntax to something as simple 
> as this?
> 
>       (let ([a 3]) a)
> 
> Something like….
> 
>       (let-syntax ([a 3]) ….) 
> 
> At which point I’m stumped as to what expression in the body would return 3. 
> There are no examples in the Reference. 

Others have pointed out different things you could put on the right-hand-side 
of the let-binding, iow, where the 3 is.

However, your original question was about what body expression would make 
`(let-syntax ([a 3]) ....)` return 3. The function that lets you do that is 
`syntax-local-value`. It's used in macros to get the compile-time values of 
things defined with define-syntax or let-syntax.

(let-syntax ([a 3])
  (define-syntax m
    (lambda (stx)
      #`(quote #,(syntax-local-value #'a))))
  (m))

While this compile-time value can be any normal value like 3, most of the time 
you want it to be a function. If it's a function, the macro expander will call 
that function when it sees that identifier in the code, to expand the macro.

However, if you want two macros to communicate a compile-time value between 
them, you can have one of them generate a `let-syntax` or `define-syntax` to 
define that value, and have the other use `syntax-local-value` to get it.

Alex Knauth

> 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