A library for doing static analysis of Clojure code, catching clojure.spec conform errors at compile time.
Wait what?
It's like core.typed, but it relies on clojure.spec annotations.
So it's an optional static type system?
Kind-of. It finds errors at compile time, and predicates kind of look like types. So sure.
Developer Preview, not yet ready for any kind of use. master
may not
compile. Tests definitely won't pass.
Current development is working towards making spectrum self-check.
In particular, spectrum aims to be fast and usable, and catching bugs. It aims to have low false positives, at the expense of potentially not catching 100% of type errors.
A tool that catches 80% of bugs that you use every day is better than a 100% tool that you don't use. Spectrum will converge on 100% correct, but won't guarantee correctness for a while.
Still under active development, so this is incomplete.
Use clojure.spec as normal. Then, at the repl:
(require '[spectrum.flow :as f])
(require '[spectrum.types :as t])
(f/infer-var #'foo)
There is also
(f/infer-form '(foo 3))
which is useful when you want to debug the signature of a form.
infer-form
can optionally take a map of keywordized variables to types
(f/infer-form '(string? x) {:x #'string?})
#Value[true]
(f/infer-form '(string? x) {:x (t/value-t 3)})
#Value[false]
instrument
doesn't check return valuescheck
works best on pure functions with good generators.Spectrum is still very early, and not ready for production use. Current development is focused on making spectrum self-check.
Copyright © 2019 Allen Rohner
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close