Impressum
GoTo:
Home
 
Metaphern Akazien Verlag   
 
Lesezeichen [ Jobs # QR-Code # Anagramme ]Sa 21 Dez 2024 16:02:09


 huecker.com # Grundlagen der Programmierung | Tcl Tutorial.
--

 

. State of the interpreter - info .

[ Previous | Index | Next ]

There are a number of subcommands 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.

Commands that return information about the current state of the interpreter

info cmdcount
Returns the total number of commands that have been executed by this interpreter.
info level ?number?
Returns the stack level at which the compiler is currently evaluating code. 0 is the top level, 1 is a proc called from top, 2 is a proc called from a proc, etc. - If number number is a positive value, info level returns a the name and arguments of the proc at that level on the stack. Number is that same value that file level would return if it were called in the proc being referenced. If number number is a negative value, it refers to the current level plus number. Thus info level returns a the name and arguments of the proc at that level on the stack.
info patchlevel
Returns the value of the global variable tcl_patchlevel. This is the revision level of this interpreter.
info script
Returns the name of the file currently being evaluated, if one is being evaluated. If there is no file being evaluated, returns an empty string.
info tclversion
Returns the value of the global variable tcl_version. This is the patch level of this interpreter.
pid
Returns the pid of the current Tcl interpreter.

--

. Example .

   puts "This is how many commands 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 Pid 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 had been executed"
   puts "After calling the factorial proc, $count2 commands had been executed"
   puts "It took [expr $count2-$count1] commands to calculate this factorial"
  

--
[ Home | Top ]
[ . Previous | Index | Next . ]
Der Inhalt dieser Seite wurde am 31.08.2024 um 13.36 Uhr aktualisiert.
Navigation Seminare Magic Software Projekte Publikationen Kontakt Home
 
   huecker dot com * Germany | Datenschutz
© 1999, 2024 Franz-Josef Hücker. All Rights Reserved.
Contact Print Page LinkedIn follow me on twitter RSS Feeds & Podcasts