Skip to content

Instantly share code, notes, and snippets.

View frenchy64's full-sized avatar

Ambrose Bonnaire-Sergeant frenchy64

  • Madison, Wisconsin
View GitHub Profile
(defmacro warn [msg]
(let [line (-> &form meta :line)]
`(binding [*out* *err*]
(println "WARNING:"
~(str "Line " line ":")
~msg))))
(deftest match-single-3
(is (= (let [x 3]
(match-1 [1 2]
[2 1] :a0
(b :when #(= (count %) 2)) :a1))
:a1)))
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
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
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!
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>
;; 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]
(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)
;; 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
@frenchy64
frenchy64 / part1.clj
Created October 8, 2011 20:11
Evolving a logic programming language
;; 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