Skip to content

Instantly share code, notes, and snippets.

@qbg
Created December 28, 2010 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save qbg/757885 to your computer and use it in GitHub Desktop.
Save qbg/757885 to your computer and use it in GitHub Desktop.
;;; 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