Since every class is also an object, its possible to define both procs & instprocs for it. The instprocs define methods that objects of this class will have, while the proc (as I understand it) proc would define a method on the class object, but not for objects of the class. (Yes?)
However, during my interactive playing around trying different things I've found that as soon as I define a proc on the class object any subsequent use of [info classchildren] leads to a segfault.
$ tclsh % package require XOTcl 1.0 % namespace import xotcl::* % Class C ::C % C info classchildren % C proc foo args {} % C info classchildren Segmentation fault
Is it better to avoid defining procs on the class object, or am I misunderstanding when & where to use [info classchildren]?
Michael
On Thursday 17 April 2003 20:11, Michael A. Cleverly wrote:
Since every class is also an object, its possible to define both procs & instprocs for it. The instprocs define methods that objects of this class will have, while the proc (as I understand it) proc would define a method on the class object, but not for objects of the class. (Yes?)
correct.
However, during my interactive playing around trying different things I've found that as soon as I define a proc on the class object any subsequent use of [info classchildren] leads to a segfault.
bingo. you found a bug. please apply the following patch to fix it.
Is it better to avoid defining procs on the class object, ...
The only limitation with procs in our current limitation is that one can't have procs and sub-objects with the same name, since both occupy the same slot in the namespace.
in the following code, one can call the proc t both as "o::t" and "o t" Object o o proc t {} {puts x}
When a childobject is created, it is refered to as well with o:t Object o::t o::t set x 1 ... The creation of the object o::t detetes the same-named proc and vice versa. This make it easy to "donate" ordinary tcl procs/commands to an object:
proc xxx {} {puts xxxx} ... rename xxx o::xxx
now xxx is a proc of o, which can be called via: o xxx puts [o info procs]
or am I misunderstanding when & where to use [info classchildren]?
no, you are on the right track! all the best
-gustaf
======================================================================= --- xotcl.c~ 2003-04-16 19:13:53.000000000 +0200 +++ xotcl.c 2003-04-17 22:22:59.000000000 +0200 @@ -4911,7 +4911,7 @@ if (!pattern || Tcl_StringMatch(key, pattern)) { Tcl_PushCallFrame(in, &frame, (Tcl_Namespace*)obj->nsPtr,0); childobj = GetObject(in, key); - if (XOTclObjectIsClass(childobj)) { + if (childobj && XOTclObjectIsClass(childobj)) { Tcl_ListObjAppendElement(in, list, childobj->cmdName); } Tcl_PopCallFrame(in);
=======================================================================