Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

TCL - Information about procs - info


The info command includes a set of subcommands that will provide all the Info you could want about a proc. These subcommands will return the body of a proc, the arguments to the proc, and the value of any Default arguments.
These subcommands can be used to:
  • Access the contents of a proc in a debugger.
  • Generate custom procs from a template.
  • Report default values while prompting for input.
Info commands that return information about a proc
info args procname
Returns a list of the names of the arguments to the procedure procname.
info body procname
Returns the body of the procedure procname.
info default procname arg varName
Returns 1 if the argument arg in procedure procName has a default, and sets varName to the default. Otherwise, returns 0.

Example


proc Demo {argument1 {default "DefaultValue"} } {


puts "This is a demo proc. It is being called with $argument1 and $default"

#
# We can use [info level] to find out if a value was given for

nfo level [info level]]"
}

puts "The arg

# the optional argument "default" ...
#
puts "Actual call: [
is for demo are: [info args demo]\n"
puts "The body for demo is: [info body demo]\n"


faultval]} {
puts "$

set arglist [info args demo]

foreach arg $arglist {
if {[info default demo $arg d
earg has a default value of $defaultval"
} else {
puts "$arg has no default"
}


}


This post first appeared on VLSI WORLD, please read the originial post: here

Share the post

TCL - Information about procs - info

×

Subscribe to Vlsi World

Get updates delivered right to your inbox!

Thank you for your subscription

×