Bert Freudenberg wrote:

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


Thanks, Bert. I can't believe I've been Smalltalking for so many years and not known that! I always just assumed that arrays were some special case handled by the VM, like SmallIntegers.

Michael.
_______________________________________________
Beginners mailing list
[email protected]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to