On Mon, 5 Aug 2002 03:41, you wrote:
> Sun, 4 Aug 2002 22:32:44 +0900, Harry Ohlsen <harryo / zip.com.au> pisze:
> > When you run this, it prints "Setting @a to 456".  The initial setting of
> > @a in initialize doesn't get caught.  Ie, a=() doesn't seem to come into
> > effect until AFTER the instance variable has been created.
>
> It doesn't matter if it existed. @a=... just doesn't call a=().
> Only obj.a=... does.
>
> Otherwise the body of a=() which contains @a=... would loop forever.

Good point!  I figured there was some good reason that a=() wasn't being 
called, but that hadn't dawned on me.

In theory, though, having a method that's called when an instance variable is 
*created*, as opposed to every time it's assigned, would work, since the "@a 
= something" inside that method would not be another instance variable 
creation (because, at that point the variable exists), just an assignment to 
one.

Obviously, the interpreter knows when an instance variable is created.  It has 
to, in order to add it to the class's list of variables.

I guess what I'm looking for is effectively something like trace_var(), but 
that works for more than just globals.  Maybe trace_instance_var() ?

I realise, though, that there are probably a million places one could have 
hooks like this and we don't necessarily want all of them.  I do think this 
one is potentially useful ... well, *actually* useful, since I have a use for 
it right now :-).