2025-08-27 12:28:00
github.com
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.
Current development is working towards making spectrum self-check.
- usable
- pragmatic
- readable implementation
- fast
- configurable strictness levels
- incremental checking
- perfection
- correctness
- requiring 100% spec coverage.
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
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]
- because I could
- working example of types = proofs = predicates
- Some properties of a program are easier to prove at runtime. Some at compile-time
- this is extra checking on top of spec, not a replacement for it
- to get HN to shut up about how adding a static type system to a dynamic language is impossible
- why not just use spec by itself?
instrument
doesn’t check return valuescheck
works best on pure functions with good generators.- Not all clojure code is pure
- Not always easy to write a good generator for all functions (hello, any fn that takes a DB connection)
- Not always easy to write a generator w/ 100% coverage
- you can’t spec non-defn functions
- you can’t spec higher order functions
- generative testing with side-effects doesn’t work well
- generative testing gives false negatives on rare codepaths
- static typing guarantees all codepaths are checked
- spec doesn’t deal with non-fn vars at all (binding, alter-var-root, set!, etc)
- generative testing can be slow
Spectrum is still very early, and not ready for production use. Current development is focused on making spectrum self-check.
Copyright © 2019 Allen Rohner
Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.
Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!
Help Power Techcratic’s Future – Scan To Support
If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.
As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!
BITCOIN bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge Scan the QR code with your crypto wallet app |
DOGECOIN D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA Scan the QR code with your crypto wallet app |
ETHEREUM 0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a Scan the QR code with your crypto wallet app |
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.