[Xotcl] Re: XOTcl is great!!
Taral
taraloza at gmail.com
Wed Sep 7 13:23:46 CEST 2005
Thanks a lot guys for your prompt response. Both, yours and Kristoffer's
responses were very helpful indeed. Pretty soon I will try to write a small
package to do the ORM (Object Relation Management). The examples you
provided will be extremely useful in this case. Just to give you some idea,
I'm thinking along this design:
Class Relationship -parameter FromClass ToClass RelationshipNumber
isConditional isMultiple identifiersList
Of course, I chose descriptive names here. Specially isConditional flag is
used to differentiate 1:0..1 and 1:0..n from 1:1 and 1:1..n types.
Well, I will be in touch with you guys on further development on my side.
By the way, I can not resist myself asking you guys about testing done for
XOTcl. I'm planning to use it for implantable Medical Device hard-real time
firmware system where bugs are not allowed at all. Reading you note about
the bug in expr method, do you mind giving me a small update on what type of
testing is done on this library and how much stable is it from your
experience?
Are there any plans to provide more of object relation management
functionality in the library itself? When are you planning the next release?
I was wondering about whom I'm talking to. You guys are obviously from
Germany/Austria based on my guess from your email address. It would be nice
to know you guys little more to help the communication. Do you guys have any
personal webpage? I don't have one myself :( But now I feel like I should
have one. So I will try to put up one sometime soon.
Thanks again,
Taral
On 9/5/05, Gustaf Neumann <neumann at wu-wien.ac.at> wrote:
>
> Taral schrieb:
>
> > Hello,
> >
> > I recently came across XOTcl and found it very very useful. I am
> > working on optimizing some legacy compiler code which is written in
> > TCL. I would like to make it object-oritented and so I started using
> > XOTcl. So far I have found aouut 90% reduction in execution time.
> > Overall I'm getting great performance by using XOTcl.
>
> wow, this is an impressive number; good to hear that.
>
> > I would like to Thank You guys for writing such a great library.
> >
> > Of course I have couple of questions for you. I will really appreciate
> > it if you can help me here.
> >
> > (1) Is there any way to all the objects or instances based on
> > parameter value? For example, I would like to request object names of
> > all objects where given parameter's value is equal to 5.
>
> There is no built-in support for this. a straigthforward approach is the
> following which might
> be sufficient in many situations:
>
> ===========
> # define method expr for all Objects, the operands are taken from
> # the instance variables
> Object instforward expr -objscope
>
> # define method select with some abitrary tcl expression. All objects,
> # for which the expression returns 1 are returned
> Class instproc select {expr} {
> set result_list [list]
> foreach o [my allinstances] {
> if {![catch {$o expr $expr} result]} {
> puts "$o expr {$expr} -> $result"
> if {$result} {
> lappend result_list $o
> }
> }
> }
> return $result_list
> }
> ===========
>
> so, now we define a view classes and objects with some instance variables
>
> Class C -parameter {{x 10}}
> Class D -superclass C
>
> C c1
> C c2 -x 11
> D d1 -x 100
> D d2
> D d3
> d3 unset x
>
> finally, we try it out with some demo queries
>
> foreach q {
> {$x > 10}
> {$x >= 10}
> {$x < 1}
> {[string match *00* $x]}
> } {
> puts "C select $q --> {[lsort [C select $q]]}\n"
> }
>
> Note that in this example, all instances of C are checked for the
> expression, if
> you use "... [Object select {$x > 10}]", all objects will be checked.
>
> This approach might be good enough for small examples and medium
> speed requirements. If you have larger number of objects, and you cant
> restrict the query to smaller classes, you should try to build an index
> based on associative arrays, which could replace the "allinstances"
> in the code above.
>
> > (2) Do you have more example code pieces? I would like to see more
> > sample implementation to help me with the syntax. I'm also learning
> > TCL language at the same time using XOTcl :)
>
> i am sure, you have seen the tutorial and the examples in xotcl*/apps
> and xotcl*/library. There are a few more on:
>
> http://mini.net/tcl/XOTcl
> http://wiki.tcl.tk/references/10971!
>
> > (3) Is there any way to represent relationship across two classes? For
> > example, Class A is related to Class B with one-to-many relationship.
>
> a few class/class relations and object/class relations are maintained
> by xotcl (e.g. superclass,
> class, mixins). A start point might be ::xotcl::Relations, which is
> used to implement a
> uniform interface to mixins (and instmixins ...), which allows to
> specify "... mixin add ...", #
> "... mixin delete ...", "... mixin set ...", etc. In principle, the
> same interface could be used
> for application level relations as well...
>
> In current applications, the classes use and maintain a list of related
> object/classes.
> Often, it is conveniant to use aggregations to express 1:1 or 1:n
> relationships.
>
> > (4) If there is a way to define relationship, is it possible to query
> > objects of classes in the relationship? For example, I would like to
> > get all the objects of Class B related to given object of Class A
> > (like a1) across given one-to-many relationship. In this case result
> > would be list of object handles of Class B that matches based on given
> > primary key (identifier) value between class A and B.
>
> a good key identifier is the object name. see the following snipplet,
> how such behavior
> could be obtained. We define class A, which maintains the relationship
> to some other
> objects. if an instances exists that relates e.g. to object c1, we could
> check there some
> properties with expr like above...
>
> Class A -parameter {relates_to}
>
> A a1
> A a2
>
> a1 set relates_to {c1 c2}
>
> foreach o [A allinstances] {
> catch {
> if {[lsearch -exact [$o relates_to] c2] > -1} {
> puts "could check $o"
> }
> }
> }
>
> hope theses examples help a little.
>
> -gustaf
>
> PS: when i was writing this mail i saw that the classtack information
> within methods called via the method "expr" is not correct. It will
> be fixed in the next release....
>
> >
> > Please provide some guidance to implement above functionality using
> XOTcl.
> >
> > Thanks a lot in advance.
> >
> > May be in future I would like to contribute to XOTcl. I wish to be in
> > touch with you guys.
> >
> > Regards,
> > Taral
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://alice.wu-wien.ac.at/pipermail/xotcl/attachments/20050907/2221d084/attachment.html
More information about the Xotcl
mailing list