I know this is somewhat obscure but it nonetheless appears to be a bug:
% package require XOTcl 1.3 % xotcl::Object ob ::ob % ob class xotcl::Class % ob info class Bus error
(On Mac OS X 10.3.7)
I was interested to find out if it's possible to make an already existing object into a class dynamically :-) (Should it be?)
Hi Kristoffer,
the bug happens as well under linux. it is not an OS X issue. Currently, reclassing object to classes is not supposed to work for xotcl (it is not supposed to crash either).
There are two fixes for that, one simple (don't allow reclassing of objects to classes) or a more complex one (do more or less a recreate automatically when this happens; it tries to keep the object information as far as possible).
did you try this example out of curiosity or do you have an interesting example?
-gustaf PS: i did not know that you are using a Mac...
Kristoffer Lawson schrieb:
I know this is somewhat obscure but it nonetheless appears to be a bug:
% package require XOTcl 1.3 % xotcl::Object ob ::ob % ob class xotcl::Class % ob info class Bus error
(On Mac OS X 10.3.7)
I was interested to find out if it's possible to make an already existing object into a class dynamically :-) (Should it be?)
/ http://www.fishpool.com/~setok/
Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
On Feb 7, 2005, at 10:20 PM, Gustaf Neumann wrote:
did you try this example out of curiosity or do you have an interesting example?
Mostly out of curiosity. I was also wondering if you could do a prototype object system in XOTcl (where one can inherit from any object) so then I started to wonder if it would possible in XOTcl to promote any object to a class.
-gustaf PS: i did not know that you are using a Mac...
Yup. Got myself a Powerbook a couple of months ago and am very pleased with it (after the problems with a Linux laptop it has been very refreshing). Great AquaTclTk package for it too which includes XOTcl.
On Feb 7, 2005, at 10:20 PM, Gustaf Neumann wrote:
There are two fixes for that, one simple (don't allow reclassing of objects to classes) or a more complex one (do more or less a recreate automatically when this happens; it tries to keep the object information as far as possible).
I don't know the internals really of XOTcl but basically making an object a class would mean giving it the methods 'instproc' and 'new' and various other stuff, thus allowing an instance of it to be created. I guess it's some internal thing if it has to be recreated? In some sense it would be 'pure' if this was possible.
I wonder if this has any relevance to changing the meta-class of a class?
There are two fixes for that, one simple (don't allow reclassing of objects to classes) or a more complex one (do more or less a recreate automatically when this happens; it tries to keep the object information as far as possible).
I don't know the internals really of XOTcl but basically making an object a class would mean giving it the methods 'instproc' and 'new' and various other stuff, thus allowing an instance of it to be created. I guess it's some internal thing if it has to be recreated? In some sense it would be 'pure' if this was possible.
From the C level, a class has to keep more information than an object. The class structure is an extension of an object, containing hash tables and a couple of pointers:
typedef struct XOTclClass { struct XOTclObject object; struct XOTclClasses* super; struct XOTclClasses* sub; short color; struct XOTclClasses* order; struct XOTclClass* parent; Tcl_HashTable instances; Tcl_Namespace *nsPtr; Tcl_Obj* parameters; XOTclClassOpt* opt; Tcl_HashTable *nonposArgsTable; } XOTclClass;
therefore classes need somewhat more memory than objects, these structures have to be allocated and maintained, so everything is a little more costly than it has to for objects.
Providing means to make "obj class Class" and "cl class Object" working is certainly doable, but i am not sure that is worth the effort, since one can achieve similar effects already from the tcl level (see below).
I wonder if this has any relevance to changing the meta-class of a class?
Check out the code below, it might be pretty close to what you might be thinking about.
-gustaf =============================================================== package req XOTcl namespace import ::xotcl::*
# we will defined our own Class and Object commands namespace forget Class Object
# redefine Class and Object ::xotcl::Class create Class -superclass ::xotcl::Class Class instproc unknown {m args} {puts "[self] unknown called for $m $args"} Class instproc init {} { set sc [my info superclass] if {$sc eq "::xotcl::Object"} {set sc [list]} my superclass [concat $sc Class] } ::xotcl::Class Object -superclass Class
# create some object Object c
# ... which is a class that can create an object ... c create d # ... and so on ... d create e
# provide a method d instproc foo {} {puts [self proc]}
# call the method from it's instance e foo
# create another object which should use the methods provided # by some other objects.... e create f -mixin d
# call the method f foo
On Feb 8, 2005, at 2:25 PM, Gustaf Neumann wrote:
Providing means to make "obj class Class" and "cl class Object" working is certainly doable, but i am not sure that is worth the effort, since one can achieve similar effects already from the tcl level (see below).
OK, well as this was about academic interest than anything else, I'll just let you guys decide what's best.