it seems very difficult to get a proper source of information about Squeak. I have a few basic questions about it:
does '=' check for equality by refrence?
does '==' check for equality of values?
collection - linked list - if I do something like:
list := LinkedList new. element := list first.
does it mean that element and 'list first' are both references to the same place in memory (the first place in thr linked list?)
- why do I need to override the operator = for linked list? and how do I do it?
By default
==is equality by reference. In Object=is defined asBut other classes usually override it. For example in Character
=is defined asYou can get all implementors of
=by executing#= implementors.In your case
elementandlist firstare referencing the same object. This is becausefirstis implemented asAnd
atreturns the element on position 1. But iffirstwould be implemented asthen it would return a copy of an element (or if you use
element := list first copy) and then they will returnfalsewhen compared with==, but if=is implemented in a smart way it should returntruein most cases.Also be sure that you want to use LinkedList because in pharo which is a fork of squeak it is used mostly for process scheduling and I think that there was a discussion that LinkedList is more of a utility collection. The most used collection with random access features is
OrderedCollection