Re:Critiquing Clojure
by twopoint718 on Monday June 22, 2009 @01:46PM
(#669134)
On #5, the code isn't doing what the author may think:
(let [#^int a 2
#^int b 3]
(cons a b))
a and b are not hinted to be primitive types. Type hinting is purely for objects. Use hinting to make it clear to the compiler what sort of objects you are passing into something (e.g. a constructor that takes a String). If there is confusion, clojure will do reflection.
The right thing to do in this case, is the second thing that the author mentions:
(let [a (int 2)
b (int 3)]
(cons a b))
a way to see that a and b are really primitive is:
(let [x (int 5)]
(.shortValue #^Integer x)) ; exception: "can't type hint primitive..."
I understand that this is really beside the point, that the author finds type hinting syntax unattractive, but I just wanted to clear up confusion (if there was any).
The right thing to do in this case, is the second thing that the author mentions:
a way to see that a and b are really primitive is: There's a post on the mailing list that goes over this much better than I did (and where I drew the examples): http://groups.google.com/group/clojure/browse_thread/thread/...I understand that this is really beside the point, that the author finds type hinting syntax unattractive, but I just wanted to clear up confusion (if there was any).
EDIT: clarity