:TITLE: Information about procs - info ;# ;# RCSID: $Header: /cvsroot/tcl/tcltutorial/original/Tcl29.lsn,v 1.1 2004/11/04 16:01:14 davidw Exp $ ;# Copyright (c) 1995 Clif Flynt ;# 9300 Fleming Rd. ;# Dexter, MI 48130 ;# clif@cflynt.com ;# See file "NOTICE" for licensing terms. ;# :LESSON_TEXT_START_LEVEL 0: 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.

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.
:TEXT_END: :LESSON_TEXT_START_LEVEL 1: 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:

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.
:TEXT_END: :LESSON_TEXT_START_LEVEL 2: 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:

The example code shows these info subcommands being used to display the arguments, and body for a simple demo proc. After a list of the arguments is acquired, info default is used to test each argument for a default value, and report that value if it exists.

Note that the info body command does not return the outside braces.

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.
:TEXT_END: :CODE_START: proc demo {argument1 {default "DefaultValue"} } { puts "This is a demo proc. It is being called with $argument1 and $default" } puts "The args for demo are: [info args demo]\n" puts "The body for demo is: [info body demo]\n" set arglist [info args demo] foreach arg $arglist { if {[info default demo $arg defaultval]} { puts "$arg has a default value of $defaultval" } else { puts "$arg has no default" } } :TEXT_END: