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
element
andlist first
are referencing the same object. This is becausefirst
is implemented asAnd
at
returns the element on position 1. But iffirst
would be implemented asthen it would return a copy of an element (or if you use
element := list first copy
) and then they will returnfalse
when compared with==
, but if=
is implemented in a smart way it should returntrue
in 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