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]))
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:
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 tonestis 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:Which reminds me of Haskell’s
where.Similarly, the author illustrates the utility of
nestwith binding forms, but using it for function composition may feel backwards. If I understandnestcorrectly, then these should be equivalent: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:
nestis implemented in a library for Clojure as<<-