Skip to content

Commit

Permalink
Change to symbols with question marks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Miller committed Sep 6, 2018
1 parent f76124c commit 41d80f4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
22 changes: 10 additions & 12 deletions libraries/clojure/pattern-matcher/src/pattern_matcher/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
(match args# ~@patterns)))




(comment
(match true
true false
Expand All @@ -35,30 +33,30 @@


(match [1 2 3]
[x] {:x x}
[x y] {:x x :y y}
[x y z] {:x x :y y :z z})
[?x] {:x ?x}
[?x ?y] {:x ?x :y ?y}
[?x ?y ?z] {:x ?x :y ?y :z ?z})


(match [1 2 1]
[x y x] {:x x :y y}
[x y z] {:x x :y y :z z})
[?x ?y ?x] {:x ?x :y ?y}
[?x ?y ?z] {:x ?x :y ?y :z ?z})


(defmatch fib
[0] 0
[1] 1
[n] (+ (fib (- n 1))
(fib (- n 2))))
[?n] (+ (fib (- ?n 1))
(fib (- ?n 2))))


(fib 5)
(fib 10)

(defmatch get-x
[x] x
[x y] x
[x y z] x)
[?x] ?x
[?x ?y] ?x
[?x ?y ?z] ?x)

(get-x 1)
(get-x 1 2)
Expand Down
38 changes: 19 additions & 19 deletions libraries/clojure/query-engine/src/query_engine/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,35 @@



(q {:find {:name name}
:where [[_ :name name]]}
(q {:find {:name ?name}
:where [[?_ :name ?name]]}
db)


(q {:find {:name name
:age age}
:where [[e :name name]
[e :age age]]}
(q {:find {:name ?name
:age ?age}
:where [[?e :name ?name]
[?e :age ?age]]}
db)




(q {:find {:name1 name1
:name2 name2}
:where [[e1 :name name1]
[e2 :name name2]
[e1 :age age]
[e2 :age age]]}
(q {:find {:name1 ?name1
:name2 ?name2}
:where [[?e1 :name ?name1]
[?e2 :name ?name2]
[?e1 :age ?age]
[?e2 :age ?age]]}
db)



(q {:find {:name name
:address-line-1 address-line-1
:city city}
:where [[e :name name]
[a :address e]
[a :address-line-1 address-line-1]
[a :city city]]}
(q {:find {:name ?name
:address-line-1 ?address-line-1
:city ?city}
:where [[?e :name ?name]
[?a :address ?e]
[?a :address-line-1 ?address-line-1]
[?a :city ?city]]}
db))
32 changes: 17 additions & 15 deletions libraries/clojure/unifier/src/unifier/core.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
(ns unifier.core
(:import (clojure.lang Sequential))
(:require [clojure.walk]))
(:require [clojure.walk]
[clojure.string :as string]))

(defn variable? [x]
(symbol? x))
(and (symbol? x)
(string/starts-with? (name x) "?")))

(defn add-var [env var val]
(assoc env var val))
Expand Down Expand Up @@ -57,23 +59,23 @@
(comment

(-> {}
(unify 'x 2)
(unify 'y 'x)
(unify 'z 'y)
(lookup 'z))
(unify '?x 2)
(unify '?y '?x)
(unify '?z '?y)
(lookup '?z))

(-> {}
(unify 'x 'y)
(unify 'y 'z)
(unify 'z 2)
(lookup 'x))
(unify '?x '?y)
(unify '?y '?z)
(unify '?z 2)
(lookup '?x))


(-> {}
(unify 2 'x)
(unify 'x 'y)
(unify 'z 'y)
(lookup 'z))
(unify 2 '?x)
(unify '?x '?y)
(unify '?z '?y)
(lookup '?z))


(substitute '[{x 3} [x [x [x [x [x [[x]]]]]]]]))
(substitute '[{?x 3} [?x [?x [?x [?x [?x [[?x]]]]]]]]))

0 comments on commit 41d80f4

Please sign in to comment.