9

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?

1 Answer 1

14

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ł: Thanks. I did not realize that the syntax had changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.