| Author |
Why have I to rename before aliasing a command
|
|
| maurice.ulis@gmail.com 2006-05-27, 7:03 pm |
| 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
| |
| maurice.ulis@gmail.com 2006-05-27, 7:03 pm |
| Sorry.
The complete script:
package require Tk
frame .f
#rename ::.f ::_.f
interp alias {} ::.f {} ::myproc
proc myproc {args} {}
pack .f
| |
| stephanearnold@yahoo.fr 2006-05-28, 4:06 am |
| 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=E9phane
| |
| maurice.ulis@gmail.com 2006-05-28, 7:10 pm |
| Many thanks for this info St=E9phane.
It's strange that interp alias destroys the aliased command.
And it remains strange that pack .f uses the .f command.
ulis
| |
| suchenwi 2006-05-29, 7:09 pm |
| 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 :-)
| |
| maurice.ulis@gmail.com 2006-05-29, 7:09 pm |
| lamentable
| |
| Florian.Murr@siemens.com 2006-05-31, 4:13 am |
| 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!
|
|
|
|