Version 3 of transparent

Updated 2004-05-20 12:10:37

NEM Transparent values in Tcl, are those which directly represent the value, as opposed to handle values which are more like pointers or references in other languages. Transparent values include things like lists, dicts (in 8.5) and strings. Transparent values are first-class in that they can be passed directly to commands, and returned from commands. Handles are first-class, but the things that they are handles for (what is being pointed to) are not first-class, as they can only be passed around via a handle. For instance, commands are a handle value - you pass around the name of the command, rather than the command itself (Tcl uses a hashtable or similar to map the name to the actual command internally). On the particular issue of commands, see TIPs 187, 194, and 196 which all try to introduce first-class transparent commands into Tcl.

Lars H: An advice to people who are new to Tcl is to try to do all data structures "transparent" in this sense. Tcl can do a lot more with transparent values than most other languages can, which means experience from other languages on how to implement things may be irrelevant for Tcl.

The main thing that can prevent something from being a transparent value is that it doesn't support the copy-on-modification semantics: that data isn't modified in place, but that rather a modified copy of the data is created. A typical example of something that doesn't have copy-on-modification semantics is a text document window; when you change a document by typing some additional text, you want the change to be in the same window, not have a new window created with the changed version of the document. Therefore windows are referenced using handles (the so-called "path name" of the window) in Tk. Similarly opened files (i.e., channels) have to be handles. Neither complexity nor size of data are good reasons for making values non-transparent, however.


[ Category Tutorial | Category Data Structure ]