Hello,
I attach a few files that will demonstrate the problem. Just run tester.tcl On my PC the effect is that I get an error message:
::tmp1: unable to dispatch method 'testA' while executing "tmp1 testA"
The problem is that tmp1 is of class B and should be able to call testA, which is defined its superclass - A.
I have found that the problem is source command, which includes file a.xotcl several times in several different files. I don't understand however why the message from interpreter says that it cannot find proc testA - this doesn't make sense.
Is there a "nice" method to avoid this? Like in C we use #define and #ifndef
I suppose effect by redefining class
namespace import xotcl::* # file 1 Class F1 F1 instproc foo {} { puts foo } # file 2 source file1 Class F2 -superclass F1 # file 3 source file 1 Class F1 F1 instproc foo {} { puts foo } Class F3 -superclass F1 F2 create f2 f2 foo # F1 is not more superclass of F2 F2 superclass
Redefining F1 (double source) delete old implementation of F1 and so superclass of F2.
The same as
namespace import xotcl::* Class F1 F1 instproc foo {} { puts foo } Class F2 -superclass F1 F2 create f2 f2 foo F1 destroy f2 foo
Artur
Hello,
I attach a few files that will demonstrate the problem. Just run tester.tcl On my PC the effect is that I get an error message:
::tmp1: unable to dispatch method 'testA' while executing "tmp1 testA"
The problem is that tmp1 is of class B and should be able to call testA, which is defined its superclass - A.
I have found that the problem is source command, which includes file a.xotcl several times in several different files. I don't understand however why the message from interpreter says that it cannot find proc testA - this doesn't make sense.
Is there a "nice" method to avoid this? Like in C we use #define and #ifndef
Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
Am 10.01.11 22:26, schrieb Artur Trzewik:
I suppose effect by redefining class
Artur, i had the same guess, since all the files load fine as they are. Something is missing in the picture.
But most probably, the problem is the redefinition problem, where the standard redefining semantics are a destroy followed by a create. When a class is destroyed, the references to the class are deleted, so a superclass relation (or similar) will get lost.
In this case, xotcl::configure softrecreate will help:
========================================= namespace import xotcl::* ::xotcl::configure softrecreate true
Class F1 Class F2 -superclass F1 # # Before 2nd create of F1 # puts "F2 superclass [F2 info heritage]" Class F1 # # After 2nd create of F1 # puts "F2 superclass [F2 info heritage]" =========================================
Krzysztof, soucing your file extendedContainer.xotcl and creating an instance of ExtendedContainer works fine:
========================================= ~/scripts/krz% xotclsh % source extendedContainer.xotcl % ExtendedContainer x Calling testB on class B object... testB was called ...proc called successfully Calling testA on class B object... testA was called ...proc called successfully ::x =========================================
btw, not sure that you are aware that you are creating in several of your source files classes twice. E.g. in extendedContainer.xotcl, you create the class ExtendedContainer in line (2) and once again in line (8).
-gustaf neumann
======================================= 1 package require XOTcl 2 xotcl::Class ExtendedContainer 3 4 namespace import xotcl::* 5 source b.xotcl 6 7 8 Class create ExtendedContainer 9 10 ExtendedContainer instproc init {} { ... =======================================