Whither SmallScript? (was Re: Integer micro-benchmarks)

Darren New dnew at san.rr.com
Wed May 2 12:16:06 EDT 2001


James A. Robertson wrote:
> > were wondering. And add or remove instance variables
> > dynamically, too (I don't think that one is so easy in
> > Smalltalk).
> 
> Sure it is.
> MyClass addInstVarName: 'foo'
> MyClass removeInstVarName: 'foo'

This is a little different from Python, tho.

In smalltalk, addInstVarName adds the instance variable to the *class* and
then updates all instances to now have that variable in them. (A relatively
high-overhead operation, yes.) IIRC, it might also have to recompile some or
all of the class code? 

In Python, you add instance variables to individual instances. Not all
instances of the same class must have the same set of instance variables.
(In one sense, all instances of a class have the same instance variables,
but one of those instance variables is a dictionary mapping instance
variable names to values, and the syntax makes this mostly invisible.)

I think if you want to add an instance variable to all instances of a class,
you need to write a loop to iterate over all those instances. I'm not sure
whether you could find them.

-- 
Darren New / Senior MTS & Free Radical / Invisible Worlds Inc.
       San Diego, CA, USA (PST).  Cryptokeys on demand.
       Invasion in chinese restaurant:
                        ALL YOUR RICE ARE BELONG TO US!



More information about the Python-list mailing list