Hello,
This is very useful information, thank you! I still have trouble
understanding _why_ this works, though; I guess I’m a little confused as to
how the scope-flipping influences things.
For instance, I don’t quite understand why the example from the docs works,
but if you define the module to import in the macro (no matter whether it’s
wrapped in `syntax-local-introduce` or not, it won’t. Example:
```
(module example racket (provide require-mod)
(define-syntax (require-mod stx)
#`(begin
(module mod racket (provide hi) (define (hi) 1))
#,(syntax-local-introduce #'(require 'mod))))
)
(require-mod) ; works fine, without an error
(hi) ; is still undefined
```
I’m not sure that this is supposed to work, but I’m using these to
highlight my lack of understanding for the big picture here. What is going
on? What am I missing?
V
On Thursday, 12 November 2020 at 13:26:48 UTC+1 [email protected] wrote:
> See
> https://docs.racket-lang.org/reference/stxtrans.html#%28def._%28%28quote._~23~25kernel%29._syntax-local-introduce%29%29
> for
> an example program that requires a library via a macro.
>
> On Thu, Nov 12, 2020 at 3:09 AM Veit Heller <[email protected]> wrote:
>
>>
>> Hello,
>>
>> I’m suspecting I’m getting a little turned around by phase levels and
>> where `require` comes in: it seems to be impossible to write a macro that
>> expands to a valid `require` (it doesn’t throw an error, but the functions
>> aren’t defined either). What am I missing? At what phase level does
>> `require` do its magic? And can I tap into this magic from within a macro?
>>
>> An example to illustrate my point:
>>
>> ```
>> (define-syntax require-distributed ()
>> ((_)
>> (require racket/place/distributed))) ; could be anything, really
>> (require-distributed) ; expands and runs fine, but no symbols :(
>> ```
>>
>> I know that this is somewhat of an odd thing to want, and I understand if
>> it’s not possible.
>>
>> V
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-users/a49ab428-ae49-45ce-9d16-8a77d27f5a85n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/racket-users/a49ab428-ae49-45ce-9d16-8a77d27f5a85n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/ae330ba0-7f89-4e2d-aa0f-6ff518dc72b7n%40googlegroups.com.