Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Checkers within prerequisites

marick edited this page · 3 revisions
Clone this wiki locally

Suppose you want a prerequisite function to return 3 no matter what its argument. That's done like this:

      (f 33) => 3
         (g anything) => 3))  ;; 3 is returned any time g is called.

Most of the time, a function not a predefined checker is matched exactly, as that seems to be what people naturally expect. Consider this function:

      (f 33) => 3
         (filter even? [1 2 3]) => [2]))

Here, the main purpose of the prerequisite is probably to document that filter is called a certain way. If you do want to use even? as a checker, wrap it in as-checker:

      (f 33) => 3
         (g (as-checker even?)) => 3))  ;; g will be called with some even number and should return 3.

You can use the as-checker wrapper with anonymous functions, but you can also use checker as shorthand:

      (f 33) => 3
         (g (checker [actual] (...))) => 3))

That is, just replace the fn in the function definition with checker.

If you'll be using a predicate in many prerequisites, you can make a named checker with defchecker:

     (defchecker prime
       "Checks whether the actual value is a prime"

To emphasize: you only need to define checkers specially for prerequisites. If you want to describe facts, like this:

     (fact 17 => prime?)

... you don't need as-checker, checker, or defchecker.

Something went wrong with that request. Please try again.