Re: After I overload "switch" command, how can I get back the original "switch" function back?



pheobe wrote:
I am planning to overlad "switch" command in my application, and use
it do something, yet after that, how can I get back the original
function of "switch" ? I don't want to use the overlad "switch" all
through my appliction.

You have to take action *before* you overload the [switch] command. To
do this, you use the [rename] command to change the original [switch] to
something else, before creating the replacement procedure. Once you've
finished with the overload, [rename] the saved real [switch] command
back to its normal name. Like this:

rename switch switch_savedForLaterByPheobe
proc switch args {
...
}
# do stuff with the custom [switch] here before restoring...
rename switch_savedForLaterByPheobe switch

If the code that is using your modified [switch] is in a namespace other
than the default global one, another technique is possible. Simply
create the modified [switch] inside that other namespace; it will then
overload inside the procedures in that namespace automatically without
affecting any commands elsewhere.

namespace eval someNs {
proc yourProcedure ... ...
proc switch args {
...
}
}
# Invoke command that uses the custom [switch]
someNs::yourProcedure ...

Note that you can cause the code in the namespace to use the standard
[switch] by just deleting or renaming the namespace's local switch
command, like this:

# To delete, do this:
rename someNs::switch {}
# To move out of the way, do this:
rename someNs::switch someNs::switch_outOfService

(Tcl 8.5 has some extra techniques that are more-powerful variants on
this theme, but the schemes already described will continue to work for
at least the foreseeable future.)

Donal.
.



Relevant Pages

  • Re: Decision Tables
    ... namespace parser{ ... switch ){ ... bool b = expr; ... "See source grammar for query syntax\n" ...
    (comp.programming)
  • Re: Tcl Switch case
    ... Going back to the 'mess' which is switch. ... a unique command in several ways. ... The nocase variety does the same thing in the::myswitchnc namespace. ...
    (comp.lang.tcl)
  • Re: SET_PERSONALITY and TASK_SIZE
    ... for the interpreter happens in the namespace of the ... SET_PERSONALITY is NOT allowed to switch ... 'extra' bits is set we may incorrectly set personality to PER_LINUX even ...
    (Linux-Kernel)
  • Re: using /namespace with tlbimp.
    ... I want some information regarding /namespace switch. ... Namespace of the source code where our COM dll is referenced for which we ... Using the tlbimp /namespace switch, you can control the namespace in which ... the interop typeinfo is generated. ...
    (microsoft.public.dotnet.framework)
  • Re: C2960 config - What do the commands do
    ... To enable visible sequence numbering of system logging messages, use the service sequence-numbers command in global configuration mode. ... Configure the system to automatically switch to summer time. ... This sybnet has the same network address what main network (the subnetted one) but longer subnet mask ... For chassis with 64 MAC addresses, STP uses the extended system ID plus a MAC address to make the bridge ID unique for each VLAN. ...
    (comp.dcom.sys.cisco)