3 ms·
Something as simple as "is this string in this fixed set of strings" benefits from compile-time optimization of the matching algorithm. This is a place where L
by pfdietz 3y ago
Something as simple as "is this string in this fixed set of strings" benefits from compile-time optimization of the matching algorithm. This is a place where Lisp's macros really shine, as they enable this kind of optimization to be performed at macro expansion time, without the need for preprocessing or matching algorithms built into the compiler itself.
- nsm 3y agoI'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.
- tmtvl 3y agoYep, trivia* for instance is very impressive in performance, especially considering you can switch optimizers. * <https://github.com/guicho271828/trivia https://github.com/guicho271828/trivia>
- pfdietz 3y agoI've used it. :) https://github.com/guicho271828/trivia/issues/108 https://github.com/guicho271828/trivia/issues/108