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

Re: [Xotcl] Static member functions?

From: Uwe Zdun <uwe.zdun_at_wu-wien.ac.at>
Date: Thu, 17 Apr 2003 10:17:40 +0200

I'm not pretty sure about the goal of these examples yet, but - I'm
guessing - it seems that the problem is that variable traces do not act
like message interceptors. Instead they happen after the variable is
affected. This simple -pure tcl- example illustrates that the var trace
has no "protective" effect on x:

% proc a {var sub op} {
  error "I do not affect the variable"
}
% trace variable x rwu a
% set x 3
can't set "x": I do not affect the variable
% trace vdelete x rwu a
% set x
3
%

Of course, one could reverse the effect, say with unset; but this is a bit
cumbersome.

--uwe

On Wednesday 16 April 2003 22:35, Michael A. Cleverly wrote:
> 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
>
>
> _______________________________________________
> Xotcl mailing list - Xotcl_at_alice.wu-wien.ac.at
> http://alice.wu-wien.ac.at/mailman/listinfo/xotcl

-- 
Uwe Zdun
Department of Information Systems, Vienna University of Economics
Phone: +43 1 313 36 4796, Fax: +43 1 313 36 746
zdun_at_{xotcl,computer,acm}.org, uwe.zdun_at_wu-wien.ac.at