Skip to content

Instantly share code, notes, and snippets.

@bsless
Created April 22, 2022 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsless/27676a6ead322368d3d36b6bfbdd09a0 to your computer and use it in GitHub Desktop.
Save bsless/27676a6ead322368d3d36b6bfbdd09a0 to your computer and use it in GitHub Desktop.
Make thunks of Clojure expressions, can be named
(defmacro $ [& body] `(fn ~'thunk [] ~@body))
;;; best effort to create a named function
(defmacro $
[& body]
(let [name (or (and (sequential? (first body))
(symbol? (ffirst body))
(-> body ffirst name (str "-thunk") symbol))
'thunk)]
`(fn ~name [] ~@body)))
($ (str "foo" "bar"))
;; => #function[user/eval9453/str-thunk--9454]
(($ (str "foo" "bar")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment