Last active
June 23, 2020 15:25
-
-
Save timmc/9d5a97eac25ac7bc524aa59f781dbd9b to your computer and use it in GitHub Desktop.
originally refheap.com/97879
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro essentially | |
"Like letfn, but with the bindings at the end. Connotes that the | |
bindings are not important for the core logic, just for logging, | |
metrics, debugging etc. Recommend using footnote-looking bindings such | |
as *0, *1, *2 or even Unicode daggers if you are super-brave. | |
This is like Haskell's `where`. Thanks to amalloy for the pointer; no | |
blame attaches to him, though." | |
[& args] | |
`(letfn ~(last args) | |
~@(butlast args))) | |
(defn do-a-thing | |
[foo bar baz] | |
(essentially | |
(let [grovel (+ foo (‡ (bar)))] | |
(baz grovel)) | |
[(‡ [v] (println "Bar was:" v) v)])) | |
;; => (do-a-thing 1 (constantly 2) -) | |
;; Bar was: 2 | |
;; -3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment