Hi Cistian,

Both of your examples are hygienic, in the sense that neither actually
do anything that violates macro hygiene.

When `a_definition` is defined in the module context (i.e., the
"global namespace"), it has the same scope as the `a_definition` used
inside `my-macro`. (There's more to it, but this is enough for now.)

When `a_definition` is defined in a local context (e.g., inside a
`(let () ...)` form) outside `my-macro`, it won't have the same scope
as the `a_definition` used inside `my-macro`.

There's an easy trick to get around this. As Simon suggested, make
`a_definition` an argument to `my-macro`:

  (define-simple-macro (my-macro a_definition)
    (display a_definition))

Now, each call to `my-macro` "borrows" `a_definition` from the macro
caller's scope. There are other ways to tackle the problem, but this
is the safest option.

Eric

On Mon, Oct 7, 2019 at 7:33 AM Cistian Alejandro Alvarado Vázquez
<alex.alvar...@resuelve.mx> wrote:
>
> Okay, that I am aware of, but why is it hygienic inside of let but *not* in 
> the global namespace? Also, you should (from my limited understanding!) still 
> be able to access bindings from inside of a macro, no? For example, I can 
> call functions inside of a macro and those identifiers are available even 
> though they weren't provided as arguments. So it appears that macros have 
> access to module-level bindings but NOT more local bindings, and that is what 
> I'm confused about.
>
> On Monday, 7 October 2019 08:04:56 UTC-5, Simon Schlee wrote:
>>
>> Your second macro does not work as you expect, because by default macros in 
>> racket are hygienic, described roughly that means that a macro only 
>> "manipulates" the syntax it is given as arguments, not with the syntax 
>> around its invocation. As gfb has mentioned one way to do this is to use 
>> parameters, this way you can achieve dynamic effects without breaking 
>> hygiene.
>>
>> Why is hygiene good? This section in the guide explains: 
>> https://docs.racket-lang.org/guide/pattern-macros.html?q=macro#%28part._.Lexical_.Scope%29
>>
>> You say you want to use some definitions in your macro, why not just pass 
>> the relevant ones as parameters?
>> Without knowing more about what you are trying to do, it is difficult to 
>> suggest a good direction/solution.
>>
>> Not part of the answer, but related and interesting:
>> (fifth RacketCon): Matthew Flatt — Bindings as Sets of Scopes
>> https://www.youtube.com/watch?v=ABWLveMNdzg
>
> --
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/47407fc2-2c51-4cf1-a5b7-78a390484fbf%40googlegroups.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAORuSUwA-%3DLEK7DughwXZKyW2d10oxV8EcXgGgx5jnonioMX6g%40mail.gmail.com.

Reply via email to