From 41d80f41faa1cb47ee4430fbe0b3b73007915b47 Mon Sep 17 00:00:00 2001 From: Jimmy Miller Date: Thu, 6 Sep 2018 01:38:13 -0400 Subject: [PATCH] Change to symbols with question marks --- .../src/pattern_matcher/core.clj | 22 +++++------ .../query-engine/src/query_engine/core.clj | 38 +++++++++---------- .../clojure/unifier/src/unifier/core.clj | 32 ++++++++-------- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/libraries/clojure/pattern-matcher/src/pattern_matcher/core.clj b/libraries/clojure/pattern-matcher/src/pattern_matcher/core.clj index dbbea31..dea88a9 100644 --- a/libraries/clojure/pattern-matcher/src/pattern_matcher/core.clj +++ b/libraries/clojure/pattern-matcher/src/pattern_matcher/core.clj @@ -22,8 +22,6 @@ (match args# ~@patterns))) - - (comment (match true true false @@ -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) diff --git a/libraries/clojure/query-engine/src/query_engine/core.clj b/libraries/clojure/query-engine/src/query_engine/core.clj index c198b22..d697962 100644 --- a/libraries/clojure/query-engine/src/query_engine/core.clj +++ b/libraries/clojure/query-engine/src/query_engine/core.clj @@ -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)) diff --git a/libraries/clojure/unifier/src/unifier/core.clj b/libraries/clojure/unifier/src/unifier/core.clj index f33ba33..56b9aa8 100644 --- a/libraries/clojure/unifier/src/unifier/core.clj +++ b/libraries/clojure/unifier/src/unifier/core.clj @@ -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)) @@ -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]]]]]]]]))