Tutorial by Examples

All built-in Clojure collections are immutable and heterogeneous, have literal syntax, and support the conj, count, and seq functions. conj returns a new collection that is equivalent to an existing collection with an item "added", in either "constant" or logarithmic time. Wha...
A list is denoted by parentheses: () ;;=> () A Clojure list is a singly linked list. conj "conjoins" a new element to the collection in the most efficient location. For lists, this is at the beginning: (conj () :foo) ;;=> (:foo) (conj (conj () :bar) :foo) ;;=> (:foo :ba...
A sequence is very much like a list: it is an immutable object that can give you its first element or the rest of its elements in constant time. You can also construct a new sequence from an existing sequence and an item to stick at the beginning. You can test whether something is a sequence using ...
A vector is denoted by square brackets: [] ;;=> [] [:foo] ;;=> [:foo] [:foo :bar] ;;=> [:foo :bar] [1 (+ 1 1) 3] ;;=> [1 2 3] In addition using to the literal syntax, you can also use the vector function to construct a vector: (vector) ;;=> [] (vector :foo) ;;=&...
Like maps, sets are associative and unordered. Unlike maps, which contain mappings from keys to values, sets essentially map from keys to themselves. A set is denoted by curly braces preceded by an octothorpe: #{} ;;=> #{} #{:foo} ;;=> #{:foo} #{:foo :bar} ;;=> #{:bar :foo} As...
Unlike the list, which is a sequential data structure, and the vector, which is both sequential and associative, the map is exclusively an associative data structure. A map consists of a set of mappings from keys to values. All keys are unique, so maps support "constant"-time lookup from k...

Page 1 of 1