type hints in macros?

8 views
Skip to first unread message

mifrai

unread,
Jun 24, 2008, 1:16:40 AM6/24/08
to Clojure
Is there a way to put in type hints into macros?

(defmacro hinted []
(let [i (gensym "i")]
`(let [#^Integer ~i 3]
~i)))


Metadata can only be applied to
IObjsjava.lang.IllegalArgumentException: Metadata can only be applied
to IObjs
java.lang.Exception: ReaderError:(8,1) Metadata can only be applied to
IObjs
at clojure.lang.LispReader.read(LispReader.java:163)
at clojure.lang.Repl.main(Repl.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.IllegalArgumentException: Metadata can only be
applied to IObjs
at clojure.lang.LispReader$MetaReader.invoke(LispReader.java:579)
at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:473)

Christophe Grand

unread,
Jun 24, 2008, 2:37:52 AM6/24/08
to clo...@googlegroups.com
mifrai a écrit :

> Is there a way to put in type hints into macros?
>
> (defmacro hinted []
> (let [i (gensym "i")]
> `(let [#^Integer ~i 3]
> ~i)))
>
I don't know if there's a best way:

(defmacro hinted []
(let [i (with-meta (gensym "i") {:tag 'Integer})]
`(let [~i 3]
~i)))


Christophe

Reply all
Reply to author
Forward
0 new messages