TclOO tutorial : where ?

503 views
Skip to first unread message

Thomas MENEZ

unread,
Jan 10, 2011, 4:32:18 PM1/10/11
to
Hi !

I would like to try out TclOO ... But I cannot find any tutorial on
the matter. Apart from the few examples from the Wiki, is there any
good place to start ?

Thanks !

Thomas

jima

unread,
Jan 10, 2011, 6:12:11 PM1/10/11
to

This might sound strange... I learned a bit of XOTcl (http://
media.wu.ac.at/) some years ago... after that, taking what's in the
wiki and man pages for TclOO should suffice...besides practice,
naturally...

I find that this is so because TclOO is inspired in XOTcl in some
way...

jima

Larry W. Virden

unread,
Jan 11, 2011, 8:46:41 AM1/11/11
to
On Jan 10, 4:32 pm, Thomas MENEZ <menez.tho...@gmail.com> wrote:
> I would like to try out TclOO ... But I cannot find any tutorial on
> the matter.

I would expect that the descriptions at http://tip.tcl.tk/ for the
TIPs related to TclOO might be helpful. But I haven't seen a specific
tutorial written for TclOO itself.

Harald Oehlmann

unread,
Jan 11, 2011, 9:40:19 AM1/11/11
to
On 11 Jan., 14:46, "Larry W. Virden" <lvir...@gmail.com> wrote:
> On Jan 10, 4:32 pm, Thomas MENEZ <menez.tho...@gmail.com> wrote:
>
> > I would like to try out TclOO ... But I cannot find any tutorial on
> > the matter.
>
> I would expect that the descriptions athttp://tip.tcl.tk/for the

> TIPs related to TclOO might be helpful.  But I haven't seen a specific
> tutorial written for TclOO itself.

The book "Tcl 8.5 Network Programming" handles TclOO in 10 pages.
I think this description is quite professional.
Nevertheless the XOTCL Tutorial describes Mixins, which are also in
TclOO.

Harald

Gerald W. Lester

unread,
Jan 11, 2011, 10:00:42 AM1/11/11
to

Well, there was a tutorial given at the last Tcl/Tk Conference
(http://www.tcl.tk/community/tcl2010/tutorials.html#adv1) -- I expect there
will be at the next one also.


--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+

Thomas MENEZ

unread,
Jan 11, 2011, 5:31:46 PM1/11/11
to
On Jan 11, 4:00 pm, "Gerald W. Lester" <Gerald.Les...@KnG-

Consulting.net> wrote:
> On 1/10/11 3:32 PM, Thomas MENEZ wrote:
>
> > Hi !
>
> > I would like to try out TclOO ... But I cannot find any tutorial on
> > the matter. Apart from the few examples from the Wiki, is there any
> > good place to start ?
>
> Well, there was a tutorial given at the last Tcl/Tk Conference
> (http://www.tcl.tk/community/tcl2010/tutorials.html#adv1) -- I expect there
> will be at the next one also.
>
> --
> +------------------------------------------------------------------------+
> | Gerald W. Lester, President, KNG Consulting LLC                        |
> | Email: Gerald.Les...@kng-consulting.net                                |
> +------------------------------------------------------------------------+

Thansk for your suggestions.

Maybe it's too early for a tutorial to pop out, I mean maybe TclOO is
not mature enough to have people jump onboard ?

Gerald W. Lester

unread,
Jan 11, 2011, 7:21:15 PM1/11/11
to

Ah, the tutorial was presented in the Fall of 2009 -- I do not understand
what you mean by "too early for a tutorial to pop out".

--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |

| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+

Larry W. Virden

unread,
Jan 12, 2011, 7:05:17 AM1/12/11
to
On Jan 11, 7:21 pm, "Gerald W. Lester" <Gerald.Les...@KnG-

Consulting.net> wrote:
> On 1/11/11 4:31 PM, Thomas MENEZ wrote:

> > Maybe it's too early for a tutorial to pop out, I mean maybe TclOO is
> > not mature enough to have people jump onboard ?
>
> Ah, the tutorial was presented in the Fall of 2009 -- I do not understand
> what you mean by "too early for a tutorial to pop out".
>

> - Show quoted text -

Rather than thinking of it being too early for someone to have written
a tutorial, you could think of it as the experts being too busy
finishing up the Tcl 8.6 code to sit down and writing a tutorial.
Remember, even though TclOO has been around for years, the Tcl in
which it is included has yet to reach formal release. Things could,
potentially, have some changes occur between now and the final
release. Just look at all the changes that have occurred during the
nearly 3 years of development for Tcl 8.6... http://wiki.tcl.tk/21276

Larry W. Virden

unread,
Jan 12, 2011, 7:29:27 AM1/12/11
to
On Jan 11, 10:00 am, "Gerald W. Lester" <Gerald.Les...@KnG-

Consulting.net> wrote:
>
> Well, there was a tutorial given at the last Tcl/Tk Conference
> (http://www.tcl.tk/community/tcl2010/tutorials.html#adv1) -- I expect there
> will be at the next one also.

Also note that the tutorial material isn't included in the conference
proceedings. However, there was at least one conference presentation
on TclOO in 2010 by Donal K. Fellows (see http://lulu.com/tcl , I
believe, for a way to purchase the proceedings).

elipse

unread,
Jan 12, 2011, 7:38:28 AM1/12/11
to
I fully support you.

Without proper documentation, TclOO looks like a crutch.
And how much is already possible to draw with Tcl 8.6 ?
My kids will be able to see the release of Tcl 8.6? :))

Donal K. Fellows

unread,
Jan 12, 2011, 9:11:51 AM1/12/11
to

In terms of tutorials, you're best off seeing what Clif Flynt has to
say, as he's written one. (It's not available online as of now, but it
was given last Tcl Conference and will probably be given again.)

