Clojure Scalar Literals
Nov 15, 2016
1 minute read

Scalar Literals

;This is the content printed to standart out.
;=> This is what the function returns

String

Strings are Java Strings, instance of java.lang.String and represented with double quotes.

"Hello Clojure"
;=> "Hello Clojure"

"Hello
new line"
;=> "Hello \nnew line"

(println "Life is simple")
;Life is simple
;=> nil

(println "hello with newline,
prints with newline")
;hello with newline,
;prints with newline
;=> nil

(println "or you can print with \n newline")
;or you can print with
; newline
;=> nil

(class "I'm String")
;=> java.lang.String

Character

\s
;=> \s

\u0053
;=> \S - Unicode

\o123
;=> \S - Octal

(class \s)
;=> java.lang.Character

;special chars
\space
;=> \space
(print \newline)
;
;=> nil
(println \return)
;
;=> nil
\backspace
;=> \backspace
\tab
;=> \tab
\formfeed
;=> \formfeed

Boolean

(class true)
;=> java.lang.Boolean

false
;=> false

nil

(class nil)
;=> nil

Keyword

:apple
;=> :apple
(class :peanut)
;=> clojure.lang.Keyword

Symbol

(def meaning-of-life 42)
;=> #'sandbox.core/meaning-of-life
meaning-of-life
;=> 42

Numbers

(class 42)
;=> java.lang.Long
(class 3.14)
;=> java.lang.Double
(class 42N)
;=> clojure.lang.BigInt
(class 0.01M)
;=> java.math.BigDecimal
(class 22/7)
;=> clojure.lang.Ratio

Regular Expression

(class #"(m|t)ail")
;=> java.util.regex.Pattern

Back to posts


comments powered by Disqus