I believe this due to an edge case of 'module': when there is only one form
provided, it is partially expanded to determine if its expansion would lead
to a #%plain-module-begin form. Otherwise (more than one form provided)
they are wrapped in #%module-begin with no partial expansion occurring.

>From the docs (https://docs.racket-lang.org/reference/module.html):

If a single form is provided, then it is partially expanded in a module-begin
context
<https://docs.racket-lang.org/reference/syntax-model.html#%28tech._module._begin._context%29>.
If the expansion leads to #%plain-module-begin
<https://docs.racket-lang.org/reference/module.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~23~25plain-module-begin%29%29>,
then the body of the #%plain-module-begin
<https://docs.racket-lang.org/reference/module.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~23~25plain-module-begin%29%29>
is the body of the module. If partial expansion leads to any other
primitive form, then the form is wrapped with #%module-begin using the
lexical context of the module body; this identifier must be bound by the
initial module-path import, and its expansion must produce a
#%plain-module-begin
<https://docs.racket-lang.org/reference/module.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~23~25plain-module-begin%29%29>
to supply the module body. Finally, if multiple forms are provided, they
are wrapped with #%module-begin, as in the case where a single form does
not expand to #%plain-module-begin
<https://docs.racket-lang.org/reference/module.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._~23~25plain-module-begin%29%29>
.

On Mon, Jan 13, 2020, 12:18 PM Matthew Butterick <m...@mbtype.com> wrote:

> Below, the two modules `test1` and `test2` use the same expander `exp` and
> otherwise differ only in the presence of the string "foo" as the second
> datum in `test2`.
>
> The syntax objects passed to #%module-begin are more different than that,
> however: the syntax passed to the first is
>
> #'(#%module-begin 'mac-result)
>
> wheras the second gets:
>
> #'(#%module-begin (mac 42) "foo")
>
> Thus my question: why is `mac` getting expanded at different times based
> on the presence of "foo"?
>
>
> ;;;
> #lang racket
>
> (module exp racket
>   (provide #%datum mac (rename-out [mb #%module-begin]))
>
>   (define-syntax-rule (mac x) 'mac-result)
>
>   (define-syntax (mb stx)
>     (println (syntax->datum stx))
>     (syntax-case stx ()
>       [(_ . EXPRS)
>        #'(#%module-begin . EXPRS)])) )
>
> (module test1 (submod ".." exp)
>   (mac 42))
> (require 'test1)
> ;; '(#%module-begin 'mac-result)
>
> (module test2 (submod ".." exp)
>   (mac 42) "foo")
> (require 'test2)
> ;; '(#%module-begin (mac 42) "foo")
>
> --
> 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/C0F76736-B28C-4F64-A1AA-D2B2EFD34BF8%40mbtype.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/CACehHmD0PKdkJZ4CGmZ%2BV6JtknkDQQMx9BXMX_oTBqK0KHR%2B8g%40mail.gmail.com.

Reply via email to