I've not written one; too much work in the way. :-(

For very basic usage, here's this. It assumes you know a bit about OO
systems in general.

Declare a class like this:

oo::class create MyExampleClass {
constructor {args} {# like [proc]
# Do something with the args...
}
# Public methods begin with lower-case letters
method foo {bar boo} {# like [proc]
puts "bar=$bar, boo=$boo"
}
destructor {# No arguments
# Clean up here if necessary
}
}

Use that class/object like this:

MyExampleClass create exampleObj someArgumentToConstructor...
exampleObj foo 1 2; # prints 'bar=1, boo=2'
exampleObj destroy; # wipes the object out
set obj [MyExampleClass new]; # 'Unnamed' object
$obj foo 3 4; # prints 'bar=3, boo=4'
$obj destroy

Every object (i.e., every instance) has its own arbitrarily-named
namespace that is not shared with anything else. It is the current
namespace when a method (or constructor or destructor) is executing.
Store state in there, perhaps like this:

oo::class create Example2 {
constructor x {
variable X $x
}
method addToX y {
variable X
set X [expr {$X + $y}]
return
}
destructor {
variable X
puts "X is $X"
}
}
Example2 create eg 3
eg addToX 5
eg addToX 2
eg destroy; # Prints 'X is 10'

Introspection is done by [info class], [info object] and (within
methods only) [self]. For example, the name of an object's private
namespace is given by [info object namespace $obj]. By itself, [self]
returns the name of the currently-executing object. See the
documentation for details.

Private methods are methods whose names don't begin with a lower-case
letter. They can be invoked on an object by using [my] instead of the
object name, like this:

...
method ThePrivateMethod ... ...
method aPublicMethod ... {
puts "before the private call"
my ThePrivateMethod ...
puts "after the private call"
}
...

The [my] command is always located in the object's private namespace.
This makes it ideal (with a very little trickery) for handling
callbacks like traces and events.

Expert stuff: classes *are* objects themselves (instances of
oo::class) which is why the syntax for making a class is so much like
the syntax for making a named object. Because it's exactly the same.
This is a deep rabbit-hole, but I'll stop writing this up here. :-)

Donal.

Gerald W. Lester

