Skip to content

Commit

Permalink
Can detect nil layers.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 23, 2011
1 parent a1e6c73 commit 6a423dc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/heimdallr.clj
Expand Up @@ -3,9 +3,10 @@
;Email: eduardoejp@gmail.com
;License: EPL 1.0 -> http://www.eclipse.org/legal/epl-v10.html

(ns heimdallr
"Small lib for Context-Oriented Programming."
)
(ns
#^{:author "Eduardo Emilio Julián Pereyra"
:doc "Small lib for Context-Oriented Programming."}
heimdallr)

(def #^{:doc "This dynamic var holds the current Context Stack for a thread."}
*context* (with-meta '() {:type ::ContextStack}))
Expand Down Expand Up @@ -69,7 +70,7 @@ The latter layers will be nested inside the former ones as in:
`(with-context ~(first ctx) (with-context ~(if (> (count (rest ctx)) 1) (vec (rest ctx)) (fnext ctx)) ~@forms))
`(let [reqs# ~ctx]
(if (or (empty? (:requires reqs#)) (->> (:requires reqs#) (map eval) (map #(some (fn [~'c] (= % ~'c)) *context*)) (every? true?)))
(binding [*context* (conj *context* reqs#)] ~@forms)
(binding [*context* (if reqs# (conj *context* reqs#) *context*)] ~@forms)
(throw (Exception. (str "The layer dependencies of <" (:name reqs#) ">, " (str (:requires reqs#)) " are not active in the Context Stack.")))))
))

Expand Down

0 comments on commit 6a423dc

Please sign in to comment.