REPL Experiments with Clojure Specλ︎
Create a minimal Project
Clojure Spec can be tried without creating a Clojure project, although creating a project is useful if saving the Clojure Spec code experiments.
Create a minimal Clojure project with a Clojure CLI deps.edn configuration.
Run a Clojure REPL with a rich terminal UI
A REPL with a rich terminal UI and tools to support the Practicalli REPL Reloaded workflow.
Require the clojure.spec.alpha
using an alias called spec
to use functions from that namespace.
NOTE:
clojure.spec.alpha
is often aliased ass
, although Practicalli avoids
Spec auto-completionλ︎
Using rebel-readline for the Clojure REPL will show autocompletion for all spec functions once the spec namespace has been required.
Type
(spec /
and pressTAB
to list all the functions in the namespace.
Typing a space character after the full name of a function shows the function signature with arguments that should be passed to that function.
Ctrl x Ctrl d displays the documentation for the current function
Check data conforms to specificationλ︎
Use the spec/conform
and spec/valid?
functions to test if data matches a specification. In these examples, predicate functions are used as a specification.
Example expressionsλ︎
spec/conform
will return the value if it conforms to the specification, or :clojure.spec.alpha/invalid
if the data does not conform.
Clojure Spec - Conform values
spec/valid?
returns true or false