Namespaces

 
0.3.2 permalink Arrow_down_16x16

defconstrainedfn

fogus.me.trammel

  • (defconstrainedfn name & body)
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.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source fogus/me/trammel.clj:161 top

(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)))
Vars in fogus.me.trammel/defconstrainedfn: defmacro let name concat defn list seq
Used in 0 other vars

Comments top

No comments for defconstrainedfn. Log in to add a comment.