guicho271828 / trivia

Pattern Matcher Compatible with Optima
Other
334 stars 22 forks source link
common-lisp pattern-matching

[[https://travis-ci.org/guicho271828/trivia][https://travis-ci.org/guicho271828/trivia.svg?branch=master]]

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 [[https://github.com/guicho271828/trivia/wiki][our wiki]]. Known differences between Optima and Trivia, which are bug, are [[https://github.com/guicho271828/trivia/wiki/Known-Differences][described here]] (7/31/2016)

+BEGIN_SRC diff

(defpackage :playwithit (:use :cl

(match '(something #(0 1 2)) ((list a (vector 0 _ b)) (values a b))) ;; --> SOMETHING, 2

+END_SRC

Patterns compiled with Trivia runs [[https://github.com/guicho271828/trivia/wiki/Benchmarking-Results][faster than Optima]].

| runtime [sec] | [[https://github.com/guicho271828/trivia/blob/master/bench/definitions.lisp#L11][fibonacci]] | [[https://github.com/guicho271828/trivia/blob/master/bench/definitions.lisp#L40][gomoku]] | [[https://github.com/guicho271828/trivia/blob/master/bench/definitions.lisp#L214][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 =defpattern= is able to implement all of [[https://github.com/m2ym/optima#constructor-pattern][unmodifiable, core pattern language]] in Optima within itself.

+BEGIN_SRC lisp

(defpattern cons (a b) (with-gensyms (it) `(guard1 (,it :type cons) (consp ,it) (car ,it) ,a (cdr ,it) ,b)))

+END_SRC

Detailed documentation is in [[https://github.com/guicho271828/trivia/wiki][github wiki]].

To run the tests, =(asdf:test-system :trivia)= .

To run the benchmark, =(asdf:test-system :trivia.benchmark)=