Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…


Cannot retrieve contributors at this time

file 62 lines (43 sloc) 1.36 kb


First add the following to your Leiningen project.clj file in the :dependencies section:

[org.clojure/core.contracts "0.0.1"]

To include core.contracts, add it to your namespace declaration:

(ns my.awesome.lib
    [clojure.core.contracts :as contracts]))

Write your functions as you normally would:

(defn sqr [n] (* n n))

(sqr 10)
;=> 100

(sqr 0)
;=> 0

Later, annotate your functions separately with the constraints:

  (sqr "Constraints for squaring" 
    [x] [number? (not= 0 x) => number? pos?]))

The core.contracts validation will occur at run-time:

(sqr 10)
;=> 100

(sqr 0)
; java.lang.AssertionError: 
;   Pre-condition failed: (not= 0 x)

To turn-off contracts for any given file, add the following to the top of the file in question before compiling:

(set! *assert* false)
Something went wrong with that request. Please try again.