Skip to content

Commit 990312b

Browse files
committed
Fixes flatten-bindings to keep unresolved lvars and also bindings to nil
1 parent bbe80a1 commit 990312b

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ core.unify provides a la carte unification facilities that are not deeply tied i
1919
Releases and Dependency Information
2020
========================================
2121

22-
Latest stable release: 0.7.0
22+
Latest stable release: 0.7.1
2323

2424
* [All Released Versions](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22core.unify%22)
2525
* [Development Snapshot Versions](https://oss.sonatype.org/index.html#nexus-search;gav~org.clojure~core.unify~~~)
2626

2727
[CLI/`deps.edn`](https://clojure.org/reference/deps_and_cli) dependency information:
2828
```clojure
29-
org.clojure/core.unify {:mvn/version "0.7.0"}
29+
org.clojure/core.unify {:mvn/version "0.7.1"}
3030
```
3131

3232
[Leiningen](https://github.com/technomancy/leiningen) dependency information:
3333

34-
[org.clojure/core.unify "0.7.0"]
34+
[org.clojure/core.unify "0.7.1"]
3535

3636
[Maven](https://maven.apache.org/) dependency information:
3737

3838
<dependency>
3939
<groupId>org.clojure</groupId>
4040
<artifactId>core.unify</artifactId>
41-
<version>0.7.0</version>
41+
<version>0.7.1</version>
4242
</dependency>
4343

4444

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:1.9 {:override-deps {org.clojure/clojure {:mvn/version "1.9.0"}}}
77
:1.10 {:override-deps {org.clojure/clojure {:mvn/version "1.10.3"}}}
88
:1.11 {:override-deps {org.clojure/clojure {:mvn/version "1.11.4"}}}
9-
:1.12 {:override-deps {org.clojure/clojure {:mvn/version "1.12.0"}}}
9+
:1.12 {:override-deps {org.clojure/clojure {:mvn/version "1.12.4"}}}
1010
;; suitable for Clojure 1.8 or later:
1111
:runner
1212
{:extra-deps {io.github.cognitect-labs/test-runner

src/main/clojure/clojure/core/unify.cljc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@
126126
binds)))))
127127

128128
(defn flatten-bindings
129-
"Flattens recursive bindings in the given map to the same ground (if possible)."
129+
"Flattens recursive bindings in binds to the same ground, if possible.
130+
If a variable cannot be resolved then it is left in place."
130131
([binds] (flatten-bindings lvar? binds))
131132
([variable? binds]
132-
(into {}
133-
(remove (comp nil? second)
134-
(map (fn [[k v]]
135-
[k (loop [v v]
136-
(if (variable? v)
137-
(recur (binds v))
138-
v))])
139-
binds)))))
133+
(into {}
134+
(map (fn [[k v]]
135+
[k (loop [v v]
136+
(if-let [entry (and (variable? v) (find binds v))]
137+
(recur (val entry))
138+
v))])
139+
binds))))
140140

141141
(defn- try-subst
142142
[variable? x binds]

src/test/clojure/clojure/core/unify_test.cljc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
(ns ^{:doc "A unification library for Clojure."
1010
:author "Michael Fogus"}
1111
clojure.core.unify-test
12-
(:require [clojure.core.unify :refer [unify]]
12+
(:require [clojure.core.unify :refer [unify] :as u]
1313
[clojure.test :refer [deftest is testing]]))
1414

1515
#?(:clj (println "\nTesting with Clojure" (clojure-version))
@@ -63,7 +63,9 @@
6363
(is (= '{?y (2 3)} (#'clojure.core.unify/garner-unifiers '(_ & ?y) [1 2 3]))))
6464

6565
(deftest test-flatten-bindings
66-
(is (= '{?y a, ?x a} (#'clojure.core.unify/flatten-bindings '{?y a, ?x ?y}))))
66+
(is (= '{?y a, ?x a} (u/flatten-bindings '{?y a, ?x ?y})))
67+
(is (= '{?z a, ?x ?y} (u/flatten-bindings '{?x ?y, ?z a})))
68+
(is (= {'?x nil} (u/flatten-bindings '{?x nil}))))
6769

6870

6971
(deftest test-unifier*

0 commit comments

Comments
 (0)