logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

info - Information about the state of the Tcl interpreter

Description

       Available commands:

       infoargsprocname
              Returns the names of the parameters to the procedure named procname.

       infobodyprocname
              Returns the body of the procedure named procname.

       infoclasssubcommandclass ?arg...
              Returns information about the class named class.  See CLASSINTROSPECTION below.

       infocmdcount
              Returns the total number of commands evaluated in this interpreter.

       infocmdtypecommandName
              Returns a the type of the command named commandName.  Built-in types are:                          2

              alias                                                                                              2
                     commandName was created by interpalias.  In a safe interpreter an alias is only visible if 2
                     both the alias and the target are visible.                                                  2

              coroutine                                                                                          2
                     commandName was created by coroutine.                                                       2

              ensemble                                                                                           2
                     commandName was created by namespaceensemble.                                              2

              import                                                                                             2
                     commandName was created by namespaceimport.                                                2

              native                                                                                             2
                     commandName  was  created  by  the  Tcl_CreateObjCommand interface directly without further 2
                     registration of the type of command.                                                        2

              object                                                                                             2
                     commandName is the public command that represents an instance of oo::object or one  of  its 2
                     subclasses.                                                                                 2

              privateObject                                                                                      2
                     commandName  is  the  private  command,  my  by  default,  that  represents  an instance of 2
                     oo::object or one of its subclasses.                                                        2

              proc                                                                                               2
                     commandName was created by proc.                                                            2

              interp                                                                                             2
                     commandName was created by interpcreate.                                                   2

              zlibStream                                                                                         2
                     commandName was created by zlibstream.                                                     2

       infocommands ?pattern?
              Returns the names of all commands visible in the current namespace.  If pattern is given,  returns
              only  those  names  that match according to stringmatch.  Only the last component of pattern is a
              pattern.  Other components identify a namespace.  See NAMESPACERESOLUTION in the  namespace(3tcl)
              documentation.

       infocompletecommand
              Returns  1  if  command  is  a complete command, and 0 otherwise.  Typically used in line-oriented
              input environments to allow users to type in commands that span multiple lines.

       infoconstantvarName
              Returns 1 if varName is a constant variable (see const) and 0 otherwise.                           2

       infoconsts ?pattern?
              Returns the list of constant variables (see const) in the current scope, or the list  of  constant 2
              variables matching pattern (if that is provided) in a manner similar to infovars.

       infocoroutine
              Returns the name of the current coroutine, or the empty string if there is no current coroutine or
              the current coroutine has been deleted.

       infodefaultprocnameparametervarname
              If the parameter parameter for the procedure named procname has a default value, stores that value
              in varname and returns 1.  Otherwise, returns 0.

       infoerrorstack ?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 infolevel0. 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; infoerrorstack is a convenient way of retrieving it for uncaught errors at top-
              level in an interactive interpreter.

       infoexistsvarName
              Returns 1 if a variable named varName is visible and has been defined, and 0 otherwise.

       infoframe ?depth?
              Returns  the  depth  of the call to infoframe itself.  Otherwise, returns a dictionary describing
              the active command at the depth, which counts all commands visible to infolevel,  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 infolevel and error traces, for nested commands like “foo [bar [x]]”, only “x” is seen by
              infoframe invoked within “x”.

              The dictionary may contain the following keys:

              type   Always present.  Possible values are source, proc, eval, and precompiled.

                     source A script loaded via the source command.

                     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 to eval or uplevel.

                     precompiled
                            A precompiled script (loadable by the package tbcload), and no  further  information
                            is available.

              line   The  line  number  of  of  the  command  inside  its script.  Not available for precompiled
                     commands.  When the type is source, 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 type source, provides the normalized path of the file that contains the command.

              cmd    The command before substitutions were performed.

              proc   For type proc, the name of the procedure containing the command.

              lambda For  a  command  in  a  script  evaluated  as  the body of an unnamed routine via the apply
                     command, 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)

       infofunctions ?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 stringmatch.

       infoglobals ?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 stringmatch.

       infohostname
              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.

       infolevel ?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.

       infolibrary
              Returns the value of tcl_library, which is the name of the library directory in which the  scripts
              distributed with Tcl scripts are stored.

       infoloaded ?interp? ?prefix?
              Returns the name of each file loaded in interp by the load command with prefix prefix .  If prefix
              is  not  given,  returns  a list where each item is the name of the loaded file and the prefix for
              which the file was loaded.  For a statically-loaded package the name of  the  file  is  the  empty
              string.  For interp, the empty string is the current interpreter.

       infolocals ?pattern?
              If  pattern is given, returns the name of each local variable matching pattern according to stringmatch.  Otherwise, returns the name of each local variable.  A variables defined with the  global,
              upvar or variable is not local.

       infonameofexecutable
              Returns  the absolute pathname of the program for the current interpreter.  If such a file can not
              be identified an empty string is returned.

       infoobjectsubcommandobject ?arg...
              Returns information about the object named object. subcommand is  described  OBJECTINTROSPECTION
              below.

       infopatchlevel
              Returns  the  value  of  the global variable tcl_patchLevel, in which the exact version of the Tcl
              library initially stored.

       infoprocs ?pattern?
              Returns the names of all visible procedures. If pattern is given, returns only  those  names  that
              match  according  to  stringmatch.  Only the final component in pattern is actually considered a
              pattern.  Any qualifying components simply select a namespace.  See NAMESPACERESOLUTION  in  the
              namespace(3tcl) documentation.

       infoscript ?filename?
              Returns  the pathname of the innermost script currently being evaluated, or the empty string if no
              pathname can be determined.  If filename is given, sets the return value of any  future  calls  to
              infoscript  for  the  duration  of  the innermost active script.  This is useful in virtual file
              system applications.

       infosharedlibextension
              Returns the extension used on this platform  for  names  of  shared  libraries,  e.g.   .so  under
              Solaris.  Returns the empty string if shared libraries are not supported on this platform.

       infotclversion
              Returns  the value of the global variable tcl_version, in which the major and minor version of the
              Tcl library are stored.

       infovars ?pattern?
              If pattern is not given, returns the names of all visible variables.  If pattern is given, returns
              only those names that match according to stringmatch.  Only the last component of  pattern  is  a
              pattern.   Other components identify a namespace.  See NAMESPACERESOLUTION in the namespace(3tcl)
              documentation.  When pattern is a qualified name, results are fully qualified.

              A variable that has been declared but not yet given a value will be included in the results.

   CLASSINTROSPECTION
       The following subcommand values are supported by infoclass:

       infoclasscallclassmethod
              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 consists of a list of lists
              of four elements, where each sublist consists of a word that describes the general type of  method
              implementation  (being one of method for an ordinary method, filter for an applied filter, private 2
              for a private method, and unknown for  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, and a word describing the type of method implementation
              (see infoclassmethodtype).

              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 2
              contain private methods.

       infoclassconstructorclass
              This  subcommand  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 to proc or a method definition, and the
              second  element  is  the  body  of the constructor. If no constructor is present, this returns the
              empty list.

       infoclassdefinitionclassmethod
              This subcommand returns a description of the definition of the method named method of class class.
              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.

       infoclassdefinitionnamespaceclass ?kind?
              This subcommand returns the definition namespace for kind definitions  of  the  class  class;  the 2
              definition namespace only affects the instances of class, not class itself. The kind can be either 2
              -class  to  return  the  definition  namespace  used  for  oo::define,  or -instance to return the 2
              definition namespace used for oo::objdefine; the -class kind  is  default  (though  this  is  only 2
              actually useful on classes that are subclasses of oo::class).                                      2

              If class does not provide a definition namespace of the given kind, this command returns the empty 2
              string. In those circumstances, the oo::define and oo::objdefine commands look up which definition 2
              namespace to use using the class inheritance hierarchy.                                            2

       infoclassdestructorclass
              This  subcommand  returns  the body of the destructor of class class. If no destructor is present,
              this returns the empty string.

       infoclassfiltersclass
              This subcommand returns the list of filter methods set on the class.

       infoclassforwardclassmethod
              This subcommand returns the argument list for the method forwarding called method that is  set  on
              the class called class.

       infoclassinstancesclass ?pattern?
              This  subcommand  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 of stringmatch.

       infoclassmethodsclass ?options...?
              This  subcommand  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 are returned:

              -all   If the -all flag is given, and the -scope flag is not  given,  the  list  of  methods  will 2
                     include  those  methods defined not just by the class, but also by the class's superclasses
                     and mixins.

              -private
                     If the -private flag is given, and the -scope flag is not given, the list of  methods  will 2
                     also include the non-exported methods of the class (and superclasses and mixins, if -all is
                     also given).  Note that this naming is an unfortunate clash with true private methods; this 2
                     option name is retained for backward compatibility.

              -scopescope
                     Returns  a  list  of  all methods on class that have the given visibility scope.  When this 2
                     option is supplied, both the -all and -private options are ignored. The  valid  values  for 2
                     scope are:                                                                                  2

                     public                                                                                      2
                        Only  methods  with  public  scope (i.e., callable from anywhere by any instance of this 2
                        class) are to be returned.                                                               2

                     unexported                                                                                  2
                        Only methods with unexported scope (i.e., only callable via my) are to be returned.      2

                     private                                                                                     2
                        Only methods with private scope (i.e., only callable from within this  class's  methods) 2
                        are to be returned.                                                                      2

       infoclassmethodtypeclassmethod
              This  subcommand  returns  a  description  of the type of implementation used for the method named
              method of class class. When the result is method, further information can be discovered with  infoclassdefinition, and when the result is forward, further information can be discovered with infoclassforward.

       infoclassmixinsclass
              This subcommand returns a list of all classes that have been mixed into the class named class.

       infoclasspropertiesclass ?options...
              This subcommand returns a sorted list of properties defined on the class named class. The  options 2
              define exactly which properties are returned:                                                      2

              -all                                                                                               2
                     With  this  option,  the  properties from the superclasses and mixins of the class are also 2
                     returned.                                                                                   2

              -readable                                                                                          2
                     This option (the default behavior) asks for the readable properties to  be  returned.  Only 2
                     readable or writable properties are returned, not both.                                     2

              -writable                                                                                          2
                     This  option  asks  for  the writable properties to be returned.  Only readable or writable 2
                     properties are returned, not both.                                                          2

       infoclasssubclassesclass ?pattern?
              This subcommand returns a list of direct subclasses  of  class  class.  If  the  optional  pattern
              argument  is  present, it constrains the list of returned classes to those that match it according
              to the rules of stringmatch.

       infoclasssuperclassesclass
              This subcommand returns a list of direct superclasses of class  class  in  inheritance  precedence
              order.

       infoclassvariablesclass ?-private?
              This  subcommand returns a list of all variables that have been declared for the class named class
              (i.e. that are automatically present in the class's methods, constructor and destructor).  If  the 2
              -private option is given, this lists the private variables declared instead.

   OBJECTINTROSPECTION
       The following subcommand values are supported by infoobject:

       infoobjectcallobjectmethod
              Returns   a  description  of  the  method  implementations  that  are  used  to  provide  object's
              implementation of method.  This consists of a list of lists of four elements, where  each  sublist
              consists  of  a word that describes the general type of method implementation (being one of method
              for an ordinary method, filter for an applied filter, private for a private  method,  and  unknown 2
              for  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 object if the method implementation is on an instance),  and  a  word
              describing the type of method implementation (see infoobjectmethodtype).

              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 2
              contain private methods.

       infoobjectclassobject ?className?
              If className is not given, this subcommand returns class of the object  object.  If  className  is
              present, this subcommand returns a boolean value indicating whether the object is of that class.

       infoobjectcreationidobject
              Returns  the  unique creation identifier for the object object. This creation identifier is unique 2
              to the object (within a Tcl interpreter) and cannot be  controlled  at  object  creation  time  or 2
              altered afterwards.                                                                                2

              Implementationnote:  the  creation  identifier is used to generate unique identifiers associated 2
              with the object, especially for private variables.                                                 2

       infoobjectdefinitionobjectmethod
              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.

       infoobjectfiltersobject
              This subcommand returns the list of filter methods set on the object.

       infoobjectforwardobjectmethod
              This  subcommand  returns the argument list for the method forwarding called method that is set on
              the object called object.

       infoobjectisacategoryobject ?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:

              infoobjectisaclassobject
                     This returns whether object is a class (i.e.  an  instance  of  oo::class  or  one  of  its
                     subclasses).

              infoobjectisametaclassobject
                     This returns whether object is a class that can manufacture classes (i.e. is oo::class or a
                     subclass of it).

              infoobjectisamixinobjectclass
                     This returns whether class is directly mixed into object.

              infoobjectisaobjectobject
                     This returns whether object really is an object.

              infoobjectisatypeofobjectclass
                     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).

       infoobjectmethodsobject ?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  -all  flag  is  given,  and the -scope flag is not given, the list of methods will 2
                     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  -private flag is given, and the -scope flag is not given, the list of methods will 2
                     also include the non-exported methods of the object (and classes, if -all is  also  given). 2
                     Note  that  this naming is an unfortunate clash with true private methods; this option name 2
                     is retained for backward compatibility.

              -scopescope
                     Returns a list of all methods on object that have the given visibility  scope.   When  this 2
                     option  is  supplied,  both the -all and -private options are ignored. The valid values for 2
                     scope are:                                                                                  2

                     public                                                                                      2
                        Only methods with public scope (i.e., callable from anywhere) are to be returned.        2

                     unexported                                                                                  2
                        Only methods with unexported scope (i.e., only callable via my) are to be returned.      2

                     private                                                                                     2
                        Only methods with private scope (i.e., only callable from within this object's  instance 2
                        methods) are to be returned.                                                             2

       infoobjectmethodtypeobjectmethod
              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
              infoobjectdefinition, and when the result is forward, further information can be discovered with
              infoobjectforward.

       infoobjectmixinsobject
              This subcommand returns a list of all classes that have been mixed into the object named object.

       infoobjectnamespaceobject
              This subcommand returns the name of the internal namespace of the object named object.

       infoobjectpropertiesobject ?options...
              This  subcommand  returns  a  sorted  list  of  properties defined on the object named object. The 2
              options define exactly which properties are returned:                                              2

              -all                                                                                               2
                     With this option, the properties from the class, superclasses and mixins of the object  are 2
                     also returned.                                                                              2

              -readable                                                                                          2
                     This  option  (the  default behavior) asks for the readable properties to be returned. Only 2
                     readable or writable properties are returned, not both.                                     2

              -writable                                                                                          2
                     This option asks for the writable properties to be  returned.  Only  readable  or  writable 2
                     properties are returned, not both.                                                          2

       infoobjectvariablesobject ?-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 2
              given, this lists the private variables declared instead.

       infoobjectvarsobject ?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 stringmatch
              glob pattern) that constrains the list of variables returned. Note that this is different from the
              list returned by infoobjectvariables; 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).

