A Clojure Story - Basic Data Types
Clojure Data Types :⌗
Type
A type is property some values share to collect all similar things. Every language has a type system. Some langugages have strict type system, some are relaxed.
Clojure is a dynamic and strongly typed language:
Dynamic - As the type checking is enforced on the fly/run time.
Strong - As operations on improper types are not allowed and errored out.
type
function in clojure helps knowing what is the type of the expression. or
Use class
to inspect clojure expressions.
Numbers:⌗
Long (default) 64 bits
Thanks to More Clojure Basic Types for more detailed insight in few others like
BigInt
Integer
Short & Byte
Double
Float
Ratios
Strings:⌗
Interesting thing about clojure is that it only allows ""
instead of ''
We transform anything into a string with str
function defined by clojure
Booleans⌗
Every value in cojure is true
except false
and nil
(both return false
)
(just like ruby)
Symbols⌗
Not to be confused with symbols in Ruby
Symbols in clojure are used to name things. Like:
Functions like str
and inc
To create a symbol just use quoting
i.e:
Symbols cannot start with a number. Job of symbols is to refer to things, to point to other values.
Keywords⌗
Seem similar to ruby symbols
Keywords are like symbols, except that keywords begin with a colon (:).They are specifically intended for use as labels or identifiers and are useful as keys in maps/hashes.
Keywords resolve to themselves.