Sanity is a clojure library which uses plug-in based macros to…
- deduce argument types based on argument names
- add type hints & assertions based on the former
Furthermore, the plug-in system can be used to enhance any macro you like in various ways.
You may simply specify the project as a dependency in your projects
project.clj using [de.karolski/sanity "0.1.0"]
.
Alternatively if you want the bleeding edge, clone the repository
and use leiningen’s lein install
command to install the library
into your local maven repo. After that you can use it inside your
own local projects by specifying [de.karolski/sanity
"0.1.0-SNAPSHOT"]
as a dependency.
Simple example defining a custom defn
:
(defpluggable
defn
[(argument-type-deducer-plugin :deduce-map {#"i" Long
#".*-fn" clojure.lang.AFunction
#".*text" String
})
(argument-type-assertion-plugin)
clojure.core/defn])
Once you have that defined (make sure you (:refer-clojure :exclude
[defn])
inside the namespace), you can use it like a normal defn
form. However, any argument which matches the regular expressions as
specified inside the :deduce-map
keyword argument to the
argument-type-deducer-plugin
will be type hinted and checked upon
function entry.
In case you don’t want to completely override defn
, you may also use with-pluggable
:
(with-pluggable
defn
[(argument-type-deducer-plugin :deduce-map {#"i" Long
#".*-fn" clojure.lang.AFunction
#".*text" String
})
(argument-type-assertion-plugin)
clojure.core/defn]
;; YOUR CODE HERE
)
This will only bind defn
within the local scope of with-pluggable
.
see this projects TODO.org
Copyright (C) 2011 FIXME
Distributed under the Eclipse Public License, the same as Clojure.