Skip to content

Commit

Permalink
* remove macro ns not needed
Browse files Browse the repository at this point in the history
* add CLJS alias
  • Loading branch information
swannodette committed Sep 28, 2024
1 parent 1d06241 commit c0ce6b1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 40 deletions.
5 changes: 4 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
{:git/url "https://github.com/cognitect-labs/test-runner"
:sha "f7ef16dc3b8332b0d77bc0274578ad5270fbfedd"}}
:main-opts ["-m" "cognitect.test-runner"
"-d" "src/test/clojure"]}}}
"-d" "src/test/clojure"]}
:cljs
{:extra-deps {org.clojure/clojurescript {:mvn/version "1.11.132"}}
:main-opts ["-m" "cljs.main" "-re" "node" "-r"]}}}
30 changes: 24 additions & 6 deletions src/main/clojure/clojure/core/unify.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
(ns ^{:doc "A unification library for Clojure."
:author "Michael Fogus"}
clojure.core.unify
#?(:cljs (:require-macros [clojure.core.unify-macros :refer [create-var-unification-fn]]))
#?(:cljs (:require-macros [clojure.core.unify :refer [create-var-unification-fn]]))
(:require [clojure.zip :as zip]
#?(:clj [clojure.core.unify-macros :refer [create-var-unification-fn]])
[clojure.walk :as walk]))

(defn ignore-variable? [sym] (= '_ sym))
Expand Down Expand Up @@ -61,17 +60,36 @@
(recur (zip/next (zip/insert-right z (binds current))))
:else (recur (zip/next z))))))

(defn occurs-check-error [expr]
#?(:clj (throw (IllegalStateException. (str "Cycle found in the path " expr)))
:cljs (throw (js/Error. (str "Cycle found in the path " expr)))) )

(defn- bind-phase
[binds variable expr]
(if (or (nil? expr)
(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)
#?(:clj (throw (IllegalStateException. (str "Cycle found in the path " ~expr)))
:cljs (throw (js/Error. (str "Cycle found in the path " ~expr))))
(bind-phase ~binds ~v ~expr))
`(bind-phase ~binds ~v ~expr)))

#?(:clj
(defmacro create-var-unification-fn
[want-occurs?]
(let [varp (gensym)
v (gensym)
expr (gensym)
binds (gensym)]
`(fn ~'var-unify
[~varp ~v ~expr ~binds]
(if-let [vb# (~binds ~v)]
(garner-unifiers ~varp vb# ~expr ~binds)
(if-let [vexpr# (and (~varp ~expr) (~binds ~expr))]
(garner-unifiers ~varp ~v vexpr# ~binds)
~(determine-occursness want-occurs? varp v expr binds)))))))

(def ^{:doc "Unify the variable v with expr. Uses the bindings supplied and possibly returns an extended bindings map."
:private true}
Expand Down
33 changes: 0 additions & 33 deletions src/main/clojure/clojure/core/unify_macros.clj

This file was deleted.

0 comments on commit c0ce6b1

Please sign in to comment.