Updated 2012-02-10 02:15:20 by RLE

interp create ?-safe? ?--? ?path?

Creates a slave interpreter identified by path and a new command, called a slave command. The name of the slave command is the last component of path. The new slave interpreter and the slave command are created in the interpreter identified by the path obtained by removing the last component from path. For example, if path is a b c then a new slave interpreter and slave command named c are created in the interpreter identified by the path a b. The slave command may be used to manipulate the new interpreter as described below. If path is omitted, Tcl creates a unique name of the form interpx, where x is an integer, and uses it for the interpreter and the slave command. If the -safe switch is specified (or if the master interpreter is a safe interpreter), the new slave interpreter will be created as a safe interpreter with limited functionality; otherwise the slave will include the full set of Tcl built-in commands and variables. The -- switch can be used to mark the end of switches; it may be needed if path is an unusual value such as -safe. The result of the command is the name of the new interpreter. The name of a slave interpreter must be unique among all the slaves for its master; an error occurs if a slave interpreter by the given name already exists in this master. The initial recursion limit of the slave interpreter is set to the current recursion limit of its parent interpreter.

Note that interp create has to do a lot of processing to find init.tcl and load it, to construct a sensible tcl environment. This is quite time consuming. If you need a swifter interp create and can live with (very) reduced functionality, use -safe, it's substantially faster:
 puts "Normal interp create: [time {interp create} 40]"
 Normal interp create: 9236.6 microseconds per iteration

compared to:
 puts "Safe interp create :[time {interp create -safe} 40]"
 Safe interp create :967.55 microseconds per iteration

See also:

Category Command[Category Tcl syntax help]