As your code grows from 1 to 10 to 100 lines, you'll find that it's helpful to split it into a series of logical blocks, each of which can be run as a command. You'll learn how to define such procedures, how to pass information in and out of them, and how to access information that's held in your main program and in the calling procedure too.
This topic is presented on public course
Tcl Basics
Examples from our training material
| add2 | Answer to final exercise |
| addindemo | Sample code to complete - final exercise |
| cbn | Using upvar to call by name |
| doublit | Another upvar example for learners |
| gsc | The global scope |
| p1 | Sharing a variable using global |
| p2 | Sharing a variable using upvar |
| p3 | Sharing a variable using upvar and call by name - RECOMMENED |
| p4 | returning a variable - RECOMMENED for passing 1 piece of data back |
| p5 | Sharing a variable using uplevel - obscure |
| pr1 | Defining a proc (command) and using it |
| pr3 | loading a file of procs shared with other applications |
| scope1 | Variable default to being local |
| up1 | using upvar to effect a variable in the calling code |
| uquery | Shared file of procs |
| uv | Call by value and call by name |
| vardemo | Calling a proc with a variable number of arguments |
| whatandwhen | Exercise - please write the proc to complete |
| wwanswer | First sample answer - "getnumber" |
| wwbetter | Better sample answer - "getnumber" |
Opentalk forum discussions related to this topic
Passing arrays in and out of proceduresUsing variables defined inside the procedurePulling a list out of a proceedureProcedure with variable number of argumentsPassing lists into procedures
Pictures
Radia software is tailored through Tcl procedures
Teaching Tcl around the world
Background information
Some modules are
available for download as a sample of our material or under an
Open Training Notes License for free download from
http://www.training-notes.co.uk.
Topics covered in this module
Holding commonly used command sequences.
Why use procs?.
Sharing procedures with another application.
Variable parameters.
Variable scope.
The global scope.
The upvar command.
Another example of upvar.
Structured programming and OO.
Structured programming.
Programming with objects.
Use of Procs as an interface to Tcl.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our
Listing and schedule page.
Well House Consultants specialise in training courses in
Tcl/Tk, Expect,
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if
you live in a different
country or continent to us.
We have a technical library of over 600 books on the subjects on which we teach.
These books are available for reference at our training centre. Also
available is the Opentalk
Forum for discussion of technical questions.