RFC: define-module+

96 views
Skip to first unread message

Jay McCarthy

unread,
Oct 27, 2016, 3:53:26 PM10/27/16
to dev
Something that has annoyed me about module+ since we first implemented it was that you couldn't make `module`s using it and you couldn't specify the module language (it is always `module*` with `#f` as the language.)

When I originally did it, I left that out because I didn't want the weight of it and for them to be inconsistent and when Matthew made the more beautiful implementation in #%kernel, he kept it that way.

I've gone back and made the implementation support this via a `define-module+` and `define-module*+` form. Please take a look at this example file and let me know any opinions you have:


In particular, should this be in racket? Should it be a package? Should it be in remix? Should have a different name, because obviously you know a better one?

Jay

--
Jay McCarthy
Associate Professor
PLT @ CS @ UMass Lowell
http://jeapostrophe.github.io

           "Wherefore, be not weary in well-doing,
      for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
                          - D&C 64:33

Matthias Felleisen

unread,
Oct 27, 2016, 8:17:12 PM10/27/16
to Jay McCarthy, dev

I like this. How does define-duck+ communicate with DrRacket? 


--
You received this message because you are subscribed to the Google Groups "Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
To post to this group, send email to racke...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CAJYbDaktv5qPo%3D6ymSaG1QC03jWAHGzHrpNtdPb0403H8exSQg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Laurent

unread,
Oct 28, 2016, 5:30:17 AM10/28/16
to Matthias Felleisen, Jay McCarthy, dev
My 2 cents (unknown currency):

I like this too, and I've wanted to use this a few times in the past.

Regarding the names, since 'module+' also defines a name, it wouldn't be very consistent to prefix the new one with "define-". I also worry a little about creating a whole zoo of module declarations.