Examples

       This command prints out a procedure suitable for saving in a Tcl script:

              proc printProc {procName} {
                  set result [list proc $procName]
                  set formals {}
                  foreach var [infoargs $procName] {
                      if {[infodefault $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 [infobody $procName]]
              }

   EXAMPLESWITHOBJECTS
       Every object necessarily knows what its class is;  this  information  is  trivially  extractable  through
       introspection:

              oo::class create c
              c create o
              puts [infoobjectclass o]
                                   prints"::c"
              puts [infoobjectclass c]
                                   prints"::oo::class"

       The  introspection  capabilities can be used to discover what class implements a method and get how it is
       defined. This procedure illustrates how:

              proc getDef {obj method} {
                  foreach inf [infoobjectcall $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 [infoobjectdefinition $obj $name]
                      } else {
                          return [infoclassdefinition $locus $name]
                      }
                  }
                  error "no definition for $method"
              }

       This is an alternate way of looking up the definition; it is implemented by manually scanning the list of
       methods up the inheritance tree. 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 infoobjectcall as above is the simplest way
       of doing this by far):

              proc getDef {obj method} {
                  if {$method in [infoobjectmethods $obj]} {
                      # Assume no forwards
                      return [infoobjectdefinition $obj $method]
                  }

                  set cls [infoobjectclass $obj]

                  while {$method ni [infoclassmethods $cls]} {
                      # Assume the simple case
                      set cls [lindex [infoclasssuperclass $cls] 0]
                      if {$cls eq ""} {
                          error "no definition for $method"
                      }
                  }

                  # Assume no forwards
                  return [infoclassdefinition $cls $method]
              }

Keywords

       command, information, interpreter, introspection, level, namespace, object, procedure, variable

Tcl                                                    8.4                                            info(3tcl)

Name

       info - Information about the state of the Tcl interpreter

See Also

global(3tcl),    oo::class(3tcl),    oo::define(3tcl),    oo::object(3tcl),    proc(3tcl),    self(3tcl),
       tcl_library(3tcl), tcl_patchLevel(3tcl), tcl_version(3tcl)

Synopsis

infooption ?argarg...?
________________________________________________________________________________________________________________

See Also