#== (test for identity/same object) is perhaps most useful when verifying that 
objects are copying themselves as intended, or that code has or has not made a 
copy of an object - I lost a few hours this weekend over a glorified version of 
just that question :(  Found it :)

Literals can sometimes be confusing, being identical (courtesy of the compiler) 
when one might otherwise think they should be distinct but equal objects.  As 
for whether a string and a symbol should have the same address, I am not 
convinced they would, but a good exercise for your students would be to make a 
C function that prints on stdout and/or returns the address of something passed 
to it, and then call it with both 'hello' and 'hello' asSymbol, #hello, etc.

Bill


________________________________________
From: [email protected] 
[[email protected]] On Behalf Of Igor Stasenko 
[[email protected]]
Sent: Monday, September 27, 2010 5:28 AM
To: [email protected]
Subject: Re: [Pharo-project] ('a' == 'a') == true ?

On 27 September 2010 11:54, Johan Brichau <[email protected]> wrote:
>
> On 27 Sep 2010, at 10:38, Lukas Renggli wrote:
>
>>> Am I wrong?
>>
>> Yes, almost always one should probably use #= instead of #==.
>
> I will add that to the exercise :-)
> The exercise actually makes students aware of the difference between strings 
> and symbols (which should be pointer-equal)
>

I think you can avoid using 'equal' word when describing a #== comparison.
It can be explained as 'test whether comparands are same object or not'
while #= is test whether two objects equal or not.

Also keep in mind that #== optimized by compiler. So , even if you
override it in some class,
it won't behave differently.

And #=, of course, can be implemented in any way you like. One of
interesting example:

= anObject
 ^ false

saying 'i am not equal to anything' :)


> Johan
> _______________________________________________
> Pharo-project mailing list
> [email protected]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to