Arrays are mutable, seqs immutable. Clojure ='s compares immutable
structures by value, and mutable structures by reference (for the
objects that it is aware of, for others it just prays that they have a
resoanable equals method). This behaviour is described in the very
interisting Henry Baker's egal Paper, and yields the cleanest equality
semantics that I know of.

On 23 mar, 14:24, Frank Siebenlist <frank.siebenl...@gmail.com> wrote:
> My REPL shows:
> ...
> user> (= (bytes (.getBytes "a"))(bytes (.getBytes "a")))
> false
> user> (= (seq (bytes (.getBytes "a"))) (seq (bytes (.getBytes "a"))))
> true
> ...
>
> in other words, "equality" for java byte arrays is defined differently than 
> their seq'ed version.
>
> It seems that the native arrays are compared on their reference while the 
> seq'ed version on their value (as it should...).
>
> Sometimes the seq'ing seems implied, however, like in:
>
> ...
> user> (first (bytes (.getBytes "a")))
> 97
> ...
>
> but for the "=" function it is not.
>
> This doesn't feel right and is confusing to say the least.
>
> Could anyone shed some light on this behaviour?
>
> Thanks, Frank.

-- 
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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to