[CLJ-1333] Documentation for "=" is misleading Created: 30/Jan/14 Updated: 14/Feb/14 |
|
Status: | Open |
Project: | Clojure |
Component/s: | None |
Affects Version/s: | Release 1.5 |
Fix Version/s: | None |
Type: | Enhancement | Priority: | Minor |
Reporter: | George | Assignee: | Unassigned |
Resolution: | Unresolved | Votes: | 0 |
Labels: | docs | ||
Environment: |
linux 2.6.32-431.el6.x86_64 |
Description |
Document for clojure.core/= says it compares numbers in a type-independent manner. In reality the comparission is made in a type dependent manner. If the above statement was true then (= 1 1.0) would eval to true not false; clojure.core/= |
Comments |
Comment by Kevin Downey [ 02/Feb/14 4:58 PM ] |
I think this is a little more complex than described. = does compare things in a jvm type independent manner, but it does use what people have taken to calling "equality classes" (= [1 2] '(1 2)) (= {:a 1} (doto (java.util.HashMap.) (.put :a 1))) etc. now for numbers, it seems logical to me, to have floating point and precise numbers in distinct equality classes in which case, 1.0 and 1 are in distinct equality classes, so not equal. |
Comment by Gary Fredericks [ 13/Feb/14 10:16 PM ] |
The docstring is definitely misleading for people unfamiliar with this sort of thing though. Numbers are probably the first thing that the words "type independent manner" bring to mind. A brief pointer to the == function might be useful. |
Comment by George [ 14/Feb/14 5:47 AM ] |
I find == function to be confusing and doc says: |
Comment by Alex Miller [ 14/Feb/14 7:56 AM ] |
@George - that last example (== 1 1.0M) is actually a bug that is fixed in 1.6 where it will return true. |