4 ms·
Nice work! It's a good write-up, too. Hygienic macro expansion is one of the things I still haven't implemented before. I remember a [talk][1] where Matthew Fl
by MathMonkeyMan 2y ago
Nice work! It's a good write-up, too.
Hygienic macro expansion is one of the things I still haven't implemented before. I remember a [talk][1] where Matthew Flatt illustrates the idea of sets of scopes, and choosing the largest intersection. I see in your implementation there are sets of "marks" in syntax objects, is that what's going on there?
I haven't played with rust, but when I do I'll be able to play with this scheme too.
[1]: https://www.youtube.com/watch?v=Or_yKiI3Ha4 https://www.youtube.com/watch?v=Or_yKiI3Ha4
- maplant 2y agoI probably should have looked at this talk! Instead my reference was this PhD thesis[1] cited in the R6RS spec. I can’t say I read the whole thing, but my takeaway was to use a system of marks/antimarks. The basic idea is that at the point of macro expansion, the syntax object is “marked” (i.e. added to the set of marks) with a random integer. The environment of the macro is recorded at that point as well, along with the mark used. After expansion, the resulting syntax object is again marked with the same mark. When an identifier is marked twice with the same mark, the marks cancel each other out. The result of this is that identifier that are introduced into the expander and those introduced by the expander are distinguishable. [1]: https://www2.ccs.neu.edu/racket/pubs/dissertation-kohlbecker.pdf https://www2.ccs.neu.edu/racket/pubs/dissertation-kohlbecker...
- lygaret 2y agoThe talk goes line by line through this code [1]; I've been transcribing and taking notes on this for the last week, for a somewhat similar project actually. If you're interested, I've got a huge pile of papers and links collected here [2] that you might enjoy. I've read everything, but right now it's still a big ol' mush; there's a _ton_ of prior art! Enjoy, good hacking! [1]: https://github.com/mflatt/expander/tree/pico https://github.com/mflatt/expander/tree/pico [2]: https://github.com/lygaret/gigi?tab=readme-ov-file#reading https://github.com/lygaret/gigi?tab=readme-ov-file#reading
- -__---____-ZXyw 2y agoLovely pipe of papers and links, thanks for sharing!
- bjoli 2y agoI have said this before, but it deserves repeating: When people say scheme is a simple language, they do not mean the hygienic macro system. Especially not something like psyntax/syntax-case. I am very impressed! The implementation is crazy clear.
- maplant 2y agoThank you! I’m very proud of the macro expander, so comments like yours are really invigorating and justify the work I put into it