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 warn [msg] | |
(let [line (-> &form meta :line)] | |
`(binding [*out* *err*] | |
(println "WARNING:" | |
~(str "Line " line ":") | |
~msg)))) |
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
(deftest match-single-3 | |
(is (= (let [x 3] | |
(match-1 [1 2] | |
[2 1] :a0 | |
(b :when #(= (count %) 2)) :a1)) | |
: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.core=> (match [1 2] | |
[1 1] 1 | |
[2 2] 2 | |
[3 3] 3) | |
TRACE: DAG: Bind ocr 1 to ocr-68704 | |
TRACE: DAG: Bind ocr 2 to ocr-68705 | |
TRACE: DAG: Pick column 0 as necessary column. | |
TRACE: DAG: Column 0 : #{<LiteralPattern: 1> <LiteralPattern: 2> <LiteralPattern: 3>} | |
TRACE: DAG: Perform default matrix specialization on ocr ocr-68704 , new num ocrs: 2 -> 1 | |
TRACE: DAG: Add fail-node as default matrix (specialized matrix empty), for next node |
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=> (def ^{:dynamic true} *test1* false) | |
#'match.core/*test1* | |
match.core=> (defmacro mtest [] | |
*test1*) | |
#'match.core/mtest | |
match.core=> (mtest) | |
false | |
match.core=> (binding [*test1* true] | |
(mtest)) | |
false |
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
Clojure | |
match.core.debug=> (let [x [1 2]] | |
(m-to-clj [x] [([1 2] | [3 4] | [5 6] | [7 8] | [9 10])] nil)) | |
(binding [*rt-branches* (atom 0) *rt-breadcrumbs* (atom [])] | |
(cond | |
(if (or (seq? x) (sequential? x)) | |
(do | |
(swap! *runtime-branches* inc) | |
(swap! |
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
logic-introduction.facts=> (fact prefer Float Integer) | |
nil | |
logic-introduction.facts=> (fact prefer Integer Float) | |
nil | |
logic-introduction.facts=> (run* [q] | |
(sort-by-preference | |
[Integer Float Object] q)) | |
#<RuntimeException java.lang.RuntimeException: java.lang.Exception: Ambiguous preference: class java.lang.Floatclass java.lang.Integer> |
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
;; Enumerate 20 possible signatures of the function "int" | |
;; such that (int x) gives a Number and x is Number | |
logic-introduction.polymorphism=> (run 20 [q] | |
(expression-check | |
[['x :- Number] | |
['int :- q]] | |
[:apply 'int 'x] | |
Number)) | |
([java.lang.Number :> java.lang.Number] |
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
(defn append [a b] | |
(match [a] | |
[[]] b | |
[[x & as]] (append as (cons x b)))) | |
clojure.lang.Compiler$CompilerException: java.lang.StackOverflowError, compiling:(src/logic_introduction/decl_model.clj:51) | |
at clojure.lang.Compiler.analyzeSeq (Compiler.java:6416) | |
clojure.lang.Compiler.analyze (Compiler.java:6216) |
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
;; Using https://github.com/frenchy64/Logic-Starter/blob/master/src/logic_introduction/decl_model.clj | |
;; Without delving particularly into first order logic theory, we can see that | |
;; a building block of LP is the predicate. | |
(defn append-iio [a b c] | |
(match [a b c] | |
[[] _ _] (set-or-equals c b) | |
[[x & as] _ _] (let-dataflow [cs] | |
(choose-all |
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
;; Evolving a logic programming language | |
;; Based on sketches at https://github.com/frenchy64/Logic-Starter/blob/master/src/logic_introduction/decl_model.clj | |
;; A logic statement reduces to true or false. | |
true | |
;=> true | |
false | |
;=> false |