Skip to content

Commit

Permalink
Speculative 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Nov 9, 2018
1 parent de5539e commit c12252f
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 84 deletions.
31 changes: 10 additions & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
# Change Log
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
## [0.2.0]((https://github.com/slipset/speculative/releases/tag/v0.0.1)) (2018-11-09)

## [Unreleased]
### Changed
- Add a new arity to `make-widget-async` to provide a different widget shape.
* Specs for `=`, `/`, `apply` (clj only), `assoc`, `count`, `every?`, `filter`,
`first`, `get`, `juxt`, `not-any?`, `not-every?`, `range`, `partial`,
`remove`, `reset!`, `swap!`, `some`, `some?` and `str`.

* Test tools namespace `speculative.test` around `clojure.spec.test.alpha`. See
[here](doc/test.md).

## [0.1.1] - 2018-10-20
### Changed
- Documentation on how to make the widgets.
## [0.1.0](https://github.com/slipset/speculative/releases/tag/v0.0.1) (2018-10-20)

### Removed
- `make-widget-sync` - we're all async, all the time.

### Fixed
- Fixed widget maker to keep working when daylight savings switches over.

## 0.1.0 - 2018-10-20
### Added
- Files from the new template.
- Widget maker public API - `make-widget-sync`.

[Unreleased]: https://github.com/your-name/speculative/compare/0.1.1...HEAD
[0.1.1]: https://github.com/your-name/speculative/compare/0.1.0...0.1.1
* Initial release with specs for `map`, `filter`, `merge`, `merge-with`, `fnil`
and `reduce`.
90 changes: 28 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@
[![CircleCI](https://circleci.com/gh/slipset/speculative/tree/master.svg?style=svg)](https://circleci.com/gh/slipset/speculative/tree/master)
[![Clojars Project](https://img.shields.io/clojars/v/speculative.svg)](https://clojars.org/speculative)

speculative is a collection of specs for the functions in `clojure.core`. While its ultimate goal is to be rendered obsolete by these or similar specs being added to `clojure.core` proper, speculative hopefully provides some value while we're waiting for that to happen.
speculative is a collection of specs for the functions in `clojure.core`. While
its ultimate goal is to be rendered obsolete by these or similar specs being
added to `clojure.core` proper, speculative hopefully provides some value while
we're waiting for that to happen.

# Origins

The project started based on two tweets. First @mfikes tweeted

<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">I still hold the view that Clojure’s core fns should have specs. <br><br>Ex: While<br> (merge-with + [0 3] {0 7 1 2} {0 3 2 32})<br>produces a reasonable result, it is not even a map. A spec would reject 2nd arg.<br><br>What if I conclude dot products are possible via<br> (merge-with + [0 3] [1 2])<br>?</p>&mdash; Mike Fikes (@mfikes) <a href="https://twitter.com/mfikes/status/1053304266239197184?ref_src=twsrc%5Etfw">October 19, 2018</a></blockquote>

Then @borkdude tweeted a couple of days later:
<blockquote class="twitter-tweet" data-conversation="none" data-lang="en"><p lang="en" dir="ltr">Or maybe have a development version with guards and a production version without guards (I think Stu said something like this)</p>&mdash; (λ. borkdude) (@borkdude) <a href="https://twitter.com/borkdude/status/1053404362062606336?ref_src=twsrc%5Etfw">October 19, 2018</a></blockquote>
<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">I still
hold the view that Clojure’s core fns should have specs. <br><br>Ex: While<br>
(merge-with + [0 3] {0 7 1 2} {0 3 2 32})<br>produces a reasonable result, it is
not even a map. A spec would reject 2nd arg.<br><br>What if I conclude dot
products are possible via<br> (merge-with + [0 3] [1 2])<br>?</p>&mdash; Mike
Fikes (@mfikes) <a
href="https://twitter.com/mfikes/status/1053304266239197184?ref_src=twsrc%5Etfw">October
19, 2018</a></blockquote>

Then @borkdude tweeted a couple of days later: <blockquote class="twitter-tweet"
data-conversation="none" data-lang="en"><p lang="en" dir="ltr">Or maybe have a
development version with guards and a production version without guards (I think
Stu said something like this)</p>&mdash; (λ. borkdude) (@borkdude) <a
href="https://twitter.com/borkdude/status/1053404362062606336?ref_src=twsrc%5Etfw">October
19, 2018</a></blockquote>

## Rationale

With the new error-messages that are coming with Clojure 1.10, adding specs to the `clojure.core` functions give much better error messages.
With the new error-messages that are coming with Clojure 1.10, adding specs to
the `clojure.core` functions give much better error messages.

Without specs on `clojure.core/map` the error looks like:

Expand All @@ -42,7 +57,7 @@ Add the relevant coordinates to your favourite build tool:
deps.edn

```
speculative {:mvn/version "RELEASE"}
speculative {:mvn/version "0.0.2"}
```

lein
Expand Down Expand Up @@ -70,59 +85,8 @@ user=>
## Test tools

Namespace `speculative.test` provides macros and functions that are used in the
tests for speculative, but may also come in handy in other projects.

``` clojure
$ clj -Sdeps '{:deps {net.cgrand/macrovich {:mvn/version "0.2.1"}}}'
Clojure 1.10.0-RC1

user=> (require '[speculative.test :refer [check
with-instrumentation
gentest
success?]])
nil

user=> (require '[clojure.spec.alpha :as s])
nil

user=> (s/fdef foo
:args (s/cat :n number?)
:ret number?)
user/foo

user=> (defn foo [n]
"ret")
#'user/foo

user=> (check `foo [1])
Evaluation error - invalid arguments to null at clojure.spec.test.alpha/explain-check (alpha.clj:278).
"ret" - failed: number? at: [:ret]

user=> (s/fdef foo
:args (s/cat :n number?)
:ret string?)
user/foo

user=> (check `foo [1])
"ret"

user=> (with-instrumentation `foo
(foo "a"))
Evaluation error - invalid arguments to user/foo at (NO_SOURCE_FILE:15).
"a" - failed: number? at: [:n]

user=> (foo "a")
"ret"

user=> (gentest `foo nil {:num-tests 1})
generatively testing user/foo
({:spec #object[clojure.spec.alpha$fspec_impl$reify__2524 0x72bd06ca "clojure.spec.alpha$fspec_impl$reify__2524@72bd06ca"], :clojure.spec.test.check/ret {:result true, :pass? true, :num-tests 1, :time-elapsed-ms 1, :seed 1541249961647}, :sym user/foo})

user=> (success? *1)
true

user=>
```
tests for speculative, but may also come in handy in other projects. Read about
it [here](doc/test.md).

## Issues found

Expand All @@ -144,8 +108,10 @@ user=>

## Contributing

In the hope that the code in this project would be useful for `clojure.core`, any contributer to this repo needs to have a
[Contributor Agreement](https://clojure.org/community/contributing) for Clojure so that any code in speculative can be used in either Clojure or Clojurescript.
In the hope that the code in this project would be useful for `clojure.core`,
any contributer to this repo needs to have a [Contributor
Agreement](https://clojure.org/community/contributing) for Clojure so that any
code in speculative can be used in either Clojure or Clojurescript.

Take a look at the [style guide](doc/style.md).

Expand Down
56 changes: 56 additions & 0 deletions doc/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## Test tools

Namespace `speculative.test` provides macros and functions that are used in the
tests for speculative, but may also come in handy in other projects.

``` clojure
$ clj -Sdeps '{:deps {net.cgrand/macrovich {:mvn/version "0.2.1"}}}'
Clojure 1.10.0-RC1

user=> (require '[speculative.test :refer [check
with-instrumentation
gentest
successful?]])
nil

user=> (require '[clojure.spec.alpha :as s])
nil

user=> (s/fdef foo
:args (s/cat :n number?)
:ret number?)
user/foo

user=> (defn foo [n]
"ret")
#'user/foo

user=> (check `foo [1])
Evaluation error - invalid arguments to null at clojure.spec.test.alpha/explain-check (alpha.clj:278).
"ret" - failed: number? at: [:ret]

user=> (s/fdef foo
:args (s/cat :n number?)
:ret string?)
user/foo

user=> (check `foo [1])
"ret"

user=> (with-instrumentation `foo
(foo "a"))
Evaluation error - invalid arguments to user/foo at (NO_SOURCE_FILE:15).
"a" - failed: number? at: [:n]

user=> (foo "a")
"ret"

user=> (gentest `foo nil {:num-tests 1})
generatively testing user/foo
({:spec #object[clojure.spec.alpha$fspec_impl$reify__2524 0x72bd06ca "clojure.spec.alpha$fspec_impl$reify__2524@72bd06ca"], :clojure.spec.test.check/ret {:result true, :pass? true, :num-tests 1, :time-elapsed-ms 1, :seed 1541249961647}, :sym user/foo})

user=> (successful? *1)
true

user=>
```
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject speculative "0.0.2-SNAPSHOT"
(defproject speculative "0.0.2"
:description "A collection of specs for clojure.core functions"
:url "https://github.com/slipset/speculative"
:license {:name "Eclipse Public License"
Expand Down

0 comments on commit c12252f

Please sign in to comment.