ClojureScript

= in ClojureScript differs from Clojure API for arities other than 2

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Using ClojureScript f4c0de502c92ce710da923888d672f22213b902c (checked out on Thu Jan 19 2012)
=> (= 1)
false ;; incorrect

=> (= 1 1)
true

=> (= 1 1 2)
true ;; incorrect

=> (= 1 1 1)
true ;; correct, but by accident

In Clojure and according to Clojure's API = is defined for all arities [1,2]
=> (= 1)
true

=> (= 1 1)
true

=> (= 1 1 2)
false

The source of this bug is that = is only implemented in ClojureScript for the 2 arity [3]. Combined with the javascript behaviour for superfluous arguments this leads to these unfortunate results. Implementing = for multi arities in ClojureScript by following the Clojure implementation should fix this. See for example the <
predicate in ClojureScript [4].

[1] = API - http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/=
[2] = in clj - https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L719
[3] = in cljs - https://github.com/clojure/clojurescript/blob/master/src/cljs/cljs/core.cljs#L180
[4] < in cljs as an example of a multi-arity predicate - https://github.com/clojure/clojurescript/blob/master/src/cljs/cljs/core.cljs#L801

Activity

Hide
David Nolen added a comment -

Just to clarify = is the generic equivalence test, the numeric operator == supports what you're describing just fine.

Show
David Nolen added a comment - Just to clarify = is the generic equivalence test, the numeric operator == supports what you're describing just fine.
Hide
David Nolen added a comment -

Also if someone comes up with a patch it would be nice if it came along w/ some benchmarks.

Show
David Nolen added a comment - Also if someone comes up with a patch it would be nice if it came along w/ some benchmarks.
Hide
David Nolen added a comment -

CLJS-137 is nearing resolution - once it is we can address this one.

Show
David Nolen added a comment - CLJS-137 is nearing resolution - once it is we can address this one.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: