[Q] LinkedList

Matej Kosik kosik at fiit.stuba.sk
Mon Mar 21 11:05:54 UTC 2005


Matej Kosik wrote:
> Hello,
> 
> LinkedList does not respond to
>     second
>     third
>     ...
>     at:
> messages. Do you think that it makes sense? I would expect something 
> else. Is this a purpose or an omission?

Actually, the LinkedList responds to those messages, but those methods 
fail with an error

	LinkedLists are not indexable

I think that all sequenceable collections should be indexable, even if 
in this particular case the implementation of this operation wouldn't 
have constant time complexity as it is in case of arrays.

When such a functionality misses, and we still need to refer to 
particular linked list elements, it results in a awkward code like:

	self should: [(link := mailbox items first) == mail1].
	self should: [(link := link nextLink) == mail2].
	self should: [(link := link nextLink) == mail3].
	self should: [(link := link nextLink) == slit1].
	self should: [(link := link nextLink) == mail4].
	self should: [(link := link nextLink) == slit2].
	self should: [(link := link nextLink) == mail5].
	self should: [(link := link nextLink) == mail6].
	self should: [(link := link nextLink) == slit3].

Instead of its straightforward and clear variant:


	self should: [(mailbox items at: 1) == mail1].
	self should: [(mailbox items at: 2) == mail2].
	self should: [(mailbox items at: 3) == mail3].
	self should: [(mailbox items at: 4) == slit1].
	self should: [(mailbox items at: 5) == mail4].
	self should: [(mailbox items at: 6) == slit2].
	self should: [(mailbox items at: 7) == mail5].
	self should: [(mailbox items at: 8) == mail6].
	self should: [(mailbox items at: 9) == slit3].


-- 
  http://altair.dcs.elf.stuba.sk/wiki/Kosik/Main
   icq: 300133844
phone: 0910-993-245



More information about the Squeak-dev mailing list