No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] [self class] inside [eval]
From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Tue, 14 Sep 2004 14:12:59 +0200
Dear all,
i just returned from vacation and i am slowly digging through my mail.
> That's fine, just so I know that's not the intended use. Though I still
> think it may be interesting to have a method that would allow access to
> methods and everything in that fashion, but that may not be feasible.
the method eval is defined in predefined.xotcl through instforward.
# provide some Tcl-commands as methods for Objects
foreach cmd {array append lappend trace eval} {
::xotcl::Object instforward $cmd -objscope
}
the option -objscope means, that the instvars of the object
are in the current scope of evaluation and can be reached
without any prefix. one can do
~/scripts> Object o
::o
~/scripts> o set x 1
1
~/scripts> o incr x
2
~/scripts> o eval regexp b abc y
1
~/scripts> o info vars
x y
~/scripts> o set y
b
See the documentation of 1.3 for more details about
the forwarding stuff
accessing methods in general only through the namspace
is not possible, since we have procs+instprocs (of several
classes) with the same name. you certainly can call
a proc of the object via the eval method
~/scripts> o proc x {} {puts hu}
~/scripts> o eval x
hu
but not instprocs. The following explanation is only for advanced
readers:
<techyspeak>
in XOTcl, instprocs are defined as Tcl-procs within class-specific
namespaces. Therefore we can have a method with the same
name in various classes, which are linked via the next-path.
the class specific namespace for the methods of ::xotcl::Object
is ::xotcl::classes::xotcl::Object. you can see the instprocs of
::xotcl::Object via:
~/scripts>info procs ::xotcl::classes::xotcl::Object::*
If one defines a method in a class
~/scripts> Object instproc y {} {puts ho-[self]}
it shows up there as well
~/scripts> info procs ::xotcl::classes::xotcl::Object::y
::xotcl::classes::xotcl::Object::y
if for some reason, one has to call the instproc directly,
one could use the forwarder
~/scripts> Object instproc y {} {puts ho-[self]}
~/scripts> o eval y
ho-::o
or e.g. the approach in "Itcl in XOTcl" http://mini.net/tcl/10975
where itcl methods are called just by their names
(i have somewhere a slightly faster version using "interp alias").
</techyspeak>
I would not recommend this for the general usage, since
- as uwe pointed out - this is bypassing the xotcl dispatcher
an can lead to unexpected behavior (it is a defined behavior,
but different from the variant without eval).
hope, this helps,
-gustaf
Date: Tue, 14 Sep 2004 14:12:59 +0200
Dear all,
i just returned from vacation and i am slowly digging through my mail.
> That's fine, just so I know that's not the intended use. Though I still
> think it may be interesting to have a method that would allow access to
> methods and everything in that fashion, but that may not be feasible.
the method eval is defined in predefined.xotcl through instforward.
# provide some Tcl-commands as methods for Objects
foreach cmd {array append lappend trace eval} {
::xotcl::Object instforward $cmd -objscope
}
the option -objscope means, that the instvars of the object
are in the current scope of evaluation and can be reached
without any prefix. one can do
~/scripts> Object o
::o
~/scripts> o set x 1
1
~/scripts> o incr x
2
~/scripts> o eval regexp b abc y
1
~/scripts> o info vars
x y
~/scripts> o set y
b
See the documentation of 1.3 for more details about
the forwarding stuff
accessing methods in general only through the namspace
is not possible, since we have procs+instprocs (of several
classes) with the same name. you certainly can call
a proc of the object via the eval method
~/scripts> o proc x {} {puts hu}
~/scripts> o eval x
hu
but not instprocs. The following explanation is only for advanced
readers:
<techyspeak>
in XOTcl, instprocs are defined as Tcl-procs within class-specific
namespaces. Therefore we can have a method with the same
name in various classes, which are linked via the next-path.
the class specific namespace for the methods of ::xotcl::Object
is ::xotcl::classes::xotcl::Object. you can see the instprocs of
::xotcl::Object via:
~/scripts>info procs ::xotcl::classes::xotcl::Object::*
If one defines a method in a class
~/scripts> Object instproc y {} {puts ho-[self]}
it shows up there as well
~/scripts> info procs ::xotcl::classes::xotcl::Object::y
::xotcl::classes::xotcl::Object::y
if for some reason, one has to call the instproc directly,
one could use the forwarder
~/scripts> Object instproc y {} {puts ho-[self]}
~/scripts> o eval y
ho-::o
or e.g. the approach in "Itcl in XOTcl" http://mini.net/tcl/10975
where itcl methods are called just by their names
(i have somewhere a slightly faster version using "interp alias").
</techyspeak>
I would not recommend this for the general usage, since
- as uwe pointed out - this is bypassing the xotcl dispatcher
an can lead to unexpected behavior (it is a defined behavior,
but different from the variant without eval).
hope, this helps,
-gustaf
-- Univ.Prof. Dr.Gustaf Neumann Abteilung für Wirtschaftsinformatik und Neue Medien Wirtschaftsuniversität Wien, Augasse 2-6, 1090 Wien