info -- Interpreter introspection

Syntax: info subcommand ?arg ...?

Returns information about the state of the Molt interpreter.

SubcommandDescription
info argsNames of procedure's arguments
info bodyGets procedure body
info cmdtypeQueries a command's type
info commandsNames of all defined commands
info completeIs this string a syntactically complete command?
info defaultA procedure argument's default value
info existsIs this a variable in the current scope?
info globalsNames of all variables in the global scope
info localsNames of all local variables in the current scope
info procsNames of all defined procedures
info varsNames of all variables in the current scope

info args

Syntax: info args procname

Retrieves a list of the names of the arguments of the named procedure. Returns an error if the command is undefined or is a binary command.

For example,

% proc myproc {a b c} { ... }
% info args myproc
a b c
%

info body

Syntax: info body procname

Retrieves the body of the named procedure. Returns an error if the command is undefined or is a binary command.

For example,

% proc myproc {name} { puts "Hello, $name" }
% info body myproc
puts "Hello, $name"
%

info cmdtype

Syntax: info cmdtype command

Retrieves the named command's type, either native or proc. The command is native if it's implemented in Rust and proc if it's implemented as a TCL procedure.

% proc myproc {} { ... }
% info cmdtype set
native
% info cmdtype myproc
proc
%

TCL Liens: Standard TCL defines a variety of other command types, e.g., slave interpreters, interpreter aliases, objects, and so forth. These will be added naturally if and when they are added to Molt.

info commands

Syntax: info commands

Returns an unsorted list of the names of the commands defined in the interpreter, including both binary commands and procedures.

TCL Liens: does not support filtering the list using a glob pattern.

info complete

Syntax: info complete command

Returns 1 if the command appears to be a complete Tcl command, i.e., it has no unmatched quotes, braces, or brackets, and 0 otherwise. REPLs can use this to allow the user to build up a multi-line command.

For example,

% info complete { puts "Hello, world!" }
1
% info complete { puts "Hello, world! }
0
%

info default

Syntax: info default procname arg varname

Retrieves the default value of procedure procname's argument called arg. If arg has a default value, info default returns 1 and assigns the default value to the variable called varname. Otherwise, info default returns 0 and assigns the empty string to the variable called varname.

The command throws an error if:

  • procname doesn't name a procedure
  • The procedure procname has no argument called arg
  • The value can't be assigned to a variable called varname.

In the following example, myproc has two arguments, a and b. a has no default value; b has the default value Howdy.

% proc myproc {a {b Howdy}} { ... }
% info default myproc a defvalue
0
% puts "<$defval>"
<>
% info default myproc b defvalue
1
% puts "<$defval>"
<Howdy>
%

info exists

Syntax: info exists varname

Returns 1 if varname is the name of a variable or array element in the current scope, and 0 otherwise.

% set a 1
1
% set b(1) 1
1
% info exists a
1
% info exists b
1
% info exists c
0
% info exists b(1)
1
% info exists b(2)
0

info globals

Syntax: info globals

Returns an unsorted list of the names of all variables defined in the global scope.

TCL Liens: does not support filtering the list using a glob pattern.

info locals

Syntax: info locals

Returns an unsorted list of the names of all local variables defined in the current scope, e.g., proc arguments and variables defined locally, but no variables brought in from other scopes via global or upvar.

TCL Liens: does not support filtering the list using a glob pattern.

info procs

Syntax: info procs

Returns an unsorted list of the names of the procedures defined in the interpreter, omitting binary commands.

TCL Liens: does not support filtering the list using a glob pattern.

info vars

Syntax: info vars

Returns an unsorted list of the names of all variables that are visible in the current scope, whether global or local.

TCL Liens: does not support filtering the list using a glob pattern.