Version 2 of handle

Updated 2004-05-19 12:44:47 by lwv

Purpose: to discuss the concept of a handle.

Within Tcl, since everything is a string, sometimes things work a bit differently than expected.

For instance, Tcl variables can have various values.

  set a 123
 set b "xyz abc"
 set c [format "Nuts! There are %3.3d minutes until class" 3.1415]
 set d [open "/etc/motd" "r"]

It is this fourth example that is relevant in this page's discussion. The value from the open command is a string. That string is called a handle. It serves as a sort of indirect reference to a system resource which has been allocated. The puts command, as well as other Tcl commands, expect to deal with handles as one of their arguments. They use them as a black box value - something that you as a developer should not attempt to calculate, dynamically generate directly, etc. Instead, you let the software return these handles to you. Inside Tcl, there are functions which will make use of these handles in the appropriate manner.

[hopefully technical readers will add more details at this point]


Category tutorial