Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ITCL #auto object name

708 views
Skip to first unread message

JonoK

unread,
Sep 11, 2012, 7:45:11 PM9/11/12
to
Hi,

I'm learning/experimenting with ITCL with a view to using it for a project. I'm using 8.6, and the version of ITCL that comes bundled with that.

So, when I use #auto to auto generate an object name I get back something like classA0, classB1 ... which is fine, except it's not the actual name of the object ... later on when I try to use the object from a different context I get an unknown command error: it appears that the name of the object is the name within the local context when the object was created, something like ::classA::classB1.

I've worked around this by using a proc to generate a global name at each object creation point, but that's a bit cludgy.

Is there a way to make the auto name global? Or is there an elegant way to only have the name generation override in one place.

TIA
Jon

Donal K. Fellows

unread,
Sep 12, 2012, 4:14:27 AM9/12/12
to
On 12/09/2012 00:45, JonoK wrote:
> Is there a way to make the auto name global? Or is there an elegant
> way to only have the name generation override in one place.

It sounds to me like that's a bug in the name generation code; itcl 4
(the version you're testing) has been substantially rewritten from
previous versions, and it sounds like this is a place where an issue
remains. (I've got an idea about what's going on; it's probably linked
to a change in the semantics of name qualification in the TclOO
constructor layer that itcl 4 is building on top of. TclOO itself is
immune because it uses a different algorithm for automatic name
generation. The fix is to do a little adjustment to the name
construction code in Itcl_HandleClass in itclClass.c; I think adding a
'::' in the right spot will do the trick, it's a one-liner.)

Fortunately, this is actually likely to be easy to fix quickly. We're
testing release candidates of Tcl 8.6b3, so a critical problem like this
can be dealt with very rapidly. I've filed a bug report attaching your
message and my suggested fix (and, importantly, its consequences):

https://sourceforge.net/support/tracker.php?aid=3566940

Donal.

Ralf Fassel

unread,
Sep 12, 2012, 5:29:46 AM9/12/12
to
* "Donal K. Fellows" <donal.k...@manchester.ac.uk>
| On 12/09/2012 00:45, JonoK wrote:
| > Is there a way to make the auto name global? Or is there an elegant
| > way to only have the name generation override in one place.
--<snip-snip>--
| Fortunately, this is actually likely to be easy to fix quickly. We're
| testing release candidates of Tcl 8.6b3, so a critical problem like this
| can be dealt with very rapidly. I've filed a bug report attaching your
| message and my suggested fix (and, importantly, its consequences):
>
| https://sourceforge.net/support/tracker.php?aid=3566940

We've used something like
set object [SomeItclObject ::\#auto]
to work-around this problem.

Maybe the proposed change should check whether there is already
a "::" at the start of the name...

R'

Michael Barth

unread,
Sep 14, 2012, 1:46:02 PM9/14/12
to
[Donal K. Fellows (Wednesday 12 September 2012 10:14)]:
It's not a bug, it's feature. :-(

Even earlier versions have this feature: The instantiation of a class
returns NOT the full class name, but only the defined name.

Solution: Use [namespace current]:

MyClass [namespace current]::#auto

Or write a wrapper around your class:

proc myclass {args} {
eval MyClass [uplevel namespace current]::#auto $args
}

Regards
Michael

Donal K. Fellows

unread,
Sep 17, 2012, 5:02:59 AM9/17/12
to
On 12/09/2012 00:45, JonoK wrote:
> So, when I use #auto to auto generate an object name I get back
> something like classA0, classB1 ... which is fine, except it's not
> the actual name of the object ... later on when I try to use the
> object from a different context I get an unknown command error: it
> appears that the name of the object is the name within the local
> context when the object was created, something like
> ::classA::classB1.

After discussions, it seems that this is the way it is supposed to work;
it's a documented feature, though the documentation of the consequences
could be rather clearer. (I don't care for doing it this way, but there
you go.)

> Is there a way to make the auto name global? Or is there an elegant
> way to only have the name generation override in one place.

To get a global name, use a qualified-name to request it such as
“::#auto” (which will put the object in the global namespace and return
the fully-qualified name). The alternative is to apply [namespace which]
to the result of the creation with a plain “#auto” to get the fully-
qualified name.

Donal.

JonoK

unread,
Sep 21, 2012, 12:56:21 AM9/21/12
to
Thanks for the clarification.
0 new messages