Wouldn't it be possible to add a keyword to the module+ declaration, like
(module+ duck+ #:name duck #:lang racket/base ...)
where by default the name would just be duck+?

This means we can use #:declared on a module+, but I don't know how it works.

Laurent

On Fri, Oct 28, 2016 at 1:17 AM, Matthias Felleisen <matt...@ccs.neu.edu> wrote:

I like this. How does define-duck+ communicate with DrRacket? 
On Oct 27, 2016, at 3:53 PM, Jay McCarthy <jay.mc...@gmail.com> wrote:

Something that has annoyed me about module+ since we first implemented it was that you couldn't make `module`s using it and you couldn't specify the module language (it is always `module*` with `#f` as the language.)

When I originally did it, I left that out because I didn't want the weight of it and for them to be inconsistent and when Matthew made the more beautiful implementation in #%kernel, he kept it that way.

I've gone back and made the implementation support this via a `define-module+` and `define-module*+` form. Please take a look at this example file and let me know any opinions you have:


In particular, should this be in racket? Should it be a package? Should it be in remix? Should have a different name, because obviously you know a better one?

Jay

--
Jay McCarthy
Associate Professor
PLT @ CS @ UMass Lowell
http://jeapostrophe.github.io

           "Wherefore, be not weary in well-doing,
      for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
                          - D&C 64:33

--
You received this message because you are subscribed to the Google Groups "Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+unsubscribe@googlegroups.com.

To post to this group, send email to racke...@googlegroups.com.

Jay McCarthy

unread,
Oct 28, 2016, 8:51:28 AM10/28/16
to Laurent, Matthias Felleisen, dev
On Fri, Oct 28, 2016 at 5:29 AM, Laurent <laurent...@gmail.com> wrote:
>
> My 2 cents (unknown currency):
>
> I like this too, and I've wanted to use this a few times in the past.
>
> Regarding the names, since 'module+' also defines a name, it wouldn't be very consistent to prefix the new one with "define-". I also worry a little about creating a whole zoo of module declarations.

I feel like something must be unclear...

```
(module+ X body ...)
```

defines the module X in pieces as a `module*` with #f as the lang

This new form, `(define-module+ ADD-TO-X X L)`, defines the module X
as a `module` with L as the lang AND defines a macro that works just
like module+ (except you don't give it a name) called ADD-TO-X that
adds stuff to X's body. So it is called `define-module+` because it
defines something like `module+` as its main job.

Its companion, `define-module*+` is the same, but defines the module
as a `module*`

> Wouldn't it be possible to add a keyword to the module+ declaration, like
> (module+ duck+ #:name duck #:lang racket/base ...)
> where by default the name would just be duck+?

There's no point to #:name on module+. The only reason you need the
name with `define-module+` is that it defines two things: the ADD-TO-X
and X. It would be possible to change `module+` to specify the
language in the way you suggest, except it's easier to imagine making
a mistake by having the keyword multiple times or inconsistently, etc.

> This means we can use #:declared on a module+, but I don't know how it works.

Yes. You can already do that with my implementation. It "seals" the
module and refuses to allow any more body syntax.

Jay

>
> Laurent
>
> On Fri, Oct 28, 2016 at 1:17 AM, Matthias Felleisen <matt...@ccs.neu.edu> wrote:
>>
>>
>> I like this. How does define-duck+ communicate with DrRacket?
>>
>>
>> On Oct 27, 2016, at 3:53 PM, Jay McCarthy <jay.mc...@gmail.com> wrote:
>>
>> Something that has annoyed me about module+ since we first implemented it was that you couldn't make `module`s using it and you couldn't specify the module language (it is always `module*` with `#f` as the language.)
>>
>> When I originally did it, I left that out because I didn't want the weight of it and for them to be inconsistent and when Matthew made the more beautiful implementation in #%kernel, he kept it that way.
>>
>> I've gone back and made the implementation support this via a `define-module+` and `define-module*+` form. Please take a look at this example file and let me know any opinions you have:
>>
>> https://github.com/jeapostrophe/exp/blob/master/module/ex.rkt
>>
>> In particular, should this be in racket? Should it be a package? Should it be in remix? Should have a different name, because obviously you know a better one?
>>
>> Jay
>>
>> --
>> Jay McCarthy
>> Associate Professor
>> PLT @ CS @ UMass Lowell
>> http://jeapostrophe.github.io
>>
>> "Wherefore, be not weary in well-doing,
>> for ye are laying the foundation of a great work.
>> And out of small things proceedeth that which is great."
>> - D&C 64:33
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
>> To post to this group, send email to racke...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CAJYbDaktv5qPo%3D6ymSaG1QC03jWAHGzHrpNtdPb0403H8exSQg%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
>> To post to this group, send email to racke...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/BFD788CE-9EEE-4A8F-9164-EAD9A771866C%40ccs.neu.edu.
>>
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CABNTSaFjtb%2BO5eW8rgacAJDLosCu%2B29uKAt%2BoH%3DK%2B9nonV7dQg%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.




--

Laurent

unread,
Oct 28, 2016, 12:22:36 PM10/28/16
to Jay McCarthy, Matthias Felleisen, dev
On Fri, Oct 28, 2016 at 1:51 PM, Jay McCarthy <jay.mc...@gmail.com> wrote:
On Fri, Oct 28, 2016 at 5:29 AM, Laurent <laurent...@gmail.com> wrote:

This new form, `(define-module+ ADD-TO-X X L)`, defines the module X
as a `module` with L as the lang AND defines a macro that works just
like module+ (except you don't give it a name) called ADD-TO-X that
adds stuff to X's body. So it is called `define-module+` because it
defines something like `module+` as its main job.

Yes, ok. Let me refine my post then:
'module+' creates the module on the first instance, but then adds to it on the next instances. So you could imagine that instead of creating a macro duck+, you could also use 'module+ duck' instead (maybe), thus avoiding yet another form. The 'duck+' form is just syntactic salt on top of the main idea which is specifying the language and sealing the module explicitly so as to be required later.
 
It would be possible to change `module+` to specify the
language in the way you suggest, except it's easier to imagine making
a mistake by having the keyword multiple times or inconsistently, etc.

The multiple occurrences of the keyword can easily be fixed with '~once' in 'syntax-parse' I suppose. Not sure what you mean about inconsistency.

Then, if successful, I guess your versions of module+ and module* could replace the old ones.
 
> This means we can use #:declared on a module+, but I don't know how it works.

Yes. You can already do that with my implementation. It "seals" the
module and refuses to allow any more body syntax.

Nice!

Laurent

Ben Greenman

unread,
Nov 4, 2016, 6:49:55 PM11/4/16
to Jay McCarthy, dev
Can this be a package now?

--
You received this message because you are subscribed to the Google Groups "Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+unsubscribe@googlegroups.com.

Jay McCarthy

unread,
Nov 4, 2016, 8:17:18 PM11/4/16
to Ben Greenman, dev
I forgot to push it...

raco pkg install remix

(require racket/remixd)
>> email to racket-dev+...@googlegroups.com.
>> To post to this group, send email to racke...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-dev/CAJYbDaktv5qPo%3D6ymSaG1QC03jWAHGzHrpNtdPb0403H8exSQg%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>



Anthony Carrico

unread,
Nov 16, 2016, 12:06:19 PM11/16/16
to dev
I just noticed this thread. It looks great. When generating ffi wrappers
it would de nice to generate several modules incrementally into a file
(typed and untyped). I might put it to use for that case right away.

Related, and probably discussed elsewhere already, I wonder if a
language could use a sufficiently smart reader to delimit submodules
with different subreaders?

PS Sorry for the dup. Jay, it didn't go to the list.

--
Anthony Carrico

Jay McCarthy

unread,
Nov 16, 2016, 12:11:42 PM11/16/16
to Anthony Carrico, dev
On Wed, Nov 16, 2016 at 12:06 PM, Anthony Carrico <acar...@memebeam.org> wrote:
> I just noticed this thread. It looks great. When generating ffi wrappers
> it would de nice to generate several modules incrementally into a file
> (typed and untyped). I might put it to use for that case right away.
>
> Related, and probably discussed elsewhere already, I wonder if a
> language could use a sufficiently smart reader to delimit submodules
> with different subreaders?

The example does that

https://github.com/jeapostrophe/remix/blob/master/tests/racket/remixd.rkt

> PS Sorry for the dup. Jay, it didn't go to the list.
>
> --
> Anthony Carrico
>
> --
> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/6eb12879-3e8d-3c8d-8022-064c2cd36fd5%40memebeam.org.
> For more options, visit https://groups.google.com/d/optout.



Reply all
Reply to author
Forward
0 new messages