Home

Search IconIcon to open search

Clojure learning log

'(1 2 3) syntax to construct lists. a ' basically means “don’t interpret this as an expression”.

You can use :a <map> and <map> :a syntax to get a value out of a map. They have a slight difference, though I don’t remember what exactly.

Seems like you can get nth element of a vector with this weird syntax:

1
([41 42 43 44] 2) ;; 43

# New cool functions

iterate
peek, pop
lazy-seq

walk, tree-seq - mind blown.

Transpose:
apply mapv vector [[1 2 3] [41 42 43]] => [[1 41] [2 42] [3 43]]

Can be used for Python vibes:

1
2
(defn zip [& xs]  
  (apply map vector xs))

Clojure Destructuring Tutorial and Cheat Sheet
Recursively transform a nested map into transients, and then back to persistents
Destructuring can shoot you in the foot. For example, this function works fine with a sequence of any length:

1
2
(defn marker? a b c d  
  (not= a b c d))

This should be in the standard library:

1
2
3
4
(defn in?   
  "true if coll contains elm"  
  [coll elm]    
  (some #(= elm %) coll))

Find index of an element matching a predicate in Clojure? - Stack Overflow
How to drop the nth item in a collection in Clojure? - Stack Overflow
clojure - Returning duplicates in a sequence - Stack Overflow

Clojure Zippers

defpure macro by Fred Overflow.

Advent of Clerk repo has some cool code in the GitHub forks. Check out the Network.

Clerk

# Articles

# 4Clojure

Custom flatten:

1
2
(fn[x]  (filter (complement sequential?)
          (rest (tree-seq sequential? seq x))))

# Random syntax things

Not equal operator is not=, not !=. != has some different meaning.