unread,
Jan 12, 2011, 9:42:08 AM1/12/11
to

We've already *HAVE* a tutorial out on TclOO!!!!!

It just is not **FREE**.

It takes *work* to do a good tutorial, hence people normally present them
first as paid "live" products then later convert them to free written/online
products.

tomk

unread,
Jan 12, 2011, 1:38:34 PM1/12/11
to

For me the best way to learn TclOO was to look at other peoples code.
I would recommend downloading WUB which has quite a bit of TclOO code.
tomk

Message has been deleted

Thomas MENEZ

unread,
Jan 12, 2011, 5:31:00 PM1/12/11
to
On Jan 12, 1:21 am, "Gerald W. Lester" <Gerald.Les...@KnG-
> | Email: Gerald.Les...@kng-consulting.net                                |
> +------------------------------------------------------------------------+

Well, it is not easily available. I've made a quick google-search, and
it did not find anything relevant. Typing "tcl tutorial" with google
brings a lot of interesting results, so I'm giving it time ;-).

Thomas MENEZ

unread,
Jan 12, 2011, 6:02:59 PM1/12/11
to

My personal belief is that 8.6 agenda was a bit (read extremely) too
ambitious. My bet would have been to split 8.6 agenda in 3, to be
able
to "release early, release often". 8.6, 8.7 , 8.8... But maybe the
features available in 8.6 are interconnected, ... maybe not.
What bothers me is that no linux distribution comes with 8.6, as it's
not *stable*, so we're stuck to 8.5 in linux world (I'm building
my own wish to cope with that, which can be a hassle for some).


Thomas

Thomas MENEZ

unread,
Jan 12, 2011, 6:03:31 PM1/12/11
to
On Jan 12, 3:11 pm, "Donal K. Fellows"

Thumbs up for this post !

Thomas MENEZ

unread,
Jan 12, 2011, 6:03:48 PM1/12/11
to

Thanks for the suggestion

tomas

unread,
Jan 13, 2011, 2:27:08 AM1/13/11
to
Thomas MENEZ <menez....@gmail.com> writes:

> What bothers me is that no linux distribution comes with 8.6, as it's
> not *stable*, so we're stuck to 8.5 in linux world (I'm building
> my own wish to cope with that, which can be a hassle for some).

FWIW, Debian testing (on the verge of becoming stable) comes with Tcl
8.6

Regards
-- tomás

Larry W. Virden

unread,
Jan 13, 2011, 7:17:01 AM1/13/11
to
On Jan 12, 9:42 am, "Gerald W. Lester" <Gerald.Les...@KnG-

Consulting.net> wrote:
> On 1/12/11 6:05 AM, Larry W. Virden wrote:
>
> > Rather than thinking of it being too early for someone to have written
> > a tutorial, you could think of it as the experts being too busy
> > finishing up the Tcl 8.6 code to sit down and writing a tutorial.

> We've already *HAVE* a tutorial out on TclOO!!!!!


>
> It just is not **FREE**.
>
> It takes *work* to do a good tutorial, hence people normally present them
> first as paid "live" products then later convert them to free written/online
> products.

> - Show quoted text -

Gerald, I apologize. You are right.

So the answer is - if someone wants to learn TclOO, thery need to a)
read the TIP, b) read the man pages, c) read the source code, d) read
the wiki pages that demonstrate uses of TclOO as well as any code
making use of TclOO, e) enroll the next time the TclOO tutorials are
available.

Larry W. Virden

unread,
Jan 13, 2011, 7:21:02 AM1/13/11
to
On Jan 12, 6:02 pm, Thomas MENEZ <menez.tho...@gmail.com> wrote:
> [...] so we're stuck to 8.5 in linux world (I'm building

> my own wish to cope with that, which can be a hassle for some).
> - Show quoted text -

There have been a variety of issues with secondary distributions of
Tcl over the years - sometimes the distribution changes broke Tcl,
sometimes the distributions didn't keep up with the releases that were
made.

