Skip to content

Commit

Permalink
Don't simplify keywords to nil (mentat-collective#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
sritchie authored Apr 20, 2023
1 parent be38526 commit eb71f18
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [unreleased]

- #131 fixes accidental simplification of keywords to `nil`.

## [0.30.0]

- #126:
Expand Down
74 changes: 74 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
## Dev Dependencies

- [node.js](https://nodejs.org/en/)
- The [clojure command line tool](https://clojure.org/guides/install_clojure)
- [Babashka](https://github.com/babashka/babashka#installation)

## Github Pages, Docs Notebook

The project's [Github Pages site](https://emmy.mentat.org) hosts an
interactive [Clerk](https://github.com/nextjournal/clerk) notebook demonstrating
the library's use.

### Local Notebook Dev

Start a Clojure process however you like, and run `(user/serve!)` to run the
Clerk server. This command should open up `localhost:7777`.

Alternatively, run

```sh
bb clerk-watch
```

### Static Build

To test the static build locally:

```
bb publish-local
```

This will generate the static site in `public/build`, start a development http
server and open up a browser window (http://127.0.0.1:8080/) with the production
build of the documentation notebook.

### GitHub Pages

To build and release to Github Pages:

```
bb release-gh-pages
```

This will ship the site to https://emmy.mentat.org.

## Publishing to Clojars

The template for the project's `pom.xml` lives at
[`template/pom.xml`](https://github.com/mentat-collective/emmy/blob/main/template/pom.xml).

To create a new release:

- Update the version in
[resources/EMMY_VERSION](https://github.com/mentat-collective/emmy/blob/main/resources/EMMY_VERSION)
- Make a new [Github
Release](https://github.com/mentat-collective/emmy/releases) with tag
`v<the-new-version>`.

Submitting the release will create the new tag and trigger the following
command:

```
bb release
```

The new release will appear on Clojars.

## Linting

Code is linted with [`clj-kondo`](https://github.com/clj-kondo/clj-kondo):

```
bb lint
```
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ documentation, you'll need to install
- The [Clojure command line tool](https://clojure.org/guides/install_clojure)
- [Babashka](https://github.com/babashka/babashka#installation)

Once this is done, run this command:
Next, clone the repository:

```bash
git clone [email protected]:mentat-collective/emmy.git
cd emmy
```

Run this command in the cloned repository:

```sh
bb clerk-watch
Expand Down
Binary file modified doc/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/emmy/generic.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
(:refer-clojure :exclude [/ + - * divide infinite? abs])
(:require [emmy.util :as u]
[emmy.util.def :refer [defgeneric]]
[emmy.value :as v]))
[emmy.value :as v])
#?(:clj (:import (clojure.lang Keyword))))

;; ## Generic Numerics
;;
Expand Down Expand Up @@ -1015,6 +1016,11 @@ defaults to `ln((1 + sqrt(1+x^2)) / x)`."
(defgeneric simplify 1)
(defmethod simplify :default [a] a)

;; `defgeneric` installs a metadata-lookup handler for keywords by default; in
;; this case, we want to override that feature so that keywords simplify to
;; themselves.
(defmethod simplify [#?(:clj Keyword :cljs 'cljs.core/Keyword)] [a] a)

;; This call registers a symbol for any non-multimethod we care about. These
;; will be returned instead of the actual function body when the user
;; calls `(v/freeze fn)`, for example.
Expand Down
8 changes: 8 additions & 0 deletions test/emmy/generic_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@
(is (= x (g/divide x 1)) "dividing by one a single time returns the input")
(is (= x (g/divide x 1 1 1 1.0 1)) "dividing by 1 returns the input")))

(deftest simplify-tests
(checking "g/simplify" 100 [k gen/keyword]
(is (= k (g/simplify k)) "keywords simplify to themselves."))

(is (= [:div "cake"]
(g/simplify [:div "cake"]))
"Keywords simplify to themselves inside of nested structures"))

(defn ^:private is* [eq actual expected]
(is (eq actual expected)
#?(:clj (format "expected: %s\n actual: %s"
Expand Down

0 comments on commit eb71f18

Please sign in to comment.