On Wed, Apr 22, 2015 at 9:25 AM, Maik Schünemann <maikschuenem...@gmail.com>
wrote:

> Andy Fingerhut <andy.finger...@gmail.com> writes:
>
> > As a silly example, if one gets to define their own equals for lists,
> > and you decide to define lists as equal if they contain the same
> > number of items, e.g. the list (1 2 3) is equal to the list (4 5 6)
> > because they both have 3 items, then you are easily going to violate
> > the property.
>
> another example is that in clojure
> '(2) is equal to [2] - and this is a good thing,
> but (conj '(2) 3) is not equal to (conj [2] 3).
>

 That is Example 1 in the article [1], and the example I have seen brought
up most often in this group over several years that violates the "x=y
implies f(x)=f(y)" property.  As stated there , it is a design choice to
make clojure.core/= true between lists, vectors, lazy sequences, etc. (Alex
Miller tells me the superset including all of these is "seqables").  I
think it is a reasonable design choice.


so I agree that the property x = y => f(x) = f(y) is not reasonable for
> normal equality. It could be for pure functions and identical?


My own opinion: the property x=y implies f(x)=f(y) is a useful one, but
there are cases where it is reasonable to write define = and write
functions f that violate the property.  For purposes like memoizing
functions, it is pretty important to know whether the function you want to
memoize violates it or not, and if so, in what precise way (because the way
it violates it might be acceptable for your purposes).

The property "(identical? x y) implies (identical? (f x) (f y))" is not
true for *many* Clojure functions, and identical? is not the way to go if
what you care about are immutable values, not identities.  Here is merely
one of many examples:

user=> (def x (inc' Long/MAX_VALUE))
#'user/x
user=> (identical? x x)
true
user=> (identical? (inc x) (inc x))
false


Andy

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to