Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

The ClojureScript docstring for case says, "The test-constants are not evaluated." But that statement is not complete. The ClojureScript "Differences from Clojure" page https://www.clojurescript.org/about/differences says ":const metadata: ... causes case test constants which are symbols resolving to ^:const Vars to be inlined with their values". The case docstring should reflect that. Related discussion at https://groups.google.com/d/msg/clojure/u1RZsmjbQ64/p7B9eRwuAQAJ.

7 Answers

0 votes
by

Comment made by: ethan

Hi, after a brief discussion on #clj-dev, I've produced a patch for this issue. Link to #clj-dev conversation: https://clojurians.slack.com/archives/C07UQ678E/p1538575162000100. Please let me know if any further changes may be advisable.

One change that might need some attention is the short sentence describing that this behavior differs from Clojure.

0 votes
by

Comment made by: mfikes

Hey Ethan, have you signed the CA?

0 votes
by

Comment made by: ethan

Hi Mike, I did. Talked to David and he said it will have been filed in the necessary place automatically.

0 votes
by

Comment made by: mfikes

Hey Ethan, the attached patch is not in the right format. Please see https://clojurescript.org/community/patches for the command to use in order to create the patch.

0 votes
by

Comment made by: ethan

Hi Mike, thank you for letting me now. I followed the instructions on the page you linked, and have attached a new patch file.

0 votes
by

Comment made by: mfikes

The copy in CLJS-2209.patch looks great to me. I really like how the material related to non-evaluation or evaluation of test constants is grouped into the middle paragraph.

For reference here is what the docstring looks like with the patch applied:

`

cljs.user=> (doc case)

cljs.core/case
([e & clauses])
Macro
Takes an expression, and a set of clauses.

Each clause can take the form of either:

test-constant result-expr

(test-constant1 ... test-constantN) result-expr

If the expression is equal to a test-constant, the corresponding
result-expr is returned. A single default expression can follow the
clauses, and its value will be returned if no clause matches. If no
default expression is provided and no clause matches, an Error is thrown.

The test-constants are not evaluated. They must be compile-time
literals, and need not be quoted. The only exception to this holds for
the use of test-constants that are symbols resolving to constant Vars
(Vars with ^:const metadata). In this case, the constant's value is inlined.
Please note that this behavior differs from Clojure, which will not inline
the value.

Unlike cond and condp, case does a constant-time dispatch, the
clauses are not considered sequentially. All manner of constant
expressions are acceptable in case, including numbers, strings,
symbols, keywords, and (ClojureScript) composites thereof. Note that since
lists are used to group multiple constants that map to the same
expression, a vector can be used to match a list if needed. The
test-constants need not be all of the same type.

nil
`

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-2209 (reported by alex+import)
...