Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active December 22, 2017 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/a48780bec910e8c53a5b32e49f0d12f0 to your computer and use it in GitHub Desktop.
Save mfikes/a48780bec910e8c53a5b32e49f0d12f0 to your computer and use it in GitHub Desktop.
core.specs.alpha

The core.specs.alpha library has been ported to ClojureScript, and is available in this release as an opt-in feature. This library contains specs that describes core macros and functions. Support for the ns special form is additionally included.

To use this library, simply require the new cljs.core.specs.alpha namespace. By doing this, specs for defn, let, and other macros will be registered, and subsequent compilation of these macros will be subject to spec validation.

The following illustrates its use at the REPL. Let's say you accidentally attempt to refer all symbols of a library, using a Clojure-specific feature that does not exist in ClojureScript:

 cljs.user=> (require '[clojure.set :refer :all])
 clojure.lang.ExceptionInfo: Don't know how to create ISeq from: clojure.lang.Keyword at line 1 ...

This error is a bit cryptic. Now, let's try again, but using core.specs.alpha:

cljs.user=> (require 'cljs.core.specs.alpha)
nil
cljs.user=> (require '[clojure.set :refer :all])
clojure.lang.ExceptionInfo: Call to cljs.core/require did not conform to spec:
In: [0 1 :refer] val: :all fails spec: :cljs.core.specs.alpha/refer at: 
[:args :spec :libspec :lib+opts :options :refer] predicate: coll?
...

The resulting error is essentially indicating that :refer takes a collection as its argument.

This feature is still alpha, but we encourage you to give it a try and report any defects you might find!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment