Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact

Tips and short articles on this subject
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
Procedures and Variable Scope - Tcl/Tk module T207
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 procedures
Using variables defined inside the procedure
Pulling a list out of a proceedure
Procedure with variable number of arguments
Passing 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.


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