info(3tcl)
โจ NAME โจ
info(3tcl) โ Tcl Built-In Commands
info โ literally all the tea about the state of your Tcl interpreter ๐
๐ฆ SYNOPSIS ๐ฆ
info option ?arg arg ...?
๐ DESCRIPTION ๐
Okay so bestie, info is the main character of introspection โ it hands you the deets about what's going on inside the Tcl interpreter, no cap. Here's the whole menu of stuff you can ask it for:
info args procname
Returns the names of the parameters to the procedure named procname. Like, the whole lineup of arguments, right there. โจ
info body procname
Returns the body of the procedure named procname. The actual guts of it. ๐ซถ
info class subcommand class ?arg ...?
Returns information about the class named class. Peep CLASS INTROSPECTION down below for the full lore.
info cmdcount
Returns the total number of commands evaluated in this interpreter. Every. Single. One. ๐งฎ
info cmdtype commandName
Returns the type of the command named commandName. The built-in types are:
aliasโ commandName was created byinterp alias. โ ๏ธ Heads up: 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 to string match. But fr fr, only the last component of pattern is a pattern โ the other components identify a namespace. See NAMESPACE RESOLUTION in the namespace(3tcl) documentation for the details. ๐ธ
info complete command
Returns 1 if command is a complete command, and 0 otherwise. Typically used in line-oriented input environments so users can type in commands that span multiple lines. Lowkey essential. ๐
info constant varName
Returns 1 if varName is a constant variable (see const) and 0 otherwise.
info consts ?pattern?
Returns the list of constant variables (see const) in the current scope, or the list of constant variables matching pattern (if that is provided) in a manner similar to info 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. No coroutine, no name. Periodt. ๐
info default procname parameter varname
If the parameter parameter for the procedure named procname has a default value, this stores that value in varname and returns 1. Otherwise, it returns 0.
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 ngl 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. So while CALL and UP give you a trail of the call path, INNER serves up the details of the offending operation in the innermost procedure call, even down 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 just a convenient way of retrieving it for uncaught errors at top-level in an interactive interpreter.
info exists varName
Returns 1 if a variable named varName is visible and has been defined, and 0 otherwise.
info frame ?depth?
Returns the depth of the call to info frame itself. Otherwise, it returns a dictionary describing the active command at depth, which counts all commands visible to info level, plus commands that don't create a new level, such as eval, source, or uplevel. 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 to string 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 for string match.
info hostname
Returns the name of the current host. ๐
Bestie, listen: 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 than 0, 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. See uplevel for more information on levels.
info library
Returns the value of tcl_library, which is the name of the library directory in which the scripts distributed with Tcl scripts are stored. ๐
info loaded ?interp? ?prefix?โ tells you the name of every file that got loaded into interp by theloadcommand with prefix prefix. No prefix given? Then you get a list where each 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 the empty string, and for interp the empty string means the current interpreter. ๐info locals ?pattern?โ hand it a pattern and it returns the name of each local variable that matches pattern according tostring match. No pattern? Then it just returns the name of each local variable, periodt. Quick warning bestie: a variable defined withglobal,upvarorvariableis not local, so don't come for me when it doesn't show up. ๐info nameofexecutableโ returns the absolute pathname of the program for the current interpreter. And if such a file can't be identified? You get an empty string back. ๐ญinfo object subcommand object ?arg ...?โ returns information about the object named object. The subcommand is described down in OBJECT INTROSPECTION. โจinfo patchlevelโ returns the value of the global variabletcl_patchLevel, where the exact version of the Tcl library was initially stored. ๐info procs ?pattern?โ returns the names of all visible procedures. Give it a pattern and you only get the names that match according tostring match. Important: only the final component in pattern is actually treated as a pattern โ any qualifying components just select a namespace. Peep NAMESPACE RESOLUTION in thenamespace(3tcl)docs for the whole tea. ๐ซถinfo script ?filename?โ returns the pathname of the innermost script currently being evaluated, or the empty string if no pathname can be figured out. If filename is given, it sets the return value of any future calls toinfo scriptfor the duration of the innermost active script. Lowkey so useful in virtual file system applications. ๐ฆinfo sharedlibextensionโ returns the extension this platform uses for names of shared libraries, e.g..sounder Solaris. If shared libraries aren't supported on this platform, you get the empty string. ๐info tclversionโ returns the value of the global variabletcl_version, where the major and minor version of the Tcl library live. ๐ธinfo vars ?pattern?โ no pattern? Then you get the names of all visible variables. Got a pattern? Then you only get the names matching according tostring match. Only the last component of pattern is a pattern โ the other components identify a namespace. See NAMESPACE RESOLUTION in thenamespace(3tcl)documentation. And when pattern is a qualified name, results come back fully qualified, no cap. Also, a variable that's been declared but not yet given a value will be included in the results. ๐ง
๐ฎ CLASS INTROSPECTION ๐ฎ
These are the subcommand values that info class supports, bestie โ get comfy:
info class call class methodโ returns a description of the method implementations used to provide a stereotypical instance of class's implementation of method (stereotypical instances = objects instantiated by a class without any object-specific definitions added, iykyk). What you get is a list of lists of four elements, where 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 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
unknownfor 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 describing the general type of method implementation โ one of
Heads up: 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. Not me being dramatic, that's literally how it is. ๐
info class constructor classโ returns a description of the definition of the constructor of class class. It's 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? Empty list, bye. ๐info class definition class methodโ returns a description of the definition of the method named method of class class. Two element list again: first element is the list of arguments to the method in a form suitable for passing to another call toprocor a method definition, second element is the body of the method. โจinfo class definitionnamespace class ?kind?โ returns the definition namespace for kind definitions of the class class. Note that the definition namespace only affects the instances of class, not class itself. The kind can be either-class, to return the definition namespace used foroo::define, or-instance, to return the definition namespace used foroo::objdefine; the-classkind is the default (though this is only actually useful on classes that are subclasses ofoo::class).
If class doesn't 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 via the class inheritance hierarchy. ๐
info class destructor classโ returns the body of the destructor of class class. If there's no destructor present, you get 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's set on the class called class. ๐ฅinfo class instances class ?pattern?โ returns a list of instances of class class. If that optional pattern argument is there, it constrains the list of returned instances to the ones 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. You can pass any of these options to control 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, you can dig up more info withinfo class definition, and when the result isforward, you can dig up more info 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 come back:-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?โ drops a list of the direct subclasses of class. If you toss in the optional pattern, it narrows the returned classes down to only the ones that match it, following the rules ofstring match.info class superclasses classโ gives you the list of direct superclasses of class, listed in inheritance precedence order. no notes, just vibes ๐info class variables class ?-private?โ returns a list of every variable that's been declared for the class named class (aka the ones that are just automatically present in the class's methods, constructor and destructor ๐ซถ). If you pass the-privateoption, then instead you get the private variables that were declared. โจ
โจ OBJECT INTROSPECTION โจ
Here's the whole lineup of subcommand values that info object supports, bestie โ buckle up:
info object call object methodโ returns a description of the method implementations that are used to provide object's implementation of method. It's a list of lists, four elements each, and every 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 gets 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 (either the fully qualified name of the class, or the literal string
objectif the method implementation lives on an instance) - a word describing the type of method implementation (peep
info object methodtypefor that one)
- a word describing the general type of method implementation โ one of
Heads up: 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 isn't given, this returns the class of the object object. If className is there, you get back a boolean value telling you whether the object is of that class. simple as that ๐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. periodt.
Implementation note: the creation identifier is used to generate unique identifiers associated with the object, especially for private variables. ๐ง
info object definition object methodโ returns a description of the definition of the method named method of object object. The definition comes 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 toprocor a method definition, and the second element is the body of the method. iconic.info object filters objectโ returns the list of filter methods set on the object. ๐ธinfo object forward object methodโ returns the argument list for the method forwarding called method that is set on the object called object.info object isa category object ?arg?โ 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. Here are the supported categories:info object isa class objectโ returns whether object is a class (i.e. an instance ofoo::classor one of its subclasses).info object isa metaclass objectโ returns whether object is a class that can manufacture classes (i.e. isoo::classor a subclass of it). it's giving class-factory energy ๐info object isa mixin object classโ returns whether class is directly mixed into object.info object isa object objectโ returns whether object really is an object. vibe check fr frinfo object isa typeof object classโ 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...?โ returns a list of all public (i.e. exported) methods of the object called object. You can give any of these options, which control 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 object, but also by the object's class and mixins, plus the superclasses of those classes. the whole family tree basically ๐-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. ๐
-scope scopeโ 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โ returns a description of the type of implementation used for the method named method of object object. When the result ismethod, you can dig up more withinfo object definition, and when the result isforward, you can dig up more withinfo object forward. slay ๐ฅinfo object mixins objectโ returns a list of all classes that have been mixed into the object named object.info object namespace objectโ returns the name of the internal namespace of the object named object.info object properties object ?options...โ returns a sorted list of properties defined on the object named object. The options define exactly which properties come back:-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?โ 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-privateoption is given, this lists the private variables declared instead. ๐info object vars object ?pattern?โ returns a list of all variables in the private namespace of the object named object. If the optional pattern argument is given, it's a filter (in the syntax of astring matchglob pattern) that constrains the list of variables returned.
Note that this is different from the list returned by info object variables; that one can include variables that are currently unset, whereas this one can include variables that are not automatically included by any of object's methods (or those of its class, superclasses or mixins). ๐ญ
โจ EXAMPLES โจ
Okay bestie, this first one is so cute โ it prints out a whole procedure formatted so you can just save it straight into a Tcl script. Obsessed:
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]]
}
๐ฆ EXAMPLES WITH OBJECTS ๐ฆ
Every single object literally knows what its class is โ it's baked in. So pulling that info out is basically free, pure introspection vibes:
oo::class create c
c create o
puts [info object class o]
โ prints "::c"
puts [info object class c]
โ prints "::oo::class"
See how o is just a lil guy of class ::c, and c itself is an object of class ::oo::class? main character energy for real ๐
Now the glow-up: you can use introspection to figure out which class actually implements a method, and grab how it's defined. This procedure is giving detective ๐ต๏ธโ๏ธ:
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"
}
And here's the alternate route to the same definition โ this one manually walks the method list up the inheritance tree. Heads up though: this code assumes only single inheritance is happening, and that nobody's doing anything fancy with mixed-in classes. If that is happening, using info object call like above is by far the simplest way to do this, no cap:
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 ๐
Go read these next, they're all besties with this page ๐
global(3tcl)oo::class(3tcl)oo::define(3tcl)oo::object(3tcl)proc(3tcl)self(3tcl)tcl_library(3tcl)tcl_patchLevel(3tcl)tcl_version(3tcl)
๐ KEYWORDS ๐
The vibe check words for this page, fr fr:
command, information, interpreter, introspection, level, namespace, object, procedure, variable ๐ธ
And that's a wrap on the whole page, bestie! ๐ This one's from Tcl 8.4 and it's filed under info(3tcl) โ so if you ever forget where you read it, you know exactly where to look. Slay, go introspect something ๐
โจ๐ฆ
๐ฆ where this page comes from
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- 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