Artifacts Associated With Ticket 3474460
Ticket change [605136bace] (rid 115974) by basilik99 on 2012-01-16 14:41:27:
- assignee initialized to: "dkf"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Hi, With ActiveState Tcl 8.6.0.0.295132 Beta 6, when issuing: oo::copy Class1 It gives the error: "must supply a name when copying a class" However, the documentation tells that the second parameter is optional. I would indeed expect Tcl to generate a new name such as ::oo::Obj34. Note: this is useful to include the same class as a mixin in each class of a hierarchy. It seems Tcl only mixins a class once per hierarchy and not once per class having "mixin MyMixClass" in that hierarchy. So putting "mixin [oo::copy MyMixClass]" in each class of the hierarchy should solve the problem. This allow to add extra code to a method between each stage of the hierarchy. Thanks, Etienne
- foundin initialized to: "obsolete: 8.6b2"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "basilik99"
- subsystem initialized to: "35. TclOO Package"
- title initialized to: "targetObject should be optional for oo::copy"
- type initialized to: "Bug"
Ticket change [8d2c85a1d7] (rid 127885) by dkf on 2012-01-22 22:28:20:
- icomment:
Making the name optional would certainly be possible. (It would also be possible to allow the specifying of the name of the target object's namespace.) More generally though, there should be also some callback/method to allow an object to customize itself after being copied. Hmm.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [4790114238] (rid 99724) by basilik99 on 2012-01-24 03:35:34:
- icomment:
Hi, Indeed! I was about to open another ticket (probably a feature request) about the fact that given a class A which is an instance of class X (rather than oo::class as usual), then when copying A to B, the constructor of X does not get called. I think that would be the natural hook. I also had another concern: when I first used oo:::copy, I expected the new class to be created the same way as the first one. Eg: oo::class create CLASS1 \ { superclass MYBASE [oo::copy STORABLE [expr rand()]] ;# rand is because targetObject is not optional variable EXPRESSIONS puts "We are building a class." constructor {pL_EXPRESSIONS} \ { set EXPRESSIONS $pL_EXPRESSIONS } method WRITE {} \ { puts $EXPRESSIONS } export WRITE } oo::copy CLASS1 CLASS2 oo::define CLASS2 superclass MYBASE [oo::copy STORABLE [expr rand()]] 1) In that example, WRITE method on an object of CLASS1 works: the "variable" command given a class declaration makes that variable visible in all methods without having to write "my variable EXPRESSIONS" at the beginning of each method. That no longer works for CLASS2: the "variable" command does not seem copied... 2) Also, "rand" function does not get called once for CLASS1 and once for CLASS2. Its result is re-used when creating CLASS2. This forces me to override the superclasses of CLASS2 using oo::define command in order to generate a new copy of STORABLE class for CLASS2. Similarly, the text "We are building a class." gets printed only for CLASS1, not for CLASS2. In other words, it seems only the constructor, destructor and methods are copied. But it could be useful if all the code passed to "oo::class create" would be copied. Tell me if I should open another ticket with these. Thanks, Etienne - login: "basilik99"
- mimetype: "text/plain"
- username: "basilik99"
- icomment:
Ticket change [7c8e96ff03] (rid 97100) by dkf on 2012-01-25 21:52:29:
- icomment:
Fixed the issue with 'variable'; that was Just A Bug. Code is in trunk; will form part of next release. I don't grok what you're going on about with rand().
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [5462916069] (rid 93942) by basilik99 on 2012-01-26 06:42:28:
- icomment:
Hi, Thanks for the correction about "variable" being copied. The rand trick comes from a higher need: I have a hierarchy of classes that I want to serialize to a file. Suppose the following classes (baseclasses to subclasses): A -> B -> C -> D -> E. A given object of type E will be serialized when its WRITE method will be called. Each class can write specific info. But all classes will write its class type to the serialization output file. I wanted to implement another class, STORABLE, which job would be to write these types to the file. With introspection, it is easy: look at the class name, go get a global constant of a name similar to it, output the value of that constant. So, I want the call to the WRITE method on an object of type E to give the following chain: E's WRITE -> STORABLE's WRITE -> D's WRITE -> STORABLE's write -> ... -> STORABLE's WRITE -> A's WRITE. 1) I first tried to insert STORABLE as a mixin in the hierarchy, but STORABLE was accepted only once for the whole hierarchy (in the top superclass) and hence STORABLE's WRITE was called only once, not 5 times. Also, STORABLE's WRITE was called BEFORE the implementation of the class it is applied to: I could work with this, but it is not was I expected (however, I was new to mixins...). 2) The I tried using STORABLE as a superclass. Again, all superclass commands were ignored except the one in the topmost class. To TclOO to see its the same class, I made a copy of STORABLE each time I used it as superclass. And that's what explains the oo::copy. The rand is only because I wanted a different name for each STORABLE class copies. There may be better ways to achieve my goal. Suggestions are welcome. Thanks, Étienne
- login: "basilik99"
- mimetype: "text/plain"
- username: "basilik99"
- icomment:
Ticket change [4171739aaa] (rid 116195) by sebres on 2012-01-26 07:05:53:
- icomment:
can be useful for you: http://wiki.tcl.tk/23444 you can extend your each class with method "serializable" and extend this code with checking is a class serializable by generating string of content. then simple write/read string into/from file.
- login: "sebres"
- mimetype: "text/plain"
- username: "sebres"
- icomment:
Ticket change [dd6a8ff2e7] (rid 114663) by basilik99 on 2012-01-27 06:40:05:
- icomment:
Hi, Thanks sebres for this link. I looked at it and it could be good for a new project. However, the application which is deserializing my objects is already written and expects a particular format. In particular, it expects to find an ID for each class that composes an object O. Suppose the class hierarchy A -> B -> C -> D -> E, E having no subclass. Then in the serialized binary code, there will be some bits indicating the object is of type A, then of type B, and so on, further refining until the leaf class is reached. Moreover, at some stages, additional information is added (i.e. B outputs the attributes it contains before continuing on the chain). That might not be the standard way to do deserialization, but I have to stick with that format. Still, I am still wondering if TclOO allows such methods to be "inserted" between each class of a hierarchy... DKF, will the targetObject bug be corrected? And did you think about the copy hook? Thanks, Étienne
- login: "basilik99"
- mimetype: "text/plain"
- username: "basilik99"
- icomment:
Ticket change [b8a5d17b6a] (rid 128998) by dkf on 2012-01-27 17:35:11:
- icomment:
In my build, the targetObject is optional and as far as I can tell, has been for a long time (it's optional at the point where the code was committed to Tcl). Can you please tell me exactly what [package require TclOO] reports?
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [9954d17570] (rid 110773) by dkf on 2012-01-27 17:35:46:
- icomment:
Oh, hang about. It's a _class_ you're copying.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [4c485d33cb] (rid 126856) by dkf on 2012-01-27 17:37:52:
- icomment:
Basically, I don't understand why you would want an unnamed class. What sort of rationale is there for doing this? (I now comprehend what you're doing with rand(), but not *why*.)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [8d158ca26e] (rid 127868) by dkf on 2012-01-27 17:38:10:
- icomment:
IP - Comment Removed: 130.88.1.31
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [271b857980] (rid 88459) by dkf on 2012-01-27 17:38:19:
- icomment:
IP - Comment Removed: 130.88.1.31
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [0c05c27d5a] (rid 114104) by basilik99 on 2012-01-28 01:58:33:
- icomment:
Because to implement the serialization as I described, STORABLE's WRITE method must be called at each stage. But putting STORABLE as a superclass of classes A, B, C, D and E will not work: only class A will have STORABLE as superclass. Hence, STORABLE's WRITE will be called only once, after A's WRITE. By copying STORABLE to an unnamed class, TclOO allows each of A, B, C, D and E to inherit from STORABLE, or to be more precise, to a distinct copy of STORABLE. In short, I wanted the following inheritance tree: STORABLE \ A STORABLE \ / B STORABLE \ / ... STORABLE \ / E - login: "basilik99"
- mimetype: "text/plain"
- username: "basilik99"
- icomment:
Ticket change [700c4fbcfc] (rid 100413) by andreas_kupries on 2012-01-28 02:19:10:
- icomment:
Could this type of thing be handled better as a class or object mixin ?
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [97389e40f6] (rid 106468) by basilik99 on 2012-01-28 21:20:02:
- icomment:
Again, putting STORABLE as a mixin for classes A to E will make TclOO accept STORABLE as a mixin only for A. At least, STORABLE's WRITE method is only called once, and before A's WRITE: E's WRITE -> D's WRITE -> C's WRITE -> B's WRITE -> STORABLE's WRITE -> A's WRITE.
- login: "basilik99"
- mimetype: "text/plain"
- username: "basilik99"
- icomment:
Ticket change [f4658b4303] (rid 129907) by dkf on 2012-01-30 20:33:15:
- icomment:
I'm curious as to why there's a need to make all those STORABLEs. In particular, what's the benefit to putting those in their own classes as opposed to having the WRITE as a method on A...E directly? (When I wrote a TclOO serializer I didn't store the classes themselves, but that was due to the use-case I had in mind. That didn't require this baroque structure.) You could arrange for the creation of the method to be done by a metaclass if writing it directly is too onerous. Metaclasses (classes that are subclasses of oo::object) are essentially a way of massively customizing the class manufacturing process and let you do some *really* funky stuff.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [1700d11811] (rid 124808) by dkf on 2012-01-30 20:46:10:
- icomment:
My serializer would just introspect across the whole state — easy because TclOO (deliberately) doesn't play all that many tricks with scoping — and save it out. It included a call to a special method to allow for custom control of serialization, which would be necessary for handling things like widgets, channels, etc.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [0a8d9a19e2] (rid 113841) by basilik99 on 2012-02-07 02:05:06:
- icomment:
I am not sure to understand your question, but I wrote the STORABLE class (there is only one STORABLE class) to avoid copying-pasting code. Indeed, it writes to the output something similar to the class name (in fact, it is not a string, but a binary code). As Tcl can do introspection, STORABLE can look at the class name and write it down. This can be done with generic code that doesn't have to be modified if classes are added/removed in A->E hierarchy.
- login: "basilik99"
- mimetype: "text/plain"
- username: "basilik99"
- icomment:
Ticket change [1aedd8b2f4] (rid 123062) by dkf on 2012-02-13 20:41:58:
- icomment:
I plan to drop the check on whether a class is being no-name-copied (as part of overhaul of [oo::copy]). It was not a documented constraint and was never necessary. It's still very odd to me why you'd want to do such a complex arrangement, but I have no good reason to say "No" so I must say "Yes".
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Accepted"
- username: "dkf"
- icomment:
Ticket change [83a1116078] (rid 117417) by basilik99 on 2012-02-14 06:00:40:
- icomment:
Thanks for your answers in this ticket and in "TclOO: variables not copied when mixins are copied - ID: 3485060". Note that I am not the one that can perform the review of the changes you proposed as I am not familiar with Tcl development itself. Etienne
- login: "basilik99"
- mimetype: "text/plain"
- username: "basilik99"
- icomment:
Ticket change [17f2f2f3ae] (rid 122586) by dkf on 2012-03-27 15:28:50:
- closedate changed to: "2012-03-27T08:28:50"
- closer changed to: "dkf"
- icomment:
allow_comments - 1 Fixed with commit of TIP #397 implementation,
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "dkf"