A Multi-Language-Oriented Macro System by Michael Ballantyne at the (fourteenth RacketCon) is now available

A Multi-Language-Oriented Macro System by Michael Ballantyne at the (fourteenth RacketCon) is now available on the Racket YouTube channel at https://youtu.be/KHxZ3mT9BSo
image

--
(fourteenth RacketCon) playlist

3 Likes

This seems very cool. In the related paper "Macros for Domain-Specific Languages", the first examples are the PEG DSL.

It seems like (require peg) gives a different grammar than the paper (documented here). That documentation is incorrect in its syntax for name binding, lacks features from the paper, gives contract violations rather than relevant syntax errors, and goes into an infinite loop on arith-expr-leftrec rather than rejecting left-recursive non-terminals as described in the paper, so is there a different package that should be used while reading the paper?

1 Like

Yeah, the package you link is an unrelated project. The PEG DSL developed in the paper is available here. Runnable versions of all the code in the paper are packaged up as an artifact archived here or available in source form here.

You might also be interested in the syntax-spec version of the PEG DSL which is adapted from the implementation in that previous paper. It's checked in here. And finally, the more recent paper on syntax-spec.

Thanks for reading, and I'd love to hear your thoughts on any of it.

3 Likes

I definitely want to try to work my way through your research as I have the time. You put your finger on an issue which I've toyed with ever since I first learned about macros: you don't always want to expand in terms of the host language's primitives.

When you look at the excellent papers, blog posts, Inside Racket videos, and patient mailing list posts from those who have produced major extensions within Racket, like Robby Findler, @samth, Alexis King, Stephen Chang, etc., it seems like the basics of producing a DSL is pretty straightforward, but the nitty gritty details still bloom into a level of complexity which isn't quite contained with a perfect abstraction. These people have pioneered different approaches. Their artifacts and strategies are fascinating. Each seems like a hard won increment of progress toward the ultimate goal of finding the best way for systems to cooperate at the level of syntax.

The mechanisms for cooperation which exist inside Racket reflect these different approaches, and they aren't perfectly synthesized and abstracted yet, so studying these systems can lead to the feeling that if you have a practical goal to achieve, it might be easier to implement your own expander, just so you know exactly what is happening. The beauty of Dybvig (et. al.'s) psyntax expander, is that it was the perfect midpoint of source code you could print, read, and run, on that spectrum that ranges from a very abstract model which might fit in the appendix of a paper, to a colossal system which you could never read in full. If you could completely understand psyntax, then you could adapt or clone it for your own language, and I imagine MzScheme must have started as something like that. Connecting to this thought, it is interesting that you describe part of the work in MfDSLs as providing the tools to implement your own expander for a DSL.

Anyway, the PLT research program just seems to keep on making progress figuring out how to take the principal of syntactic abstraction up one level from intra- to inter- language cooperation. I love how PLT has stayed focused on these questions over the decades even as the topic moves in and out of the fashion!

2 Likes