diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-06-04 15:43:10 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-06-07 10:03:40 -0400 |
commit | 725547f4587f75c063c51659e582cfdbcc140f80 (patch) | |
tree | 59276e45d5b8e29438fe59e9cc8d7fa966baf355 | |
parent | 24442426af1fe643d904b4adfcf62fd7a1cf3ff7 (diff) |
tidy up and test #257, remove spurious .rej file
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | src/clj/clojure/core.clj | 1 | ||||
-rw-r--r-- | src/clj/clojure/core_deftype.clj.rej | 21 | ||||
-rw-r--r-- | test/clojure/test_clojure/other_functions.clj | 9 |
3 files changed, 10 insertions, 21 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 22357b69..2a2563f5 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -5675,6 +5675,7 @@ versions can replace arguments in the second and third positions (y, z). Note that the function f can take any number of arguments, not just the one(s) being nil-patched." + {:added "1.2"} ([f x] (fn ([a] (f (if (nil? a) x a))) diff --git a/src/clj/clojure/core_deftype.clj.rej b/src/clj/clojure/core_deftype.clj.rej deleted file mode 100644 index 83fab7ee..00000000 --- a/src/clj/clojure/core_deftype.clj.rej +++ /dev/null @@ -1,21 +0,0 @@ -diff a/src/clj/clojure/core_deftype.clj b/src/clj/clojure/core_deftype.clj (rejected hunks) -@@ -10,13 +10,18 @@ - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;; definterface ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -+(defn namespace-munge -+ "Convert a Clojure namespace name to a legal Java package name." -+ [ns] -+ (.replace (str ns) \- \_)) -+ - ;for now, built on gen-interface - (defmacro definterface - [name & sigs] - (let [tag (fn [x] (or (:tag (meta x)) Object)) - psig (fn [[name [& args]]] - (vector name (vec (map tag args)) (tag name))) -- cname (symbol (str *ns* "." name))] -+ cname (symbol (str (namespace-munge *ns*) "." name))] - `(do (gen-interface :name ~cname :methods ~(vec (map psig sigs))) - (import ~cname)))) - diff --git a/test/clojure/test_clojure/other_functions.clj b/test/clojure/test_clojure/other_functions.clj index afb67631..879af7e1 100644 --- a/test/clojure/test_clojure/other_functions.clj +++ b/test/clojure/test_clojure/other_functions.clj @@ -51,6 +51,15 @@ "quux" "quux")) (deftest test-fnil + (let [f1 (fnil vector :a) + f2 (fnil vector :a :b) + f3 (fnil vector :a :b :c)] + (are [result input] (= result [(apply f1 input) (apply f2 input) (apply f3 input)]) + [[1 2 3 4] [1 2 3 4] [1 2 3 4]] [1 2 3 4] + [[:a 2 3 4] [:a 2 3 4] [:a 2 3 4]] [nil 2 3 4] + [[:a nil 3 4] [:a :b 3 4] [:a :b 3 4]] [nil nil 3 4] + [[:a nil nil 4] [:a :b nil 4] [:a :b :c 4]] [nil nil nil 4] + [[:a nil nil nil] [:a :b nil nil] [:a :b :c nil]] [nil nil nil nil])) (are [x y] (= x y) ((fnil + 0) nil 42) 42 ((fnil conj []) nil 42) [42] |