summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Buduroi <nbuduroi@gmail.com>2011-04-22 10:21:18 -0400
committerStuart Halloway <stu@thinkrelevance.com>2011-04-29 11:11:43 -0400
commit1e863f49813fb3e540034bc541ca0fb835cab9e1 (patch)
tree410bde22d5489d753a2e75b5a573da3f442cb548
parent8fee9ad0098507c929721b136b9401b7763d85f5 (diff)
Added the check-options function to warn about wrong optional arguments and use it in defmulti macro.
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r--src/clj/clojure/core.clj14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 0c411dd1..b5835565 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -1502,6 +1502,19 @@
(list form x)))
([x form & more] `(->> (->> ~x ~form) ~@more)))
+(def map)
+
+(defn check-options
+ "Throws an exception if the given option map contains keys not listed
+ as valid, else returns nil."
+ [options & valid-keys]
+ (when (seq (apply disj (apply hash-set (keys options)) valid-keys))
+ (throw
+ (IllegalArgumentException.
+ (apply str "Only these options are valid: "
+ (first valid-keys)
+ (map #(str ", " %) (rest valid-keys)))))))
+
;;multimethods
(def global-hierarchy)
@@ -1541,6 +1554,7 @@
(let [options (apply hash-map options)
default (get options :default :default)
hierarchy (get options :hierarchy #'global-hierarchy)]
+ (check-options options :default :hierarchy)
`(let [v# (def ~mm-name)]
(when-not (and (.hasRoot v#) (instance? clojure.lang.MultiFn (deref v#)))
(def ~(with-meta mm-name m)