1. 9
  1.  

  2. 1

    Great stuff! I love the format of iterating on implementations and criticisms.

    Clojure also has de-nesting shortcuts via -> and related macros, but while the first argument to nest is the outermost expression, the first argument to -> and similar is the innermost expression. This makes it convenient for expressing function composition. However, it seems backward to use it for binding. These two expressions are equivalent:

    (let [x 1 y 2]
       (when (even? y)
          x))
    
    (->> x
         (when (even? y))
         (let [x 1 y 2]))
    

    Which reminds me of Haskell’s where.

    Similarly, the author illustrates the utility of nest with binding forms, but using it for function composition may feel backwards. If I understand nest correctly, then these should be equivalent:

    (reduce + (filter odd? (map inc [1 2 3 4])))
    
    (nest (reduce +)
          (filter odd?)
          (map inc)
          [1 2 3 4])
    

    But, this outermost-first order is the usual order of function composition in math, Haskell, and others.

    It’s interesting that you can express either binding or composition in either order.

    PS: nest is implemented in a library for Clojure as <<-