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

Why have I to rename before aliasing a command

5 views
Skip to first unread message

mauric...@gmail.com

unread,
May 27, 2006, 12:15:11 PM5/27/06
to
Hello,

I got a
'bad window path name ".f"
while executing
"pack .f"'
error with the following script.

package require Tk
frame .f
#rename ::.f ::_.f
proc myproc {args} {}
pack .f

The error vanished when I renamed the command (commented out line).
Can someone explain me what happened?
(I use Tk 8.4 and doz XP)

Thanks

ulis

mauric...@gmail.com

unread,
May 27, 2006, 12:16:45 PM5/27/06
to
Sorry.
The complete script:

package require Tk
frame .f
#rename ::.f ::_.f

interp alias {} ::.f {} ::myproc

stephan...@yahoo.fr

unread,
May 28, 2006, 2:58:09 AM5/28/06
to
Hi Maurice,

I tested it and saw that, each time you invoke interp alias, it causes
the aliased proc (or widget) to be destroyed.

proc a {arg} {puts a:$arg}
proc b {arg} {puts b:$arg}
# it works
puts [info body a]
interp alias {} ::a {} ::b
# error : a is not a procedure :
info body a

Regards,
Stéphane

mauric...@gmail.com

unread,
May 28, 2006, 3:19:44 PM5/28/06
to
Many thanks for this info Stéphane.

It's strange that interp alias destroys the aliased command.
And it remains strange that pack .f uses the .f command.

ulis

suchenwi

unread,
May 29, 2006, 4:31:51 AM5/29/06
to
Strange?
A command is either a C-coded one, a proc, or an alias. When you define
an alias named "foo", it deletes the previous instance. And in Tk, each
widget has a command with the same name. Removing such a command also
destroys the connected widget. Easily seen when you type, in an
interactive wish:
proc . args {puts hello}
The proc "." overwrites the widget command ".", which leads to its
destruction, and exit of the whole wish :-)

mauric...@gmail.com

unread,
May 29, 2006, 4:39:13 AM5/29/06
to
lamentable

Floria...@siemens.com

unread,
May 31, 2006, 4:13:05 AM5/31/06
to
lamentable? On the contrary!
See this beauty: I had some events that sent milli-seconds to my
programm and I had to cope with overflow of 32-bit ints. So I came up
with the following:

set WIDE_MAX_INT [expr {wide((1<<31)-1)}]
set wideUint [expr {wide(0)}]

proc wideUintP {a} {
if {$a<0} {
set ::wideUint [expr
{$::wideUint+$::WIDE_MAX_INT+$::WIDE_MAX_INT+2}]
interp alias {} ::wide_unsigned {} ::wideUintM
}
expr {wide($::wideUint+$a)}
}

proc wideUintM {a} {
if {$a>0} { interp alias {} ::wide_unsigned {} ::wideUintP }
expr {$::wideUint+$a}
}

interp alias {} ::wide_unsigned {} ::wideUintP

Now I can use [wide_unsigned $milli] without having to bother about
overflow anymore!
See how beautiful the two procs toggle.
And the best is, the implementation is so simple and efficient!

0 new messages