:TITLE: Information about procs - info
;#
;# RCSID: $Header: /home/cvs/TclTutor3/lesson/Tcl/Tcl29.lsn,v 1.1.1.1 2007/09/15 13:30:24 clif 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 <B>info</B> 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.
<P>
<CENTER><B> Info commands that return information about a proc</B></CENTER>
<DL>
<B><DT>info args</B> <I>procname</I>
<DD> Returns a list of the names of the arguments to the procedure <I>procname</I>.
<B><DT>info body</B> <I>procname</I>
<DD>Returns the body of the procedure <I>procname</I>.
<B><DT>info default</B> <I>procname arg varName</I>
<DD> Returns 1 if the argument <I>arg</I> in procedure <I>procName</I> has a 
default, and sets <I>varName</I> to the default.  Otherwise, returns 0.
</DL>
:TEXT_END:

:LESSON_TEXT_START_LEVEL 1:
The <B>info</B> 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.
<P>
These subcommands can be used to:
<UL COMPACT>
<LI> Access the contents of a proc in a debugger.
<LI> Generate custom procs from a template.
<LI> Report default values while prompting for input.
</UL>
<P>
<CENTER><B> Info commands that return information about a proc</B></CENTER>
<DL>
<B><DT>info args</B> <I>procname</I>
<DD> Returns a list of the names of the arguments to the procedure <I>procname</I>.
<B><DT>info body</B> <I>procname</I>
<DD>Returns the body of the procedure <I>procname</I>.
<B><DT>info default</B> <I>procname arg varName</I>
<DD> Returns 1 if the argument <I>arg</I> in procedure <I>procName</I> has a 
default, and sets <I>varName</I> to the default.  Otherwise, returns 0.
</DL>
:TEXT_END:

:LESSON_TEXT_START_LEVEL 2:
The <B>info</B> 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.
<P>
These subcommands can be used to:
<UL COMPACT>
<LI> Access the contents of a proc in a debugger.
<LI> Generate custom procs from a template.
<LI> Report default values while prompting for input.
</UL>
<P>
The example code shows these <B>info</B> subcommands being used to 
display the arguments, and body for a simple demo proc.  After a list of 
the arguments is acquired, <B>info default</B> is used to test each argument 
for a default value, and report that value if it exists.
<P>
Note that the <B>info body</B> command does not return the outside braces.
<P>
<CENTER><B> Info commands that return information about a proc</B></CENTER>
<DL>
<B><DT>info args</B> <I>procname</I>
<DD> Returns a list of the names of the arguments to the procedure <I>procname</I>.
<B><DT>info body</B> <I>procname</I>
<DD>Returns the body of the procedure <I>procname</I>.
<B><DT>info default</B> <I>procname arg varName</I>
<DD> Returns 1 if the argument <I>arg</I> in procedure <I>procName</I> has a 
default, and sets <I>varName</I> to the default.  Otherwise, returns 0.
</DL>
: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:

