Permalink
Browse files

basic outline of the ignore variable

  • Loading branch information...
1 parent 0b21858 commit 6186af8daaf86808e9c0bf4e27622f7e3f970619 @fogus fogus committed Dec 30, 2010
Showing with 16 additions and 7 deletions.
  1. +13 −4 src/main/clojure/clojure/core/unify.clj
  2. +3 −3 src/test/clojure/clojure/core/unify/tests.clj
View
17 src/main/clojure/clojure/core/unify.clj
@@ -12,7 +12,10 @@
(:require [clojure [zip :as zip]])
(:use [clojure.walk :as walk :only [prewalk]]))
-(def *variablep* #(and (symbol? %) (re-matches #"^\?.*" (name %))))
+(defn ignore-variable? [sym] (= '_ sym))
+
+(def *variablep* #(or (ignore-variable? %)
+ (and (symbol? %) (re-matches #"^\?.*" (name %)))))
(defn- composite?
"Taken from the old `contrib.core/seqable?`. Since the meaning of 'seqable' is
@@ -45,12 +48,18 @@
:else (recur (zip/next z))))))
+(defn- bind-phase
+ [binds variable expr]
+ (if (ignore-variable? variable)
+ binds
+ (assoc binds variable expr)))
+
(defn- determine-occursness [want-occurs? variable? v expr binds]
(if want-occurs?
`(if (occurs? ~variable? ~v ~expr ~binds)
(throw (IllegalStateException. (str "Cycle found in the path " ~expr)))
- (assoc ~binds ~v ~expr))
- `(assoc ~binds ~v ~expr)))
+ (bind-phase ~binds ~v ~expr))
+ `(bind-phase ~binds ~v ~expr)))
(defmacro create-var-unification-fn
[want-occurs?]
@@ -141,7 +150,7 @@
return a bindings map for two expressions. This function uses an 'occurs check'
methodology for detecting cycles."
[variable-fn]
- (partial garner-unifiers unify-variable variable-fn))
+ #(garner-unifiers unify-variable variable-fn % %2 {}))
(defn make-occurs-subst-fn
"Given a function to recognize unification variables, returns a function that
View
6 src/test/clojure/clojure/core/unify/tests.clj
@@ -41,16 +41,16 @@
(is (= '{?y a, ?x ?y} (#'clojure.core.unify/garner-unifiers '(?x ?y a) '(?y ?x ?x)))))
-(deftest test-range-variables
+#_(deftest test-range-variables
(is (= '{?x 1 ?y (2 3)} (#'clojure.core.unify/garner-unifiers '(?x & ?y) [1 2 3])))
(is (= '{?x 1 ?y 2 ?z (3)} (#'clojure.core.unify/garner-unifiers '(?x ?y & ?z) [1 2 3])))
(is (= '{?x 1 ?y ()} (#'clojure.core.unify/garner-unifiers '(?x & ?y) [1]))))
(deftest test-ignore-variables
(is (= '{?x 1 ?y 3} (#'clojure.core.unify/garner-unifiers '(?x _ ?y) [1 2 3])))
(is (= '{} (#'clojure.core.unify/garner-unifiers '(_ _ _) [1 2 3])))
- (is (= '{?x 1} (#'clojure.core.unify/garner-unifiers '(?x & _) [1 2 3])))
- (is (= '{?y (2 3)} (#'clojure.core.unify/garner-unifiers '(_ & ?y) [1 2 3]))))
+ #_(is (= '{?x 1} (#'clojure.core.unify/garner-unifiers '(?x & _) [1 2 3])))
+ #_(is (= '{?y (2 3)} (#'clojure.core.unify/garner-unifiers '(_ & ?y) [1 2 3]))))
(deftest test-subst-bindings
(is (= '{?y a, ?x a} (#'clojure.core.unify/subst-bindings '{?y a, ?x ?y}))))

0 comments on commit 6186af8

Please sign in to comment.