On 1/25/12 1:41 PM, David Nolen wrote:
On Wed, Jan 25, 2012 at 3:34 PM, Ben Mabey <b...@benmabey.com
<mailto:b...@benmabey.com>> wrote:
Hi again,
Is it possible to add primitive type hints to protocols (as the
return type)? My attempt below failed:
(definterface IPrimitiveTester
(getType [^int x])
(getType [^long x])
(getType [^float x])
(getType [^double x])
(getType [^Object x]))
(deftype PrimitiveTester []
IPrimitiveTester
(getType [this ^int x] :int)
(getType [this ^long x] :long)
(getType [this ^float x] :float)
(getType [this ^double x] :double)
(getType [this ^Object x] :object))
(defmacro primitive-type [x]
`(.getType (PrimitiveTester.) ~x))
(defmacro pt [x]
`(.getType (PrimitiveTester.) ~x))
(defprotocol Foo
(bar [foo]))
(deftype Dog []
Foo
(bar ^double [_] 42.0))
(pt (bar (Dog.))) ; => :object
(I also tried adding the hint to the protocol definition but that
resulted in a compiler error.)
In my googling the only other reference to protocols with
primitive support was an unanswered question on this mailing list
last November[1]. Hopefully my question gets a little more
attention...
(Pardon all these primitive type questions but I'm in the process
of upgrading a 1.2 app to 1.3 and trying to convert some of our
numeric heavy java code into clojure in the process.)
Thanks,
Ben
1.
http://groups.google.com/group/clojure/browse_thread/thread/6015aacd6e8d0d20/ccca98bea3970240
It's not currently supported.
Do you know if support is planned (i.e. a ticket exists)?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en