Clojure Punctuation

One thing I like about Clojure is there are not as many punctuation characters in the code, like there are in Perl or Scala. This makes it easier to read. But there are some.

Much of this info is also on the Clojure site called “Reading Clojure Characters“.


Symbol Name Description Example
_ Underscore Placeholder for unused
function arguments
(dotimes [_ 5] (swap! s-atom s-func))
. Dot Used for Java interop (.indexOf "caterpillar" "pillar")
@ At Sign Used to dereference refs (def some-data (ref 3))
( Parentheses Used for functions (println "hello")
'( Single-quote
and Parentheses
Used for lists (def list-of-numbers '(1 2 3))
[ Bracket Used for vectors (def vector-of-numbers [1 2 3])
{ Brace Used for maps (def map-of-numbers {:one 1 :two 2 :three 3})
#{ Pound sign and brace Used for sets (def set-of-states #{"AL" "IL" "TX"})
: Colon Keyword.
Common use:
a string used for map keys
(def map-of-numbers {:one 1 :two 2 :three 3})
#( Pound sign
and parantheses
Shorthand for
anonymous functions
(map #(+ % 3) some-vector)
#" Pound sign
and double quote
Regular expression #"(.+):(.+)"
% Percent sign Unnamed argument
to an anonymous function
#(println %)
; Semicolon Comment ; comments are good
\ & Ampersand
(the backslash is
needed for escape)
Optional args
to a function
(defn name-summary [name1 & others]
   (println name1 " and " (count others) " more"))
* Asterisk earmuffs:
used for fields that may be rebound
I think this is a convention and not actually
defined by the language
(def *some-var* (some-func xx))

You’re welcome.

Page created on 2015-07-13_19:54:18, last modified on 2017-11-25_18:50:24.

This site has a disclaimer.