Last active
October 13, 2022 20:22
-
-
Save hiredman/b2096b04927a9c9db480c39806dac297 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 let-macro | |
([bindings body] | |
(let [names (map first bindings)] | |
`(let-macro ~(eval `(letfn ~bindings ~(into {} (map (fn [n] [(list 'quote n) n])) names))) | |
~identity | |
~body))) | |
([bindings k body] | |
(cond (and (seq? body) | |
(symbol? (first body)) | |
(contains? bindings (first body))) | |
`(let-macro ~bindings ~k ~(apply (get bindings (first body)) (rest body))) | |
(and (seq? body) | |
(symbol? (first body)) | |
(= "quote" (name (first body)))) | |
body | |
(and (or (vector? body) (seq? body)) (seq body)) | |
`(let-macro ~bindings | |
~(partial (fn f [i o v] | |
(if (seq i) | |
`(let-macro ~bindings | |
~(partial f (rest i) (conj o v)) | |
~(first i)) | |
(do | |
(prn "body" body (conj o v)) | |
(k ((if (vector? body) identity seq) (conj o v)))))) | |
(rest body) | |
[]) | |
~(first body)) | |
(and (coll? body) (not (record? body))) | |
`(let-macro ~bindings ~(fn [v] | |
(prn "v" v) | |
(k (into (empty body) v))) ~(seq body)) | |
:else | |
(k body)))) |
Author
hiredman
commented
Oct 13, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment