Prev: Active State base-tcl8 vfs::ftp Error can't find package ftp
Next: How to change fg color of specific words in a text widget
From: Randy Melton on 24 Feb 2010 20:11 consider the following: namespace eval a {} proc a::unknown {args} {puts stderr "my unknown ..."} namespace eval a {namespace unknown ::a::unknown} a::help --> invalid command name "a::help" namespace eval a {help} --> my unknown ... I assumed that the unknown handler local to the namespace would be invoked? I can see why you might want the global unknown, but it wasn't obvious what would happen.
From: slebetman on 25 Feb 2010 04:57 On Feb 25, 9:11 am, Randy Melton <seade...(a)gmail.com> wrote: > consider the following: > > namespace eval a {} > proc a::unknown {args} {puts stderr "my unknown ..."} > namespace eval a {namespace unknown ::a::unknown} > a::help > --> invalid command name "a::help" > namespace eval a {help} > --> my unknown ... > > I assumed that the unknown handler local to the namespace would be > invoked? I can see why you might want the global unknown, but it > wasn't obvious what would happen. namespace unknown catches unknown procs that are executed in the given namespace. You are instead attempting to execute a proc defined in a given namespace in the current (global) namespace which is why the unknown mechanism for the current namespace is invoked. If instead you did: namespace eval a {help} then you would have triggered the unknown mechanism for namespace "a".
From: Randy Melton on 25 Feb 2010 13:42
On Feb 25, 2:57 am, "slebet...(a)yahoo.com" <slebet...(a)gmail.com> wrote: > namespace unknown catches unknown procs that are executed in the given > namespace. You are instead attempting to execute a proc defined in a > given namespace in the current (global) namespace which is why the > unknown mechanism for the current namespace is invoked. If instead you I'm not sure this is true. I think a::help is "launched" from the global namespace but executes in the "a" namespace. I believe the distinction between launch/execution namespace is is unclear in the "namespace unknown" command. I believe I clearly understand what is happening, I'm just questioning the implementation. One of the things I appreciate in Tcl is that most things follow pretty clear rules. I think this launch vs execution namespace WRT unknown is at best ambiguous. One might expect a::help to behave the same as namespace eval a {help}. I've read the TIP (http://www.tcl.tk/cgi-bin/tct/tip/181.html) several times trying to understand the implementation constraints. When the phrase "current namespace" is used I think it refers to the launch namespace then later it seems to refer to execution namespace. (step 4 in the "to this" section.) For the issue at hand I found "let unknown know" and the "namespace unknown" version (http://wiki.tcl.tk/12790) very useful. Using those I added a handler to watch for a::* and dispatch those calls to a::unknown. thanks, randy |