There are a number of subcommands to the info command that provide information about the current state of the interpreter. These commands provide access to information like the current version and patchlevel, what script is currently being executed, how many commands have been executed, or how far down in the call tree the current proc is executing. The info tclversion and info patchlevel can be used to find out if the revision level of the interpreter running your code has the support for features you are using. If you know that certain features are not available in certain revisions of the interpreter, you can define your own procs to handle this, or just exit the program with an error message.
The info cmdcount and info level can be used while optimizing a Tcl script to find out how many levels and commands were necessary to accomplish a function.
Note that the pid command is not part of the info command, but a command in its own right.
(Note: There are several other subcommands that can be useful at times - see the man page on info)
puts "Number of commands that have been executed: [info cmdcount]" puts "Now THIS many commands have been executed: [info cmdcount]" puts "\nThis interpreter is revision level: [info tclversion]" puts "This interpreter is at patch level: [info patchlevel]" puts "The process id for this program is [pid]" proc factorial {val} { puts "Current level: [info level] - val: $val" set lvl [info level] if {$lvl == $val} { return $val } return [expr {($val-$lvl) * [factorial $val]}] } set count1 [info cmdcount] set fact [factorial 3] set count2 [info cmdcount] puts "The factorial of 3 is $fact" puts "Before calling the factorial proc, $count1 commands run" puts "After calling the factorial proc, $count2 commands run" puts "It took [expr $count2-$count1] commands for the factorial"
This is how many commands have been executed: 147 Now *THIS* many commands have been executed: 150 This interpreter is revision level: 8.6 This interpreter is at patch level: 8.6.6 The process id for this program is 10816 Current level: 1 - val: 3 Current level: 2 - val: 3 Current level: 3 - val: 3 The factorial of 3 is 6 Before calling the factorial proc, 162 commands run After calling the factorial proc, 189 commands run It took 27 commands for the factorial
The info script command is useful to construct the names of related script files:
# # Use [info script] to determine where the other files of interest # reside # set sysdir [file dirname [info script]] source [file join $sysdir "utils.tcl"]