So I thought it would be a nice idea to name a function that calculates the exponential ^, but it seems like the caret actually does something special, as the Clojure REPL generates an error when evaluating '^. Googling mostly gave me this, so I was wondering what the actualy use for the caret in Clojure is.
(Also, would it be possible after all to name a function ^?)
^is “the meta character” it tells the reader to add the symbol starting with^as metadata to the next symbol (provided it is something that implements IMetas)You can learn a lot about how clojure works under the hood by looking at the
metaof things, for instance functions:this is very often used for type hints
it is generally a good idea to turn on reflection warnings
(set! *warn-on-reflection* true)and then add type hints until the warnings go away. without these Clojure will look up the type of the function operands at run-time, which saves you the trouble of fussing with types though at a slight cost.PS: My next favorite reader character is the “dispatch” character
#, it is well worth learning about it next 🙂PPS: this is different in clojure 1.2.x vs clojure 1.3.x
in Clojure 1.2.1 metadata does not compose when you use the meta-character:
and in 1.3 it “does the right thing” and also keywords are options instead of “tags”: