Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optima compat #115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
+ news!(09/06/2018) SPLIT symbol was exported from the =trivia.ppcre= package.
+ news!(02/19/2019) Added =MEMBER= pattern. When the argument is a constant, it also adds type declaration.
+ news!(04/24/2019) Improved the compilation of =GUARD= pattern. It no longer uses the internal hackery.
+ *news!(04/24/2019)* *Balland2006 optimizer is now the default optimizer for the pattern compiler!*
+ news!(04/24/2019) Balland2006 optimizer is now the default optimizer for the pattern compiler!
+ *news!(04/28/2019)* Added a =progv= pattern, which can dynamically alter the dynamic variable the value will be bound to.
+ *news!(05/08/2019)* Now the optimizer can be specified in the lexical environment via =(declare (trivia:optimizer <name>))= (e.g. =(declare (trivia:optimizer :trivial))=). Implemented through cltl2 API.
+ *news!(10/11/2019)* The OR1 consistency checking algorithm in Level 1 no longer takes the exponential runtime. Compilation of [[https://github.com/guicho271828/type-r][type-r]] library is now 10x faster! (patch from @pfdietz)
+ *news!(08/01/2020)* Due to the recent breakage in the original (and unmaintained) Optima library in SBCL, a compatibility layer was added.

* Trivia : Trivial Pattern Matching Compiler

Expand Down
40 changes: 40 additions & 0 deletions optima-compat/package.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

(defpackage :optima
(:use :trivia :trivia.fail)
(:export #:match
#:multiple-value-match
#:ematch
#:multiple-value-ematch
#:cmatch
#:multiple-value-cmatch

#:fail
#:match-error
#:match-error-values
#:match-error-patterns

#:place
#:guard
#:property
#:defpattern))

(defpackage :optima.extra
(:use :trivia)
(:export #:alist
#:plist

#:if-match
#:when-match
#:unless-match
#:let-match
#:let-match*
#:let-match1

#:lambda-match
#:lambda-ematch
#:lambda-cmatch
#:lambda-match1
#:lambda-ematch1
#:lambda-cmatch1))


4 changes: 4 additions & 0 deletions optima-compat/ppcre.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

(defpackage :optima.ppcre
(:use :trivia.ppcre)
(:export #:ppcre))
55 changes: 55 additions & 0 deletions optima-compat/test.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

(defpackage trivia.optima-compat.test
(:use :cl))

(in-package :trivia.optima-compat.test)

(defvar *who-depends-on*
'("check-it"
"cl-environments"
"cl-htmlprag"
"cl-iterative"
"cl-mock"
"cl-quil"
"cl-vhdl-tests"
"clj"
"datafly"

"erlang-term-optima"
"fact-base"
"fare-quasiquote-optima"
"hash-set"
"house"
"hu.dwim.def.test"
"inferior-shell"

"minilem"
"mito-core"
"quux-hunchentoot"
"spatial-trees.nns"

"spatial-trees.nns.test"
"sxql"
"taglib"
"transparent-wrap"
"varjo.import"
"weblocks"

"weblocks-util"
"zenekindarl"
))

(defparameter *errors* nil)

(progn
(setf *errors* nil)
(dolist (system *who-depends-on*)
(handler-case
(ql:quickload system)
(error (c)
(let ((pair (cons system c)))
(print pair)
(push pair *errors*)))))
(print *errors*))


10 changes: 10 additions & 0 deletions optima.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(defsystem optima
:description "(Legacy) Optimized Pattern Matching Library --- Compatibility layer for Trivia"
:version "1.0"
:author "Tomohiro Matsuyama"
:maintainer "Masataro Asai"
:license "LLGPL"
:depends-on (:trivia)
:pathname "optima-compat/"
:components ((:file "package")))

9 changes: 9 additions & 0 deletions optima.ppcre.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(asdf:defsystem :optima.ppcre
:description "(Legacy) CL-PPCRE support for optima --- Compatibility layer for Trivia"
:version "1.0"
:author "Tomohiro Matsuyama"
:maintainer "Masataro Asai"
:license "LLGPL"
:depends-on (:trivia.ppcre)
:pathname "optima-compat/"
:components ((:file "ppcre")))
11 changes: 9 additions & 2 deletions test/level2.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,8 @@
(is-not-match 6 (member '(1 2 3)))))

(test (more-guards :compile-at :run-time)
(flet ((optima (x)
(flet (#+(or)
(optima (x)
(optima:match x
((list (optima:guard x (eql x y)) y)
:ok)))
Expand All @@ -1132,12 +1133,15 @@
((list (guard x (eql x y)) y)
:ok))))

#+(or)
(is (eql :ok (optima '(1 1))))
#+(or)
(is (eql nil (optima '(1 2))))
(is (eql :ok (trivia '(1 1))))
(is (eql nil (trivia '(1 2)))))

(flet ((optima (x)
(flet (#+(or)
(optima (x)
(optima:match x
((not (optima:guard (list x y) (eql x y)))
:ok)))
Expand All @@ -1156,8 +1160,11 @@
;; (or (guard (list #:x #:y) (not (eql #:x #:y)))
;; (not (list #:x #:y)))
;; --- variables are renamed
#+(or)
(is (eql nil (optima '(1 1))))
#+(or)
(is (eql :ok (optima '(1 2))))
#+(or)
(is (eql :ok (optima :a)))

;; currently:
Expand Down
2 changes: 1 addition & 1 deletion trivia.test.asd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:author "Masataro Asai"
:mailto "[email protected]"
:description "Test system of trivia"
:depends-on ("fiveam" "trivia" "trivia.ppcre" "trivia.quasiquote" "trivia.cffi" "optima")
:depends-on ("fiveam" "trivia" "trivia.ppcre" "trivia.quasiquote" "trivia.cffi")
:pathname "test/"
:components ((:file "base")
(:file "level0")
Expand Down