Skip to content

Instantly share code, notes, and snippets.

@timmc
Last active June 23, 2020 15:25
Show Gist options
  • Save timmc/9d5a97eac25ac7bc524aa59f781dbd9b to your computer and use it in GitHub Desktop.
Save timmc/9d5a97eac25ac7bc524aa59f781dbd9b to your computer and use it in GitHub Desktop.
originally refheap.com/97879
(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