This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns logic-introduction.core | |
(:refer-clojure :exclude [inc reify ==]) | |
(:use [clojure.core.logic minikanren prelude nonrel match disequality])) | |
(defn geto [key env value] | |
"Succeed if type association [key :- value] is found in vector env." | |
(matche [env] | |
([[[key :- value] . _]]) | |
([[_ . ?rest]] (geto key ?rest value)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def pm2 (pattern-matrix [(pattern-row [wildcard (pattern false) (pattern true)] :a1) | |
(pattern-row [(pattern false) (pattern true) wildcard] :a2) | |
(pattern-row [wildcard wildcard (pattern false)] :a3) | |
(pattern-row [wildcard wildcard (pattern true)] :a4)] | |
'[x y z])) | |
(compile pm2) | |
;#match.core.SwitchNode[ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def pm2 (pattern-matrix [(pattern-row [wildcard (pattern false) (pattern true)] :a1) | |
(pattern-row [(pattern false) (pattern true) wildcard] :a2) | |
(pattern-row [wildcard wildcard (pattern false)] :a3) | |
(pattern-row [wildcard wildcard (pattern true)] :a4)] | |
'[x y z])) | |
(compile pm2) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; (match [x y z] | |
;; [_ f# t#] 1 | |
;; [f# t# _ ] 2 | |
;; [_ _ f#] 3 | |
;; [_ _ t#] 4) | |
(def pm2 (pattern-matrix [(pattern-row [wildcard (pattern false) (pattern true)] :a1) | |
(pattern-row [(pattern false) (pattern true) wildcard] :a2) | |
(pattern-row [wildcard wildcard (pattern false)] :a3) | |
(pattern-row [wildcard wildcard (pattern true)] :a4)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
match.test.core=> (-> (build-matrix [x] | |
[[1]] 1 | |
[(isa? Object)] 2) | |
compile | |
to-clj) | |
(clojure.core/cond | |
(<TypePattern: class java.lang.Object > x) 2 | |
(#match.core.VectorPattern[[1], 0] x) (clojure.core/cond | |
(<LiteralPattern: 1> x0) (clojure.core/cond |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftyped | |
addInteger | |
[Integer :> [Integer :> Integer]] | |
[x y] | |
(+ x y)) | |
(deftyped | |
addDouble | |
[Double :> [Double :> Double]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
match.core=> (-> (build-matrix [x] | |
[1] 2 | |
[(a)] 1) | |
compile | |
to-clj | |
source-pprint) | |
(cond | |
(sequential? x) (cond | |
(= x nil) 1 | |
:else (throw |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro expand-pattern [vars & clauses] | |
`(-> (build-matrix ~vars ~@clauses) | |
compile | |
to-clj | |
source-pprint)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(match [x y] | |
([1 2] | | |
[2 3] | | |
[3 4]) :a0 | |
[10 20] :a1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(match x | |
(1 | | |
2 | | |
3) :a0 | |
1 :a1) | |
(match [x y] | |
([1 2] | | |
[2 3] | | |
[3 4]) :a0 |