(github.com) guicho271828/trivia: Pattern Matcher Compatible with Optima
ROAM_REFS: https://github.com/guicho271828/trivia
- Trivia : Trivial Pattern Matching Compiler
Trivia is a pattern matching compiler that is compatible with Optima. It shares the same testing code with Optima and acts as a drop-in replacement for 99% usage. For the basic usage, consult our wiki. Known differences between Optima and Trivia, which are bug, are described here (7/31/2016)
(defpackage :playwithit
(:use :cl
- :optima))
+ :trivia))
(in-package :playwithit)
(match '(something #(0 1 2))
((list a (vector 0 _ b))
(values a b)))
;; --> SOMETHING, 2
Patterns compiled with Trivia runs faster than Optima.
runtime [sec] fibonacci gomoku string-match optima 11.5 39.8 82.5 trivia [1] 9.68 37.4 1.57 [1]: trivia is using :balland2006 optimiizer
… and Trivia is more extensible. In fact, Trivia's
defpatternis able to implement all of unmodifiable, core pattern language in Optima within itself.
(defpattern cons (a b)
(with-gensyms (it)
`(guard1 (,it :type cons) (consp ,it) (car ,it) ,a (cdr ,it) ,b)))
Detailed documentation is in github wiki.