diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-02-28 14:09:15 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-02-28 14:09:15 +0000 |
commit | 5425498acd4101960bede9c68f82849973892cd0 (patch) | |
tree | a9625f0009a1694fc43edd90c86acf1115552c6c /src | |
parent | e8fdf8f175dc5d48113b5715cb8c909a2bc64405 (diff) |
added cast, cast arg to Number in unary +, *
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.clj | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/boot.clj b/src/boot.clj index 0c226432..5eaa62fc 100644 --- a/src/boot.clj +++ b/src/boot.clj @@ -128,7 +128,11 @@ defn (fn [name & fdecl] (. (var defn) (setMacro)) - +(defn + #^{:doc "Throws a ClassCastException if x is not a c, else returns x."} +cast [#^Class c x] + (. c (cast x))) + (defn #^{:doc "Creates a new vector containing the args."} vector @@ -360,7 +364,7 @@ reverse [coll] #^{:doc "Returns the sum of nums. (+) returns 0."} + ([] 0) - ([x] x) + ([x] (cast Number x)) ([x y] (. clojure.lang.Num (add x y))) ([x y & more] (reduce + (+ x y) more))) @@ -369,7 +373,7 @@ reverse [coll] #^{:doc "Returns the product of nums. (*) returns 1."} * ([] 1) - ([x] x) + ([x] (cast Number x)) ([x y] (. clojure.lang.Num (multiply x y))) ([x y & more] (reduce * (* x y) more))) @@ -2070,4 +2074,5 @@ special-symbol? [s] (defn #^{:doc "Returns true if v is of type clojure.lang.Var"} var? [v] - (instance? clojure.lang.Var v))
\ No newline at end of file + (instance? clojure.lang.Var v)) + |