info(n)
π info(n) β Tcl Built-In Commands π
πΈ NAME πΈ
info β the tea on the state of your Tcl interpreter. ββ¨
β¨ SYNOPSIS β¨
info option ?arg arg ...?
π DESCRIPTION π
Available commands:
info argsprocname β spits out the names of the parameters for the procedure named procname. πinfo bodyprocname β gives you the body of the procedure named procname. πinfo classsubcommand class ?arg ...? β returns info about the class named class. Peep CLASS INTROSPECTION below. πinfo cmdcountβ returns the total number of commands evaluated in this interpreter. π’info cmdtypecommandName β returns the type of the command named commandName. The built-in types are: π§aliasβ commandName was created byinterp alias. In a safe interpreter an alias is only visible if both the alias and the target are visible. πcoroutineβ commandName was created bycoroutine. πensembleβ commandName was created bynamespace ensemble. πΌimportβ commandName was created bynamespace import. π₯nativeβ commandName was created by theTcl_CreateObjCommandinterface directly without further registration of the type of command. π οΈobjectβ commandName is the public command that represents an instance ofoo::objector one of its subclasses. π§¬privateObjectβ commandName is the private command,myby default, that represents an instance ofoo::objector one of its subclasses. π€«procβ commandName was created byproc. βοΈinterpβ commandName was created byinterp create. πzlibStreamβ commandName was created byzlib stream. ποΈ
info commands?pattern? β returns the names of all commands visible in the current namespace. If pattern is given, it returns only those names that match according tostring match. Only the last component of pattern is a pattern. Other components identify a namespace. See NAMESPACE RESOLUTION in thenamespace(n)documentation. πinfo completecommand β returns1if command is a complete command, and0otherwise. Usually used in line-oriented input environments so users can type commands that span multiple lines. βinfo constantvarName β returns1if varName is a constant variable (seeconst) and0otherwise. πinfo consts?pattern? β returns the list of constant variables (seeconst) in the current scope, or the list of constant variables matching pattern (if that is provided) in a manner similar toinfo vars. πinfo coroutineβ returns the name of the current coroutine, or the empty string if there is no current coroutine or the current coroutine has been deleted. πͺ’info defaultprocname parameter varname β If the parameter parameter for the procedure named procname has a default value, stores that value in varname and returns1. Otherwise, returns0. πinfo errorstack?interp? β returns a description of the active command at each level for the last error in the current interpreter, or in the interpreter named interp if given. π¨
The description is a dictionary of tokens and parameters. Tokens are currently either CALL, UP, or INNER, but other values may be introduced in the future. CALL indicates a command call, and its parameter is the corresponding info level 0. UP indicates a shift in variable frames generated by uplevel or similar, and applies to the previous CALL item. Its parameter is the level offset. INNER identifies the βinner contextβ, which is the innermost atomic command or bytecode instruction that raised the error, along with its arguments when available. While CALL and UP provide a trail of the call path, INNER provides details of the offending operation in the innermost procedure call, even to sub-expression granularity.
This information is also present in the -errorstack entry of the options dictionary returned by 3-argument catch; info errorstack is a convenient way of retrieving it for uncaught errors at top-level in an interactive interpreter.
info existsvarName β returns1if a variable named varName is visible and has been defined, and0otherwise. πinfo frame?depth? β returns the depth of the call toinfo frameitself. Otherwise, returns a dictionary describing the active command at the depth, which counts all commands visible toinfo level, plus commands that don't create a new level, such aseval,source, oruplevel. The frame depth is always greater than the current level. π§΅
If depth is greater than 0 it is the frame at that depth. Otherwise it is the number of frames up from the current frame.
As with info level and error traces, for nested commands like βfoo [bar [x]]β, only βxβ is seen by info frame invoked within βxβ.
The dictionary may contain the following keys:
typeβ Always present. Possible values aresource,proc,eval, andprecompiled.sourceβ A script loaded via thesourcecommand.procβ The body of a procedure that could not be traced back to a line in a particular script.evalβ The body of a script provided toevaloruplevel.precompiledβ A precompiled script (loadable by the packagetbcload), and no further information is available.
lineβ The line number of the command inside its script. Not available for precompiled commands. When the type issource, the line number is relative to the beginning of the file, whereas for the last two types it is relative to the start of the script.fileβ For typesource, provides the normalized path of the file that contains the command.cmdβ The command before substitutions were performed.procβ For typeproc, the name of the procedure containing the command.lambdaβ For a command in a script evaluated as the body of an unnamed routine via theapplycommand, the definition of that routine.levelβ For a frame that corresponds to a level, (to be determined).
When a command can be traced to its literal definition in some script, e.g. procedures nested in statically defined procedures, and literal eval scripts in files or statically defined procedures, its type is source and its location is the absolute line number in the script. Otherwise, its type is proc and its location is its line number within the body of the procedure.
In contrast, procedure definitions and eval within a dynamically evaluated environment count line numbers relative to the start of their script, even if they would be able to count relative to the start of the outer dynamic script. That type of number usually makes more sense.
A different way of describing this behaviour is that file-based locations are tracked as deeply as possible, and where this is not possible the lines are counted based on the smallest possible eval or procedure body, as that scope is usually easier to find than any dynamic outer scope.
The syntactic form {*} is handled like eval. I.e. if it is given a literal list argument the system tracks the line number within the list words as well, and otherwise all line numbers are counted relative to the start of each word (smallest scope)
info functions?pattern? β If pattern is not given, returns a list of all the math functions currently defined. If pattern is given, returns only those names that match pattern according tostring match. πinfo globals?pattern? β If pattern is not given, returns a list of all the names of currently-defined global variables. Global variables are variables in the global namespace. If pattern is given, only those names matching pattern are returned. Matching is determined using the same rules as forstring match. πinfo hostnameβ Returns the name of the current host. π
This name is not guaranteed to be the fully-qualified domain name of the host. Where machines have several different names, as is common on systems with both TCP/IP (DNS) and NetBIOS-based networking installed, it is the name that is suitable for TCP/IP networking that is returned.
info level?level? β If number is not given, the level this routine was called from. Otherwise returns the complete command active at the given level. If number is greater than0, it is the desired level. Otherwise, it is number levels up from the current level. A complete command is the words in the command, with all substitutions performed, meaning that it is a list. Seeuplevelfor more information on levels. πͺinfo libraryβ Returns the value oftcl_library, which is the name of the library directory in which the scripts distributed with Tcl scripts are stored. πinfo loaded ?interp? ?prefix?β bestie this one tells you the name of every file that got loaded into interp by theloadcommand, with prefix prefix. Don't give a prefix and you get a list where every item is the name of the loaded file plus the prefix it was loaded for. For a statically-loaded package, the name of the file is just the empty string. And for interp, the empty string means the current interpreter. πinfo locals ?pattern?β if pattern is given, you get the name of every local variable that matches pattern according tostring match. No pattern? You get the name of every local variable, periodt. Little heads up tho: a variable defined withglobal,upvarorvariableis not local, so it does NOT show up here. π«info nameofexecutableβ returns the absolute pathname of the program for the current interpreter. If such a file literally cannot be identified, you get an empty string back. π«info object subcommand object ?arg ...β returns information about the object named object. subcommand is described in OBJECT INTROSPECTION below. iykyk πinfo patchlevelβ returns the value of the global variabletcl_patchLevel, which is where the exact version of the Tcl library was initially stored. βinfo procs ?pattern?β names of all the visible procedures, bestie. Give it a pattern and it only returns those names that match according tostring match. Only the final component in pattern is actually considered a pattern β any qualifying components just select a namespace. See NAMESPACE RESOLUTION in thenamespace(n)documentation. πinfo script ?filename?β the pathname of the innermost script currently being evaluated, or the empty string if no pathname can be determined. If filename is given, it sets the return value of any future calls toinfo scriptfor the duration of the innermost active script. That is so genuinely useful in virtual file system applications. πinfo sharedlibextensionβ the extension used on this platform for names of shared libraries, e.g..sounder Solaris. Returns the empty string if shared libraries are not supported on this platform. πΈinfo tclversionβ returns the value of the global variabletcl_version, where the major and minor version of the Tcl library are stored. πinfo vars ?pattern?β no pattern given? You get the names of all visible variables. pattern given? Only the names that match according tostring match. Only the last component of pattern is a pattern; the other components identify a namespace. See NAMESPACE RESOLUTION in thenamespace(n)documentation. And when pattern is a qualified name, the results come back fully qualified. β¨
Alsooo, a variable that has been declared but not yet given a value will be included in the results. It's in there. Lurking. π
π¦ CLASS INTROSPECTION π¦
The following subcommand values are supported by info class:
info class call class methodβ returns a description of the method implementations that are used to provide a stereotypical instance of class's implementation of method (stereotypical instances being objects instantiated by a class without having any object-specific definitions added). This is a list of lists of four elements, where each sublist goes like this:- a word that describes the general type of method implementation β one of
methodfor an ordinary method,filterfor an applied filter,privatefor a private method, andunknownfor a method that is invoked as part of unknown method handling - a word giving the name of the particular method invoked β which is always the same as method for the method type, and "unknown" for the unknown type
- a word giving the fully qualified name of the class that defined the method
- a word describing the type of method implementation β see
info class methodtype
- a word that describes the general type of method implementation β one of
Note that there is no inspection of whether the method implementations actually use next to transfer control along the call chain, and the call chains that this command files do not actually contain private methods.
info class constructor classβ returns a description of the definition of the constructor of class class. The definition is described as a two element list: the first element is the list of arguments to the constructor in a form suitable for passing to another call toprocor a method definition, and the second element is the body of the constructor. No constructor present? You get the empty list. π«Άinfo class definition class methodβ returns a description of the definition of the method named method of class class. Also a two element list: the first element is the list of arguments to the method in a form suitable for passing to another call toprocor a method definition, and the second element is the body of the method. β¨info class definitionnamespace class ?kind?β returns the definition namespace for kind definitions of the class class; the definition namespace only affects the instances of class, not class itself. kind can be either-classto return the definition namespace used foroo::define, or-instanceto return the definition namespace used foroo::objdefine; the-classkind is default (though this is only actually useful on classes that are subclasses ofoo::class). π
If class does not provide a definition namespace of the given kind, this command returns the empty string. In those circumstances, the oo::define and oo::objdefine commands look up which definition namespace to use using the class inheritance hierarchy.
info class destructor classβ returns the body of the destructor of class class. If no destructor is present, this returns the empty string. π³οΈinfo class filters classβ returns the list of filter methods set on the class. π₯info class forward class methodβ returns the argument list for the method forwarding called method that is set on the class called class.info class instances class ?pattern?β returns a list of instances of class class. If the optional pattern argument is present, it constrains the list of returned instances to those that match it according to the rules ofstring match. πinfo class methods class ?options...?β returns a list of all public (i.e. exported) methods of the class called class. Any of the following options may be given, controlling exactly which method names come back:-allβ if the-allflag is given, and the-scopeflag is not given, the list of methods will include those methods defined not just by the class, but also by the class's superclasses and mixins.-privateβ if the-privateflag is given, and the-scopeflag is not given, the list of methods will also include the non-exported methods of the class (and superclasses and mixins, if-allis also given). Note that this naming is an unfortunate clash with true private methods; this option name is retained for backward compatibility. π-scope scopeβ returns a list of all methods on class that have the given visibility scope. When this option is supplied, both the-alland-privateoptions are ignored. The valid values for scope are:publicβ only methods with public scope (i.e., callable from anywhere by any instance of this class) are to be returned.unexportedβ only methods with unexported scope (i.e., only callable viamy) are to be returned.privateβ only methods with private scope (i.e., only callable from within this class's methods) are to be returned.
info class methodtype class methodβ returns a description of the type of implementation used for the method named method of class class. When the result ismethod, further information can be discovered withinfo class definition, and when the result isforward, further information can be discovered withinfo class forward. π§info class mixins classβ returns a list of all classes that have been mixed into the class named class. πinfo class properties class ?options...β returns a sorted list of properties defined on the class named class. The options define exactly which properties are returned:-allβ with this option, the properties from the superclasses and mixins of the class are also returned.-readableβ this option (the default behavior) asks for the readable properties to be returned. Only readable or writable properties are returned, not both.-writableβ this option asks for the writable properties to be returned. Only readable or writable properties are returned, not both. π
info class subclasses class ?pattern?
Okay bestie, this one's giving "who are your kids?" energy. It returns a list of the direct subclasses of the class class. And if you toss in that optional pattern argument? It's like a little filter β only the classes that match it according to the rules of string match get to stay. π
info class superclasses class
This one's the reverse: it hands you a list of the direct superclasses of class class, and it's in inheritance precedence order. So like, the order matters, bestie. No cap. π
info class variables class ?-private?
Returns a list of all variables that have been declared for the class named class. Translation: these are the variables that are automatically present in the class's methods, constructor and destructor. If you add the -private option, it instead lists the private variables that were declared. Periodt. π
β¨ OBJECT INTROSPECTION β¨
The following subcommand values are supported by info object:
info object call object method
Returns a description of the method implementations that are used to provide object's implementation of method. This is a list of lists of four elements. Each sublist has:
- a word describing the general type of method implementation β one of
methodfor an ordinary method,filterfor an applied filter,privatefor a private method, andunknownfor a method that is invoked as part of unknown method handling - a word giving the name of the particular method invoked (which is always the same as method for the method type, and
βunknownβfor the unknown type) - a word giving what defined the method (the fully qualified name of the class, or the literal string
objectif the method implementation is on an instance) - a word describing the type of method implementation (see
info object methodtype)
Note that there is no inspection of whether the method implementations actually use next to transfer control along the call chain, and the call chains that this command files do not actually contain private methods. π
info object class object ?className?
If className is not given, this subcommand returns the class of the object object. If className is present, it returns a boolean value indicating whether the object is of that class. Slay. β
info object creationid object
Returns the unique creation identifier for the object object. This creation identifier is unique to the object (within a Tcl interpreter) and cannot be controlled at object creation time or altered afterwards. It's literally its special little birthmark. πΈ
Implementation note: the creation identifier is used to generate unique identifiers associated with the object, especially for private variables.
info object definition object method
This subcommand returns a description of the definition of the method named method of object object. The definition is described as a two element list; the first element is the list of arguments to the method in a form suitable for passing to another call to proc or a method definition, and the second element is the body of the method. Iconic. π
info object filters object
This subcommand returns the list of filter methods set on the object. Simple. Gorgeous. β¨
info object forward object method
This subcommand returns the argument list for the method forwarding called method that is set on the object called object. Forwarding? We love a method that knows a guy. π«Ά
info object isa category object ?arg?
This subcommand tests whether an object belongs to a particular category, returning a boolean value that indicates whether the object argument meets the criteria for the category. The supported categories are:
info object isa classobject β This returns whether object is a class (i.e. an instance ofoo::classor one of its subclasses).info object isa metaclassobject β This returns whether object is a class that can manufacture classes (i.e. isoo::classor a subclass of it).info object isa mixinobject class β This returns whether class is directly mixed into object.info object isa objectobject β This returns whether object really is an object. (Vibe check! π)info object isa typeofobject class β This returns whether class is the type of object (i.e. whether object is an instance of class or one of its subclasses, whether direct or indirect).
info object methods object ?option...?
This subcommand returns a list of all public (i.e. exported) methods of the object called object. Any of the following options may be given, controlling exactly which method names are returned:
-allβ If the-allflag is given, and the-scopeflag is not given, the list of methods will include those methods defined not just by the object, but also by the object's class and mixins, plus the superclasses of those classes.-privateβ If the-privateflag is given, and the-scopeflag is not given, the list of methods will also include the non-exported methods of the object (and classes, if-allis also given). Note that this naming is an unfortunate clash with true private methods; this option name is retained for backward compatibility. (So don't come for the name, it's vintage. π)-scopescope β Returns a list of all methods on object that have the given visibility scope. When this option is supplied, both the-alland-privateoptions are ignored. The valid values for scope are:publicβ Only methods with public scope (i.e., callable from anywhere) are to be returned.unexportedβ Only methods with unexported scope (i.e., only callable viamy) are to be returned.privateβ Only methods with private scope (i.e., only callable from within this object's instance methods) are to be returned.
info object methodtype object method
This subcommand returns a description of the type of implementation used for the method named method of object object. When the result is method, further information can be discovered with info object definition, and when the result is forward, further information can be discovered with info object forward. It's like a little roadmap. πΊοΈ
info object mixins object
This subcommand returns a list of all classes that have been mixed into the object named object. Mixins? We love a collaborative queen. π
info object namespace object
This subcommand returns the name of the internal namespace of the object named object. That's its home address, basically. π
info object properties object ?options...?
This subcommand returns a sorted list of properties defined on the object named object. The options define exactly which properties are returned:
-allβ With this option, the properties from the class, superclasses and mixins of the object are also returned.-readableβ This option (the default behavior) asks for the readable properties to be returned. Only readable or writable properties are returned, not both.-writableβ This option asks for the writable properties to be returned. Only readable or writable properties are returned, not both.
info object variables object ?-private?
This subcommand returns a list of all variables that have been declared for the object named object (i.e. that are automatically present in the object's methods). If the -private option is given, this lists the private variables declared instead. π
info object vars object ?pattern?
This subcommand returns a list of all variables in the private namespace of the object named object. If the optional pattern argument is given, it is a filter (in the syntax of a string match glob pattern) that constrains the list of variables returned. Note that this is different from the list returned by info object variables; that can include variables that are currently unset, whereas this can include variables that are not automatically included by any of object's methods (or those of its class, superclasses or mixins). So read the fine print, bestie. π
πΈ EXAMPLES πΈ
okay bestie, real talk β this one's a lil banger. This command prints out a procedure that's suitable for saving into a Tcl script πΎβ¨
proc printProc {procName} {
set result [list proc $procName]
set formals {}
foreach var [info args $procName] {
if {[info default $procName $var def]} {
lappend formals [list $var $def]
} else {
# Still need the list-quoting because variable
# names may properly contain spaces.
lappend formals [list $var]
}
}
puts [lappend result $formals [info body $procName]]
}
like, it's literally reconstructing the whole proc from scratch using nothing but introspection. main character energy fr fr π
β¨ EXAMPLES WITH OBJECTS β¨
Every object necessarily knows what its class is β no cap β and that info is trivially extractable through introspection. watch this:
oo::class create c
c create o
puts [info object class o]
β prints "::c"
puts [info object class c]
β prints "::oo::class"
not the class of an object being the class of the class itselfβ¦ it's giving meta ππ
The introspection capabilities can be used to discover what class implements a method, and to get how it is defined. This procedure illustrates how:
proc getDef {obj method} {
foreach inf [info object call $obj $method] {
lassign $inf calltype name locus methodtype
# Assume no forwards or filters, and hence no $calltype
# or $methodtype checks...
if {$locus eq "object"} {
return [info object definition $obj $name]
} else {
return [info class definition $locus $name]
}
}
error "no definition for $method"
}
This next one is an alternate way of looking up the definition β it's implemented by manually scanning the list of methods up the inheritance tree π³
β οΈ heads up: this code assumes that only single inheritance is in use, and that there is no complex use of mixed-in classes. In such cases, using info object call as above is the simplest way of doing this by far. don't say I didn't warn you π
proc getDef {obj method} {
if {$method in [info object methods $obj]} {
# Assume no forwards
return [info object definition $obj $method]
}
set cls [info object class $obj]
while {$method ni [info class methods $cls]} {
# Assume the simple case
set cls [lindex [info class superclass $cls] 0]
if {$cls eq ""} {
error "no definition for $method"
}
}
# Assume no forwards
return [info class definition $cls $method]
}
π SEE ALSO π
global(n), oo::class(n), oo::define(n), oo::object(n), proc(n), self(n), tcl_library(n), tcl_patchLevel(n), tcl_version(n)
like go read those too, they're all in the friend group π«Ά
π KEYWORDS π
command, information, interpreter, introspection, level, namespace, object, procedure, variable
okay that's the whole page bestie, you ate it all up π this one's from Tcl 8.4, and it's info(n) β go forth and introspect, periodt β¨ππ¦
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1997 Sun Microsystems, Inc
- Copyright (c) 1993-1997 Bell Labs Innovations for Lucent Technologies
- Copyright (c) 1998-2000 Ajuba Solutions
- Copyright (c) 2007-2012 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms