Resources Regarding TCL - OO ( Object Oriented programming in TCL )
Asked Answered
P

3

5

I am doing my Internship and the internship requires i learn and practice TCL - OO so i have been hunting for tutorials, examples, books on TCL - OO but i cannot find anything, So i would appreciate it very much if anyone can give me some good advice regarding TCL - OO.

I did some research over the web and came across these materials

Links: http://www.tcl.tk/cgi-bin/tct/tip/257

Book: TCL/TK a developer's guide 3rd edition by clif Flynt - has only 2 chapters on TCL - OO

so besides these two references if anyone can guide me with extra material it would be splendid Thanks in advance

Polydipsia answered 24/8, 2012 at 9:16 Comment(0)
R
3

The link you have is for the new OO support that is being included Tcl 8.6 which is still in development, resources on this OO subsystem are likely to be harder to find and while it can be used as is I believe it is aimed more as a foundation for other OO packages.

For Tcl 8.5 and earlier there are a number of 'add on' OO packages, a good starting point for these is here. I've used both incr_Tcl and XOTcl in the past and you should be able to find a reasonable amount of information on them both, their home pages have on-line manuals, tutorials and examples.

Remaremain answered 24/8, 2012 at 11:42 Comment(1)
Thank you so much for responding to my question, help greatly appreciated and i will keep my progress posted( i.e if i come across something interesting and find that it can benefit a lot others like me )Polydipsia
A
7

A little late, but...

There is a tutorial I posted to http://www.magicsplat.com/articles/oo.html

Allograph answered 6/8, 2014 at 14:28 Comment(0)
V
5

Disclosure: I wrote TclOO (with a lot of help from others in the design and testing).


Simple Beginning

TclOO allows very simple use, but can get enormously more complex when you start using a large fraction of its features. Here's a quick sample:

# Make a class
oo::class create Example {
    variable x      ;# Not the same as [variable] in a namespace!
    constructor {} {
        set x 1
    }
    method bar {} {
        return [incr x]
    }
}

Example create foo  ;# Make an instance
puts [foo bar]      ;# Call the instance to get 2
puts [foo bar]      ;# Call the instance to get 3
puts [foo bar]      ;# Call the instance to get 4
foo destroy         ;# Kill the instance

Writing a class is pretty simple, and the above gives you enough to do a lot. There are a few basic features that aren't listed: superclass lets you name the parent class of a class, it defaults to oo::object which is the class of all objects; forward lets you dispatch a method call to another command, a sort-of easy delegation; destructor lets you write something that is called when the object goes away; doing Example new would make an object without naming it, the name of the created object is the result of calling that; the name of the current object is the result of calling self inside a method.

Constructors and methods can take arguments just like the basic Tcl proc command. Destructors can't.

More Complex

Objects can be renamed, just like any other Tcl command, and there is a whole slew of introspection available for them underneath info object and info class. You can attach special per-object behavior to any object with oo::objdefine. Every object has a private namespace which you can use to store state in (that's where the x variable in the above example lives).

Methods are not exported by default if their name doesn't start with a lower-case letter (strictly, it depends on whether it matches the glob pattern “[a-z]*”). You can change this if you prefer.

Classes are themselves objects (instances of oo::class) which is why they are created by calling oo::class create; their constructor passes the script you provide to the command oo::define, which is responsible for defining the behavior of classes. The create and new methods are just that: methods on classes that make instances of those classes (named/unnamed respectively).

You can use multiple inheritance. And mixins. And filters. And add a dispatch handler to deal with attempts to call an unknown method.

You can subclass oo::class itself to let you define new ways of making and managing objects.

You can change the class of any object at runtime (except for oo::object and oo::class; they're specially locked for reasons of sanity).

Yes, I'm the author of TclOO but I'm still exploring what my creation can do. I've tried very hard to ensure that will do virtually anything you ask of it.

Veljkov answered 24/8, 2012 at 15:45 Comment(3)
Mr.Donal, I went through your profile and your involvement with Tcl and your contribution to TCL OO, I am aware that , since Tcl/tk is an opensource project you can do only what you can do when you get the time and opportunity, but is it not possible for anyone form your community to take the initiative to write a very simple and concise tutorial, like just a 15 page starter on how to start with TCL-OO AND HOW TO EFFECTIVELY USE THE RESOURCES IN THE MANUAL PAGES.Polydipsia
@Polydipsia There's no need to shout (well, to type in capital letters). The problem is that I'm too close to the material; I think I see too many of the details to write a good tutorial on them. (This is a recurring argument I have with some people at work over whether developers should write user documentation or not.) I'm very happy to help others write the tutorial though. I believe that Clif Flynt's upcoming book will have a substantial section on TclOO, but that's not published yet.Veljkov
Sorry sir, with all due respect, as a student and a fresh graduate I have the highest respect for the open source community and i actually did not mean to shout, I just wanted to highlight the essence of my request, Well i am extremely sorry for meaning any disrespect (intentional and unintentional ), and I will be very glad to see a Guide on TCL-OO come out. And I really am looking forward to learning a lot form this community and pioneers like you.Polydipsia
R
3

The link you have is for the new OO support that is being included Tcl 8.6 which is still in development, resources on this OO subsystem are likely to be harder to find and while it can be used as is I believe it is aimed more as a foundation for other OO packages.

For Tcl 8.5 and earlier there are a number of 'add on' OO packages, a good starting point for these is here. I've used both incr_Tcl and XOTcl in the past and you should be able to find a reasonable amount of information on them both, their home pages have on-line manuals, tutorials and examples.

Remaremain answered 24/8, 2012 at 11:42 Comment(1)
Thank you so much for responding to my question, help greatly appreciated and i will keep my progress posted( i.e if i come across something interesting and find that it can benefit a lot others like me )Polydipsia

© 2022 - 2024 — McMap. All rights reserved.