interp eval
Runs a script in a child interpreter and gives its result.
interp eval PATH ARG ?ARG ...?
Description
Joins the ARG words with spaces, as concat does, and runs the result as a script in the interpreter of PATH, at its global level. The result of the script is the result of the command.
An error in the script is an error of interp eval, with the message and the -errorcode of the child. The variables and the procs of the child stay after the call, so the next interp eval sees them.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| PATH | interpreter path | required | The interpreter that runs the script. |
| ARG | string | required | A part of the script. |
Returns
The result of the script.
Examples
% set c [interp create]; interp eval $c {set x 5}
5
% interp eval $c {incr x}
6
# The words join into the script `set y 2`.
% interp eval $c set y 2
2
# The path {} is the current interpreter.
% interp eval {} {expr {1 + 1}}
2
Errors
% interp eval $c {expr 1/0}
divide by zero
-errorcode ARITH DIVZERO {divide by zero}
% interp eval nope {set x 1}
could not find interpreter "nope"
-errorcode TCL LOOKUP INTERP nope
% interp eval $c
wrong # args: should be "interp eval path arg ?arg ...?"
-errorcode TCL WRONGARGS
Facts
- Capability
interp. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1