[racket] Defining a typed language
On Wed, Oct 29, 2014 at 5:50 AM, Konrad Hinsen
<konrad.hinsen at fastmail.net> wrote:
> Sam Tobin-Hochstadt writes:
>
> > > This suggests that if I want my single-form module to be handled exactly
> > > like a multi-form module, my single form must expand to something else
> > > than #%plain-module-begin. Fine. But who or what decides what my single
> > > form becomes when it is "partially expanded in a module-begin context" ?
> >
> > This always happens in a single-form module. The macro system
> > partially-expands the macro to see if it turns into a version of
> > #%module-begin.
>
> Fine, but how? Where are the rules that lead to
>
> (displayln (foo 42))
>
> being partially expanded to
>
> (#%plain-module-begin ...)
The rule is that for anything like:
(module m lang
(form ...))
`form` is expanded until it either produces `#%plain-module-begin` or
another core form. In the former case, it just continues, in the
latter case, it wraps the whole thing with `#%module-begin` as
exported from the specified language, and then expands that.
In your particular example, it will expand (displayln (foo 42)) to
(#%app displayln (foo 42)) and then to (#%module-begin (#%app
displayln (foo 42))).
> Are they part of the language definition? More specifically, I am
> looking for a way to override them.
I'm not sure exactly what you want to override here.
Sam