[Newbies] Populate a new array.

Bert Freudenberg bert at freudenbergs.de
Thu Mar 15 11:01:44 UTC 2007

On Mar 15, 2007, at 10:54 , Michael van der Gulik wrote:

>> Also, observing that "at:" is actually implemented in Object,  
>> which  seems...odd!
> It is a bit odd. An Object in the virtual machine resembles an  
> array of instance variables, and that method assigns to an instance  
> variable by number.

Wrong. Any Squeak object is made of zero or more instance variables  
("named variables") plus zero or more numbered variables ("indexed  
variables"). The difference is that the number of named variables is  
fixed for all objects of that class, but the number of indexed  
variables can be specified when creating an instance using #new:, so  
it can differ from instance to instance. Object>>at: lets you access  
those indexed variables. How else would you access these?

> It's not often useful (and downright dangerous if you ask me)

Huh? It provides the very basics of the system! If we Smalltalkers  
say "everything is an Object" we mean it. Literally. There is no  
special "array object" that is different from "regular objects".  
Rather, you can implement an array as an object that happens to have  
indexed variables:

Object variableSubclass: #BertsArray
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Bert-Arrays'.

(BertsArray new: 7) at: 5 put: 42

- Bert -

More information about the Beginners mailing list