namespace code
Gives a script that runs in the current namespace from each place.
namespace code SCRIPT
Description
Gives the command prefix ::namespace inscope NS SCRIPT, with NS the current namespace. The prefix runs SCRIPT in NS from each place, so it is the form of a callback that a proc of NS gives to other code, such as a trace or a command of the event loop.
Words after the prefix go after SCRIPT as more words of its command.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| SCRIPT | script | required | The script of the callback. |
Returns
The script ::namespace inscope NS SCRIPT.
Examples
% namespace eval cb {variable n 0; proc bump {} {variable n; incr n}}
> namespace eval cb {namespace code bump}
::namespace inscope ::cb bump
# bump is found in ::cb from the global scope.
% set s [namespace eval cb {namespace code bump}]
> eval $s
> eval $s
2
# The words y and z go after the script.
% set s [namespace eval cb {namespace code {list x}}]
> {*}$s y z
x y z
Errors
% namespace code
wrong # args: should be "namespace code arg"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1