beetlebug▾
/

interp create

Makes a new child interpreter and gives its path.

interp create ?-safe? ?-meter NAME? ?--? ?PATH?

Description

Makes a new interpreter at PATH and gives PATH. With no PATH the name is interpN, with the first N from 0 that no child of the current interpreter has. A PATH with more than one name makes a child of the interpreter of the path before the last name, and that interpreter must exist.

A new child has the commands of a new interpreter and the capabilities of its parent. With -safe it is a safe interpreter: it has no command of a capability, no interp, and no exit. A safe child of ztcl has no hidden commands, so interp hidden gives an empty list for it. No command with the name of the path is made: the parent reaches the child through interp eval.

An option can come before or after PATH, and -- ends the options, for a PATH that starts with -.

Arguments

ArgumentTypeDefaultDescription
PATHinterpreter pathnoneThe path of the new interpreter: a list of names from the current interpreter.

Options

OptionTypeDefaultDescription
-safeflagnoneMakes a safe interpreter.
-metermeter namenoneCounts the child in a meter of ztcl::meter.
--flagnoneEnds the options.

-safe

Makes a safe interpreter.

The child has only the commands that reach no host resource and no other interpreter: no interp, no exit, and no command of a capability such as file or clock. interp issafe gives 1 for it. A safe child can get one power from its parent through an alias.

% set s [interp create -safe]; interp issafe $s
1

% interp eval $s {info commands interp}

# The option can come after PATH.
% interp create sandbox -safe
sandbox

A flag has no value to check.

-meter NAME

Counts the child in a meter of ztcl::meter.

The compute units, time, memory, and I/O of the child count in the meter NAME of ztcl::meter, which the option makes when it does not exist. It needs the capability meter, and with no capability meter the option is a bad option. The message of a bad option lists only -safe and -- in each case.

% interp create -meter billing job
job

% dict get [ztcl::meter get billing] name
billing
# The option has no value.
% interp create -meter
bad option "-meter": must be -safe or --
-errorcode TCL LOOKUP INDEX option

--

Ends the options.

The word after -- is PATH, also when it starts with -.

% interp create -safe -- -x
-x

A flag has no value to check.

Returns

The path of the new interpreter.

Examples

% interp create
interp0

% interp create box
box

% interp create {box inner}
box inner

% interp children box
inner

% interp create -- -dash
-dash

Errors

% interp create box
interpreter named "box" already exists, cannot create
-errorcode NONE

% interp create a b
wrong # args: should be "interp create ?-safe? ?--? ?path?"
-errorcode TCL WRONGARGS

% interp create -bogus
bad option "-bogus": must be -safe or --
-errorcode TCL LOOKUP INDEX option

% interp create {nope inner}
could not find interpreter "nope inner"
-errorcode NONE

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

See also