Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A node may not depend on itself #1

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/com/stuartsierra/dependency.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@

(defn- remove-from-map [amap x]
(reduce (fn [m [k vs]]
(assoc m k (disj vs x)))
{} (dissoc amap x)))
(assoc m k (disj vs x)))
{} (dissoc amap x)))

(defn- transitive
"Recursively expands the set of dependency relationships starting
at (get m x)"
[m x]
(reduce (fn [s k]
(set/union s (transitive m k)))
(get m x) (get m x)))
(set/union s (transitive m k)))
(get m x) (get m x)))

(declare depends?)

Expand All @@ -71,6 +71,10 @@
(set (keys dependents))))
DependencyGraphUpdate
(depend [graph node dep]
(when (= node dep)
(let [^String msg (binding [*print-length* 10]
(str "The node " (pr-str node) " cannot depend on itself"))]
(throw (Exception. msg))))
(when (depends? graph dep node)
(let [^String msg (binding [*print-length* 10]
(str "Circular dependency between "
Expand Down