View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] Static member functions?

From: Michael A. Cleverly <michael_at_cleverly.com>
Date: Wed, 16 Apr 2003 14:35:32 -0600 (MDT)

On Wed, 16 Apr 2003, Gustaf Neumann wrote:

> Most of the important things were already answered by Neophytos and
> Kristoffer.

Thanks to all of you for the pointers. XOTcl seems to be much more
Tcl-ish than, say, [incr Tcl].

> XOTcl does not need a special construct, since every class is an object
> as well, and variables kept in a class are nothing special. Note that a
> programmer can decide what kind of class he is referring to:
> - the class which is the type of the object (via "my info class")
> - the current class, which is currently active (via "self class")
> The type variable you are refering to is the first one.

This is a very helpful explanation. A light bulb just went on in my mind.
Thanks.

> Often, when people start to use XOTcl, there come requests how to achieve
> private instance variables. These can be easily achived through variable
> traces. Maybe someone finds the following code helpful or interesting....

Very interesting. But, I'm confused by the results I'm seeing (both
before & after applying the patch). It seems that even though [o1 test0]
and [o1 test1] throw an error the variable is updated. And [o1 test3]
does unset the variable.

% c1 show
x=100
% c1 test
10
% c1 show
x=10
% o1 test0
error: Can't find result of set x
% c1 show
x=13
% c1 test
10
% c1 show
x=10
% o1 test1
error: can't set "x": private member x of ::c1 written from ::o1->test1
% c1 show
x=13
% c1 test
10
% c1 show
x=10
% o1 test2
error: can't read "x": private member x of ::c1 read from ::01->test2
% c1 show
x=10
% o1 test3
% c1 show
can't read "x": no such variable

I'm using XOTcl 1.0.2 (compiled from source) & Tcl 8.4.2 (.deb) on Linux.

(Neophytos: yes, I am the author of nstcl fame, though I didn't realize
that would make me famous anywhere. :-)

Michael