Re: [racket-users] Macros expanding to require forms

2020-11-12 Thread Veit Heller
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 sorawe...@gmail.com 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  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 racket-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/a49ab428-ae49-45ce-9d16-8a77d27f5a85n%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/ae330ba0-7f89-4e2d-aa0f-6ff518dc72b7n%40googlegroups.com.


Re: [racket-users] Macros expanding to require forms

2020-11-12 Thread Sorawee Porncharoenwase
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  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 racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/a49ab428-ae49-45ce-9d16-8a77d27f5a85n%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/CADcuegsm45NnAdw-yAqNUPKnytasXuvV0yoNQiW6cb-xu43tVw%40mail.gmail.com.


[racket-users] Macros expanding to require forms

2020-11-12 Thread Veit Heller

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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/a49ab428-ae49-45ce-9d16-8a77d27f5a85n%40googlegroups.com.