-
-
Save fogus/760696 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
;;; Almost complete opinionated defn implementation | |
;;; Does not put the arg vector on the metadata | |
(defsyntax-class distinct-argument-vector [] | |
"distinct argument vector" | |
[] | |
[var ...] | |
:fail-when (check-duplicate (syntax (var ...))) "duplicate binding form") | |
(defsyntax-class docstring [] | |
"docstring" | |
[] | |
(+var doc c-string) | |
:with meta (+code {:doc (syntax doc)}) | |
(+head) | |
:with meta {}) | |
(defsyntax-class attr-map [] | |
"attribute map" | |
[] | |
(+var meta c-map) | |
(+head) | |
:with meta {}) | |
(defsyntax-rules my-defn [] | |
(my-defn name :> c-symbol | |
doc :> docstring | |
am :> attr-map | |
av :> distinct-argument-vector | |
body ...) | |
(def (+code (with-meta (syntax name) | |
(conj (syntax doc.meta) | |
(syntax am.meta)))) | |
(fn [av.var ...] | |
body ...)) | |
(my-defn name :> c-symbol | |
doc :> docstring | |
am :> attr-map | |
(av :> distinct-argument-vector | |
body ...) ...) | |
(def (+code (with-meta (syntax name) | |
(conj (syntax doc.meta) | |
(syntax am.meta)))) | |
(fn ([av.var ...] body ...) ...))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment