[squeak-dev] Circular definitions of size and do:

Bert Freudenberg bert at freudenbergs.de
Fri Sep 30 02:35:00 UTC 2011


On 29.09.2011, at 19:22, Rodney Polkinghorne wrote:

> Dear list
> 
> I wanted an array that lazily initialized elements 1 to n when you
> asked for the nth one.  So I ran something like:
> 
> SequenceableCollection variableSubclass #Foo ...
> 
> When I started a workspace, and tried Foo new: 10, my image hung.
> 
> Eventually, I found the problem.  The workspace tried to print the
> answered instance, which resulted in it being sent a do: message to
> print its elements.  This ran the method
> 
> SequenceableCollection>>do: aBlock
> 	1 to: self size do:
> 		[:index | aBlock value: (self at: index)]
> 
> which ran
> 
> Collection>>size
> 	| tally |
> 	tally := 0.
> 	self do: [:each | tally := tally + 1].
> 	^ tally
> 
> which sent do:, which sent size, which ...
> 
> Is this considered a bug, or a learning experience for new players?

The latter. You should not instantiate an abstract class. I don't think there is much that could be done about this. 

- Bert -

> ArrayedCollection avoids it by restoring the primitive method for
> size.
> 
> Rodney
> 





More information about the Squeak-dev mailing list