Building one's own from the repository - or making use of ActiveState
ActiveTcl's binary distribution - are a couple of reliable options for
a developer. Then, making use of starkits or starpacks for software
distribution ensures that what your application needs is present on
the user's machine.

Gerald W. Lester

unread,
Jan 13, 2011, 8:43:59 AM1/13/11
to

At LEAST one of the above.

elipse

unread,
Jan 13, 2011, 1:26:35 PM1/13/11
to
On Jan 13, 9:27 am, tomas <to...@floh.bas23> wrote:

no, experimental only:
http://packages.debian.org/experimental/tcl8.6

mandriva 2010 is included tcl 8.6:
http://rpm.pbone.net/index.php3/stat/4/idpl/14270105/dir/mandriva_2010/com/tcl-debug-8.6-0.b1.3mdv2010.1.i586.rpm.html

elipse

unread,
Jan 13, 2011, 2:00:59 PM1/13/11
to

> Gerald, I apologize. You are right.
>
> So the answer is - if someone wants to learn TclOO, thery need to a)
> read the TIP,

And once:
http://www.tcl.tk/cgi-bin/tct/tip/6.html

Remarkably, and quite free. :)

tomas

unread,
Jan 14, 2011, 3:46:44 AM1/14/11
to

elipse <comp...@ymail.com> writes:

> On Jan 13, 9:27 am, tomas <to...@floh.bas23> wrote:

[...]

>> FWIW, Debian testing (on the verge of becoming stable) comes with Tcl
>> 8.6
>>
>> Regards
>> -- tomás
>
> no, experimental only:
> http://packages.debian.org/experimental/tcl8.6

Argh, sorry. I stand corrected. I'm running a backport of 8.6 and it
comes indeed from unstable.

It does build cleanly (as a Debian package) under testing. If anyone is
interested, I'll gladly dig out the recipe.

Regards
-- tomás

Harald Oehlmann

unread,
Jan 14, 2011, 4:10:45 AM1/14/11
to
On 13 Jan., 19:26, elipse <comp_...@ymail.com> wrote:
> On Jan 13, 9:27 am, tomas <to...@floh.bas23> wrote:
> > Thomas MENEZ <menez.tho...@gmail.com> writes:
> > > What bothers me is that no linux distribution comes with 8.6, as it's
> > > not *stable*, so we're stuck to 8.5 in linux world (I'm building
> > > my own wish to cope with that, which can be a hassle for some).

Reinhard provides 8 weeks old tcl 8.6 SuSE Linux packages ("Beta1.2").
Add the following URL to your package manager for OpenSuSE 11.3 and it
installs automatically:

http://download.opensuse.org/repositories/devel:/languages:/tcl:/tcl86/openSUSE_11.3/

elipse

unread,
Jan 14, 2011, 7:25:04 AM1/14/11
to
On Jan 14, 10:46 am, tomas <to...@floh.bas23> wrote:

Thanks.
After reading these threads:
http://www.adras.com/TclOO-and-inheritance-example-from-the-wiki-does-not-work.t12777-56.html

I quickly stupid and continue to dutifully use tcl 8.5, xotcl and
itcl :)
In other words, I use the stable things and having the necessary and
sufficient set of open documents.


elipse

unread,
Jan 14, 2011, 8:49:20 AM1/14/11
to
read:
http://www.tcl.tk/cgi-bin/tct/tip/311
and:
http://www.tcl.tk/cgi-bin/tct/tip/257.html

Тhis proposal and there is no information about implementation.
Тoo many of these "omissions"

Larry W. Virden

unread,
Jan 14, 2011, 9:36:19 AM1/14/11
to
> ôhis proposal and there is no information about implementation.
> ôoo many of these "omissions"

The TIP is a proposal for improvement. Some people prefer to hammer
out the requirements before implementation.

However, I do agree that there are a number of cases where someone has
submitted a proposal and then ran out of time to develop the proposal
into a set of requirements and an implementation.

I don't know how many of these there are, so I don't know whether I
would characterise the situation as being "too many" of them.

Reply all
Reply to author
Forward
0 new messages