#== (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: pharo-project-bounces@lists.gforge.inria.fr [pharo-project-bounces@lists.gforge.inria.fr] On Behalf Of Igor Stasenko [siguctua@gmail.com] Sent: Monday, September 27, 2010 5:28 AM To: Pharo-project@lists.gforge.inria.fr Subject: Re: [Pharo-project] ('a' == 'a') == true ? On 27 September 2010 11:54, Johan Brichau <johan@inceptive.be> 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 Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Best regards, Igor Stasenko AKA sig. _______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project