In Clojure 1.2, type hints only help the compiler avoid reflection and thus
generate faster Java interop code.
Starting in 1.3, function arguments and return values can have ^long or
^double type hints (int and float are not supported). These are enforced at
compile time, but they are not type-casts.
For example:
Clojure 1.3.0-master-SNAPSHOT
user=> (defn floor ^long [^double x] x)
CompilerException java.lang.RuntimeException:
java.lang.IllegalArgumentException: Mismatched primitive return, expected:
long, had: double
The `long` and `double` functions can be used to coerce primitives to their
respective types.
user=> (defn floor ^long [^double x] (long x))
#'user/floor
user=> (floor 1.5)
1
-Stuart Sierra
clojure.com
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en