4 ms·
I'm not sure how efficiently it compiles, but Racket's match form is implemented using macros and is stunningly powerful! https://docs.racket-lang.org/referenc
by nsm 3y ago
I'm not sure how efficiently it compiles, but Racket's match form is implemented using macros and is stunningly powerful!
https://docs.racket-lang.org/reference/match.html https://docs.racket-lang.org/reference/match.html
- ReleaseCandidat 3y agoThe paper (IIRC) https://arxiv.org/abs/1106.2578 https://arxiv.org/abs/1106.2578 https://arxiv.org/pdf/1106.2578.pdf https://arxiv.org/pdf/1106.2578.pdf
- kazinator 3y agoI wrote a purely macro-based implementation of pattern matching for TXR Lisp. It's documented over three consecutive chapters: https://www.nongnu.org/txr/txr-manpage.html#N-5C9CED75 https://www.nongnu.org/txr/txr-manpage.html#N-5C9CED75 (Structural Pattern Matching) https://www.nongnu.org/txr/txr-manpage.html#N-B5350C53 https://www.nongnu.org/txr/txr-manpage.html#N-B5350C53 (Pattern-Matching Notation) https://www.nongnu.org/txr/txr-manpage.html#N-CD6130ED https://www.nongnu.org/txr/txr-manpage.html#N-CD6130ED (Pattern-Matching Macros) It's implemented in one file: https://www.kylheku.com/cgit/txr/tree/stdlib/match.tl https://www.kylheku.com/cgit/txr/tree/stdlib/match.tl Starting with the second definition of the function non-triv-pat-p (the real definition which replaces the temporary stub one), the module starts to eat its own dogfood by using its own pattern matching. That function, for instance, decides whether a pattern is "trivial" or not, using pattern matching itself on the pattern matching notation. The string quasiliteral pattern's expansion relies heavily on pattern matching, also.