Updated 2016-10-11 15:50:32 by pooryorick
namespace code script

Captures the current namespace context for later execution of the script script. It returns a new script in which script has been wrapped in a namespace inscope command. The new script has two important properties. First, it can be evaluated in any namespace and will cause script to be evaluated in the current namespace (the one where the namespace code command was invoked). Second, additional arguments can be appended to the resulting script and they will be passed to script as additional arguments. For example, suppose the command set script [namespace code {foo bar}] is invoked in namespace ::a::b. Then eval "$script x y" can be executed in any namespace (assuming the value of script has been passed in properly) and will have the same effect as the command ::namespace eval ::a::b {foo bar x y}. This command is needed because extensions like Tk normally execute callback scripts in the global namespace. A scoped command captures a command together with its namespace context in a way that allows it to be executed properly later.

Curry  edit

PYK 2016-10-11: Over at the curry page there are two procedures, partial and curry, that use apply and tailcall instead of namespace code to partially apply and curry commands. They avoid adding the extra level to the evaluation stack that namespace code adds, and eliminate the need to use {*} to call the curried command. The remainder of this section is historical.

  Historical

See Also  edit

eval