Il giorno 18/mag/2015, alle ore 18.06, Atticus ha scritto:

> I guess it's a matter of definition. I must admit that i didn't reflect
> on equality that much.
> 
> My (very limited) knowledge about that stuff comes mostly from the "The
> Little Schemer" which imho explains it really well with the 'eqan?' and
> 'eqlist?' procedure.
> 
> The reason why i checked (eq? 'symbol1 'symbol2) in the first place in
> racket was because in gambit scheme (eq? "string" "string") returned #f
> and in racket returns #t. I just wanted to check the differences between
> racket and gambit and was really surprised as (eq? 'symbol1 'symbol2)
> returned #f in the racket repl (which was likely because of escape
> characters)

It's great to see someone do these checks. I guess it's important to realize
that (eq? 'symbol 'symbol) should always return true because of its definition.
If it does not return true than that would be a real error and as symbols are
usually used all over the place to denote unimplemented concepts the system
would break early on. I was not able reproduce the described behavior but
one never knows ...

Comparing  two strings on the other hand is not defined for eq? or let's say 
it's
defined as unspecified. That's because some implementations might create a
new data object for each string and return #f for (eq? "string" "string"). Other
implementations try to save memory and realize that "string" and "string" have
the same content so they can be substituted by a pointer to one data structure
containing "string". But I cannot rely on that behavior because in other 
situations
the same string might be represented by another pointer to a different data
structure. So eq? only checks for equality of pointers to data structures. Two
different lists with the same content are not equal because list creates a new
data object each time it's called: (eq? (list 'a) (list 'a)) => #f
The only exception to that definition is the empty list '() (or null):
(eq? '() '()) returns true by definition.
Comparing two empty strings with (eq? "" "") does not make sense on the other
hand because the return value of eq? is unspecified when comparing strings.
Unspecified means it might be true, it might be false but I cannot count on it.

To check for the equality of strings one needs to use equal? which is defined to
analyze the contents of the data structures and not the pointers. Same for lists
(equal? (list 'a) (list 'a)) => true
(equal? "string" "string") => true

Rackets 's reference and guide sometimes are a bit vague about these things.
So it's better to check their current standard R6RS. When you open the
documentation and search for eq? you should see several results:
rnrs/base-6 is the one you want to have a look at. But as far as I could see 
Gambit
does not support R6RS so you might want to check r5rs, too.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to