(defmacro defconstrainedfn
"Defines a function using the `contract` scheme with an additional `:body` element.
(defconstrainedfn sqr
\"Squares a number\"
[n] [number? (not= 0 n) => pos? number?]
(* n n))
Like the `contract` macro, multiple arity functions can be defined where each argument vector
is immediately followed by the relevent arity expectations.
"
[name & body]
(let [mdata (if (string? (first body))
{:doc (first body)}
{})
body (if (:doc mdata)
(next body)
body)
body (if (vector? (first body))
(list body)
body)
body (for [[args cnstr & bd] body]
(list* args
(second (build-constraints-map args cnstr))
bd))]
`(defn ~name
~(if (:doc mdata) (:doc mdata) "")
~@body)))
Used in 0 other vars
Comments top
No comments for defconstrainedfn. Log in to add a comment.