Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure type hints syntax

Tags:

types

clojure

In the book "Programming Clojure" (Halloway, S., (2009). Programming Clojure. Raleigh, NC: Pragmatic Bookshelf.) he shows type hints using the syntax

(defn describe-class [#^Class c]
  ...)

while on the Clojure Website, the type hints are shown without the # reader macro:

(defn len2 [^String x]
  ...)

Which is correct?

like image 430
Ralph Avatar asked Nov 22 '10 12:11

Ralph


1 Answers

Both are, but in different versions of Clojure: beginning with the 1.2 release, #^ syntax for reader metadata (in particular, type hints) is deprecated and ^ is to be used instead. Note that #^ still works in 1.2; also note that ^foo was shorthand for (meta foo) prior to 1.2, so you have to use the old notation if you use an older release.

like image 58
Michał Marczyk Avatar answered Oct 23 '22 14:10

Michał Marczyk