Functional Threading "Macros"
2 days ago
- #Threading Macros
- #Functional Programming
- #Lamber
- Threading macros in Common Lisp and Clojure improve code readability by showing the sequence of actions in order.
- Threading macros are not easily implementable in non-Lisp languages, leading to the need for threading combinators.
- Threading combinators involve functions that pass closures around, reversing the applicative evaluation order.
- The post uses Lamber, a Lambda Calculus compiling language, to demonstrate threading combinators.
- A pipe function is introduced to initiate piping by taking an initial value and a curried function.
- The pipe function works by closing over a function and applying a continuation to it.
- A piped terminator is used to return the passed data, acting as an identity function.
- The implementation focuses on thread-last due to Lamber's tail-heavy function philosophy.
- Thread-first and multi-arg combinators are left as exercises for the reader.