masak / alma

ALgoloid with MAcros -- a language with Algol-family syntax where macros take center stage
Artistic License 2.0
139 stars 15 forks source link

Implement pattern/case macros #491

Open masak opened 5 years ago

masak commented 5 years ago

tbd

masak commented 5 years ago

Linking http://www.willdonnelly.net/blog/scheme-syntax-rules/ here.

vendethiel commented 5 years ago

Of mild interest: https://github.com/vendethiel/ADT.ex https://github.com/vendethiel/readlist.cl/blob/master/utils.lisp#L54-L89

masak commented 5 years ago

I notice that I've let this issue get a month old without having a proper OP description. Anyway, tl;dr: I was quite taken with Dylan's pattern macros. What we're doing, Dylan calls "procedural macros", and it never got them, preferring instead the pattern macros (which it calls just "macros").

Two challenges arise. The first one is that the patterns work on the lexical level, and a sequence of patterns in a macro are conceptually tried in order. It's hard to see how this wouldn't constitute re-parsing.

The second one is hygiene. Dylan manages this, though, and I think 007 could as well. But it needs more design.

vendethiel commented 5 years ago

Looking at the source code of the SweetJS module matches.js, it seems like it does what a macro would do: generate code (well, there as a string), and create a new Function with the source code.