NEWBIE Question: == vs =?
John M McIntosh
johnmci at smalltalkconsulting.com
Wed Jan 24 20:21:09 UTC 2001
>What exactly is the difference between the two boolean mesages: #== and #= ?
>
>Can someone give an example where #== results in true but not #= ?
>(and vice versa?)
>
>Much thanks ahead of time,
>Phuong Bui
If you look
Interpreter>>primitiveEquivalent
| thisObject otherObject |
otherObject _ self popStack.
thisObject _ self popStack.
self pushBool: thisObject = otherObject
This is invoked from the only one implementor of #== in the Squeak image.
ProtoObject>> ==
== anObject
"Primitive. Answer whether the receiver and the argument are the same
object (have the same object pointer). Do not redefine the
message == in
any other class! Essential. No Lookup. Do not override in any subclass.
See Object documentation whatIsAPrimitive."
<primitive: 110>
self primitiveFailed
The "C" code produced for the VM just checks to see if the address of
this object is = to the address of that object. If they are then of
course they are the same object.
Now to answer your questions about #== true but #= false. Well you
would need a broken #= to have that case. However the reverse of
course can be true
#= is true, but of course #== can be false.
Now #= is implemented 55 times in the image and can be quite complex
= aCT
self class == aCT class ifFalse:[^false].
^rAdd = aCT rAdd and:[rMul = aCT rMul and:[
gAdd = aCT gAdd and:[gMul = aCT gMul and:[
bAdd = aCT bAdd and:[bMul = aCT bMul and:[
aAdd = aCT aAdd and:[aMul = aCT aMul]]]]]]]
If you have a bug where side effects of a message sent could alter an
object, then sure you could have #== is true but #= is false because
the object gets changed while checking it's state, but it's really a
bug. I guess also having a high priority process alter the object
well testing #= could also raise issues.
--
--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com
===========================================================================
Custom Macintosh programming & various Smalltalk dialects
PGP Key: DSS/Diff/46FC3BE6
Fingerprint=B22F 7D67 92B7 5D52 72D7 E94A EE69 2D21 46FC 3BE6
===========================================================================
More information about the Squeak-dev
mailing list
|