| 2.1 The Form of a Tcl Script |
|
|
A Tcl script is basically this line repeated again and again with different commands and arguments command ARG1 ARG2 ... ARGnThe arguments are separated by white space, that is, blanks or tabs. For example, set X 2has two arguments. Not all white space separates arguments. Here are the exceptions.
Any given command may require a fixed number of arguments or may accept a variable number of arguments. The command line pattern shown above applies not just to simple commands but also to control structures. Examples:
Since the first word in a Tcl command line can be a procedure or a built-in command, I will use the words "command" and "procedure" almost interchangeably. Tcl is interpreted. The interpretor
Here is a weird example to make the point. X + 1This would be the invocation of a procedure named X with two arguments if it is on a line by itself. In other contexts, it might be either
More Observations about Command LinesSkip these on first reading if you like. It is possible to put multiple commands on one line of text if the commands are separated by semicolons. Because # only signals a comment if it appears in place of a command name, comments usually appear on lines by themselves. Because semicolons signal the beginning of a new command, you can put a comment at the end of a command line by using ;# as a prefix for it. Tcl works with lists a lot. Compared to a language like Lisp, the concept "list" in Tcl is somewhat murky but you will have a good idea of what is meant if you think of a command line as an example of a list. The first element of this list is the command name and subsequent elements are the arguments. When using Tcl interactively, if a command requires arguments, you can execute a command without any arguments to see a short explanation of how it should be used. For example, % set wrong # args: should be "set varName ?newValue?" Some commands are really families of actions where the action is determined by the first argument. (See below in Action Families.) If you invoke such a command with an inappropriate first argument, you will get a list of the possibilities. For example, % info ? bad option "?": should be args, body, cmdcount, commands, complete, default, exists, globals, level, library, locals, patchlevel, procs, script, tclversion, or vars % info tclversion 8.0 |
Author's Home Page |
|
Order from Amazon. |