Created
April 22, 2022 14:13
-
-
Save bsless/27676a6ead322368d3d36b6bfbdd09a0 to your computer and use it in GitHub Desktop.
Make thunks of Clojure expressions, can be named
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 $ [& 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