The code I have trouble with is in my workspace where I execute via
'DoIt'
<code>
|contacts copy|
contacts := MyContact contacts.
copy := contacts deepCopy.
(contacts = copy) ifTrue: [true inspect]
ifFalse: [false inspect]
</copy>
When I use #copy instead of #deepCopy the code correctly enters the
ifTrue path. Both contacts and copy show the same under inspection
and explore.
all inst vars:
array: an Array(nil nil a MyContact a MyContact nil nil nil nil
nil nil)
firstIndex: 3
lastIndex: 4
Class methods for MyContact:
<code>
contacts
"Answers the storage for contacts"
Database isNil ifTrue: [self createSampleDatabase].
^ Database
createSampleDatabase
Database := (OrderedCollection new)
add: (self name: 'Bob Jones' emailAddress: '
bob <at> gmail.com');
add: (self name: 'Steve Smith' emailAddress:
'
steveS <at> gmail.com');
yourself
</code>
Database is an instance variable of MyContact.
The code failing is in the method
<code>
hasEqualElements: otherCollection
"Answer whether the receiver's size is the same as
otherCollection's
size, and each of the receiver's elements equal the
corresponding
element of otherCollection.
This should probably replace the current definition of #= ."
| size |
(otherCollection isKindOf: SequenceableCollection) ifFalse: [^
false].
(size := self size) = otherCollection size ifFalse: [^ false].
1 to: size do:
[:index |
(self at: index) = (otherCollection
at: index) ifFalse: [^ false]].
^ true
= anObject
"Answer whether the receiver and the argument represent the same
object. If = is redefined in any subclass, consider also
redefining the
message hash."
^self == anObject
</code>
The '#=' code executes a '#==' and fails. Why is it excuting '#==' ?
Obviously it would fail for deepCopy.
Thanks