Clojure
Basic
Define functions before you use them
Don’t def and defn the same symbol
Vector and Lists
Data-structures are Immutable and persistent which means fast almost-same copies can be produced.
Vector
A continuous chunk of memory.
Accessing last element is quick
Adding an element at beginning involves reorg
conj adds at the end
More commonly used than lists.
List
A linked linst.
Accessing last element is slow, going from one to another takes time
Adding an element at beginning is easy, creating element and point to the first one in the original list.
conj adds at the beginning
Map
Map is a key value pair. Key can be string or keyword which starts with :
Sets
Set is membership. Element occurs once, either belongs or doesn’t.
Conditionals
Truthy - everything except false, nil and true
Falsy - false, nil
if
can evaluate only one expression.
Combine if
with do
for multiple statements
Use when
for multiple statements with one leg
Use cond
in place of nested ifs
Or case
if evaluating a single variable and not a complex predicate
Catching exceptions
Throwing exception