Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact

Tips and short articles on this subject
Global and Enable - two misused words!
Tcl - uplevel to run code at calling level
Tcl - passing arrays and strings in and back out of procs
Calling procs in Tcl and how it compares to Perl
Tcl - global, upvar and uplevel.
A better alternative to cutting and pasting code
Do not duplicate your code
Functions and commands with dangerous names
Call by name v call by value
Passing arrays to procs in Tcl
Variable Scope
Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Tcl/Tk module T207
Procedures and Variable Scope
Exercises, examples and other material relating to training module T207. This topic is presented on public courses Learning to program in Tcl, Tcl Basics

Tcl Programming - The Tcl programming language, and Expect This course covers the fundamentals of the Tcl programming language. You'll learn about Tcl ...
http://www.wellho.net/course/tbfull.html  [course]
Learning to Program in Tcl - The Tcl programming language, and Expect This course covers the fundamentals of the Tcl programming language. You'll learn ...
http://www.wellho.net/course/tlfull.html  [course]
All the programming languages that we train on provide the facility for you to write a named block of code and the call it from elsewhere - such blocks ...
http://www.wellho.net/mouth/308_Call ... value.html  [short article]
In Tcl, variables are "scoped" to the procedure in which they're used. That's a sensible default, since you want to be able to write main applications ...
http://www.wellho.net/mouth/1404_Tcl ... evel-.html  [short article]
One of the vital topics on all our programming courses is that of variable scope. Variable Scope may be defined as the area of a program in which a variable ...
http://www.wellho.net/mouth/96_Variable-Scope.html  [short article]
When you want to pass data INTO a proc in Tcl from a regular variable, you write the variable name with a $ in front of it in the code and the value is ...
http://www.wellho.net/mouth/2466_Tcl ... procs.html  [short article]
If you're writing a Tcl proc, you'll normally pass in parameters by value, specifying a $ in front of the variable whos contents you want to pass in in ...
http://www.wellho.net/mouth/122_Pass ... n-Tcl.html  [short article]

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 courses Learning to program in Tcl, 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
dr2   Optional parameter in Tcl
dresser   Changing a value within a proc and returning the altered value
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"
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 700 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.


You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2010: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 344596 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho