Add a general purpose hashtable pattern matcher
[jimtcl.git] / jim_tcl.txt
blobb3100b811a041c78d25e57e7655029a6611d57b2
1 Jim Tcl(n)
2 ==========
4 NAME
5 ----
6 Jim Tcl v0.73 - overview of the Jim tool command language facilities
8 SYNOPSIS
9 --------
11   cc <source> -ljim
15   jimsh [<scriptfile>]
16   jimsh -e '<immediate-script>'
17   jimsh --version
20 .Quick Index
21 * <<CommandIndex,Command Reference>>
22 * <<OperatorPrecedence,Operator Precedence>>
23 * <<BuiltinVariables, Builtin Variables>>
24 * <<BackslashSequences, Backslash Sequences>>
26 INTRODUCTION
27 ------------
28 Jim is a reimplementation of Tcl, combining some features from
29 earlier, smaller versions of Tcl (6.x) as well as more modern
30 features from later versions of Tcl (7.x, 8.x). It also has some some
31 entirely new features not available in any version of Tcl.
33 This version is about double the size of "tinytcl" (6.8), depending upon
34 the features selected, but is significantly faster and has many new features.
36 Note that most of this man page is the original 6.8 Tcl man page, with
37 changes made for differences with Jim.
39 The major differences with Tcl 8.5/8.6 are:
41 1. Object-based I/O (aio), but with a Tcl-compatibility layer
42 2. I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
43 3. Integers are 64bit
44 4. Support for references (`ref`/`getref`/`setref`) and garbage collection
45 5. Builtin dictionary type (`dict`) with some limitations compared to Tcl 8.6
46 6. `env` command to access environment variables
47 7. `os.fork`, `os.wait`, `os.uptime`, `rand`
48 8. Much better error reporting. `info stacktrace` as a replacement for '$errorInfo', '$errorCode'
49 9. Support for "static" variables in procedures
50 10. Namespaces, threads and coroutines are not support
51 11. Command and variable traces are not supported
52 12. Direct command line editing rather than the `history` command
53 13. Expression shorthand syntax: +$(...)+
55 RECENT CHANGES
56 --------------
58 Changes between 0.72 and 0.73
59 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60 1. Built-in regexp now support non-capturing parentheses: (?:...)
62 Changes between 0.71 and 0.72
63 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64 1. procs now allow 'args' and optional parameters in any position
65 2. Add Tcl-compatible expr functions, `rand()`, `srand()` and `pow()`
66 3. Add support for the '-force' option to `file delete`
67 4. Better diagnostics when `source` fails to load a script with a missing quote or bracket
68 5. New +tcl_platform(pathSeparator)+
69 6. Add support settings the modification time with `file mtime`
70 7. `exec` is now fully supported on win32 (mingw32)
71 8. `file join`, `pwd`, `glob` etc. now work for mingw32
72 9. Line editing is now supported for the win32 console (mingw32)
73 10. Add `aio listen` command
75 Changes between 0.70 and 0.71
76 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77 1. Allow 'args' to be renamed in procs
78 2. Add +$(...)+ shorthand syntax for expressions
79 3. Add automatic reference variables in procs with +&var+ syntax
80 4. Support +jimsh --version+
81 5. Additional variables in +tcl_platform()+
82 6. `local` procs now push existing commands and `upcall` can call them
83 7. Add `loop` command (TclX compatible)
84 8. Add `aio buffering` command
85 9. `info complete` can now return the missing character
86 10. `binary format` and `binary scan` are now (optionally) supported
87 11. Add `string byterange`
88 12. Built-in regexp now support non-greedy repetition (*?, +?, ??)
90 Changes between 0.63 and 0.70
91 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92 1. +platform_tcl()+ settings are now automatically determined
93 2. Add aio `$handle filename`
94 3. Add `info channels`
95 4. The 'bio' extension is gone. Now `aio` supports 'copyto'.
96 5. Add `exists` command
97 6. Add the pure-Tcl 'oo' extension
98 7. The `exec` command now only uses vfork(), not fork()
99 8. Unit test framework is less verbose and more Tcl-compatible
100 9. Optional UTF-8 support
101 10. Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
102 11. Command line editing in interactive mode, e.g. 'jimsh'
104 TCL INTRODUCTION
105 -----------------
106 Tcl stands for 'tool command language' and is pronounced 'tickle.'
107 It is actually two things: a language and a library.
109 First, Tcl is a simple textual language, intended primarily for
110 issuing commands to interactive programs such as text editors,
111 debuggers, illustrators, and shells.  It has a simple syntax and is also
112 programmable, so Tcl users can write command procedures to provide more
113 powerful commands than those in the built-in set.
115 Second, Tcl is a library package that can be embedded in application
116 programs.  The Tcl library consists of a parser for the Tcl language,
117 routines to implement the Tcl built-in commands, and procedures that
118 allow each application to extend Tcl with additional commands specific
119 to that application.  The application program generates Tcl commands and
120 passes them to the Tcl parser for execution.  Commands may be generated
121 by reading characters from an input source, or by associating command
122 strings with elements of the application's user interface, such as menu
123 entries, buttons, or keystrokes.
125 When the Tcl library receives commands it parses them into component
126 fields and executes built-in commands directly.  For commands implemented
127 by the application, Tcl calls back to the application to execute the
128 commands.  In many cases commands will invoke recursive invocations of the
129 Tcl interpreter by passing in additional strings to execute (procedures,
130 looping commands, and conditional commands all work in this way).
132 An application program gains three advantages by using Tcl for its command
133 language.  First, Tcl provides a standard syntax:  once users know Tcl,
134 they will be able to issue commands easily to any Tcl-based application.
135 Second, Tcl provides programmability.  All a Tcl application needs
136 to do is to implement a few application-specific low-level commands.
137 Tcl provides many utility commands plus a general programming interface
138 for building up complex command procedures.  By using Tcl, applications
139 need not re-implement these features.
141 Third, Tcl can be used as a common language for communicating between
142 applications.  Inter-application communication is not built into the
143 Tcl core described here, but various add-on libraries, such as the Tk
144 toolkit, allow applications to issue commands to each other.  This makes
145 it possible for applications to work together in much more powerful ways
146 than was previously possible.
148 Fourth, Jim Tcl includes a command processor, +jimsh+, which can be
149 used to run standalone Tcl scripts, or to run Tcl commands interactively.
151 This manual page focuses primarily on the Tcl language.  It describes
152 the language syntax and the built-in commands that will be available
153 in any application based on Tcl.  The individual library procedures are
154 described in more detail in separate manual pages, one per procedure.
156 JIMSH COMMAND INTERPRETER
157 -------------------------
158 A simple, but powerful command processor, +jimsh+, is part of Jim Tcl.
159 It may be invoked in interactive mode as:
161   jimsh
163 or to process the Tcl script in a file with:
165   jimsh filename
167 It may also be invoked to execute an immediate script with:
169   jimsh -e "script"
171 Interactive Mode
172 ~~~~~~~~~~~~~~~~
173 Interactive mode reads Tcl commands from standard input, evaluates
174 those commands and prints the results.
176   $ jimsh
177   Welcome to Jim version 0.71, Copyright (c) 2005-8 Salvatore Sanfilippo
178   . info version
179   0.71
180   . lsort [info commands p*]
181   package parray pid popen proc puts pwd
182   . foreach i {a b c} {
183   {> puts $i
184   {> }
185   a
186   b
187   c
188   . bad
189   invalid command name "bad"
190   [error] . exit
191   $
193 If +jimsh+ is configured with line editing (it is by default) and a VT-100-compatible
194 terminal is detected, Emacs-style line editing commands are available, including:
195 arrow keys, +\^W+ to erase a word, +\^U+ to erase the line, +^R+ for reverse incremental search
196 in history. Additionally, the +h+ command may be used to display the command history.
198 Command line history is automatically saved and loaded from +~/.jim_history+
200 In interactive mode, +jimsh+ automatically runs the script +~/.jimrc+ at startup
201 if it exists.
203 INTERPRETERS
204 ------------
205 The central data structure in Tcl is an interpreter (C type 'Jim_Interp').
206 An interpreter consists of a set of command bindings, a set of variable
207 values, and a few other miscellaneous pieces of state.  Each Tcl command
208 is interpreted in the context of a particular interpreter.
210 Some Tcl-based applications will maintain multiple interpreters
211 simultaneously, each associated with a different widget or portion of
212 the application.  Interpreters are relatively lightweight structures.
213 They can be created and deleted quickly, so application programmers should
214 feel free to use multiple interpreters if that simplifies the application.
216 DATA TYPES
217 ----------
218 Tcl supports only one type of data:  strings.  All commands, all arguments
219 to commands, all command results, and all variable values are strings.
221 Where commands require numeric arguments or return numeric results,
222 the arguments and results are passed as strings.  Many commands expect
223 their string arguments to have certain formats, but this interpretation
224 is up to the individual commands.  For example, arguments often contain
225 Tcl command strings, which may get executed as part of the commands.
226 The easiest way to understand the Tcl interpreter is to remember that
227 everything is just an operation on a string.  In many cases Tcl constructs
228 will look similar to more structured constructs from other languages.
229 However, the Tcl constructs are not structured at all; they are just
230 strings of characters, and this gives them a different behaviour than
231 the structures they may look like.
233 Although the exact interpretation of a Tcl string depends on who is doing
234 the interpretation, there are three common forms that strings take:
235 commands, expressions, and lists.  The major sections below discuss
236 these three forms in more detail.
238 BASIC COMMAND SYNTAX
239 --------------------
240 The Tcl language has syntactic similarities to both the Unix shells
241 and Lisp.  However, the interpretation of commands is different
242 in Tcl than in either of those other two systems.
243 A Tcl command string consists of one or more commands separated
244 by newline characters or semi-colons.
245 Each command consists of a collection of fields separated by
246 white space (spaces or tabs).
247 The first field must be the name of a command, and the
248 additional fields, if any, are arguments that will be passed to
249 that command.  For example, the command:
251     set a 22
253 has three fields:  the first, `set`, is the name of a Tcl command, and
254 the last two, 'a' and '22', will be passed as arguments to
255 the `set` command.  The command name may refer either to a built-in
256 Tcl command, an application-specific command bound in with the library
257 procedure 'Jim_CreateCommand', or a command procedure defined with the
258 `proc` built-in command.
260 Arguments are passed literally as text strings.  Individual commands may
261 interpret those strings in any fashion they wish.  The `set` command,
262 for example, will treat its first argument as the name of a variable
263 and its second argument as a string value to assign to that variable.
264 For other commands arguments may be interpreted as integers, lists,
265 file names, or Tcl commands.
267 Command names should normally be typed completely (e.g. no abbreviations).
268 However, if the Tcl interpreter cannot locate a command it invokes a
269 special command named `unknown` which attempts to find or create the
270 command.
272 For example, at many sites `unknown` will search through library
273 directories for the desired command and create it as a Tcl procedure if
274 it is found.  The `unknown` command often provides automatic completion
275 of abbreviated commands, but usually only for commands that were typed
276 interactively.
278 It's probably a bad idea to use abbreviations in command scripts and
279 other forms that will be re-used over time:  changes to the command set
280 may cause abbreviations to become ambiguous, resulting in scripts that
281 no longer work.
283 COMMENTS
284 --------
285 If the first non-blank character in a command is +\#+, then everything
286 from the +#+ up through the next newline character is treated as
287 a comment and ignored.  When comments are embedded inside nested
288 commands (e.g. fields enclosed in braces) they must have properly-matched
289 braces (this is necessary because when Tcl parses the top-level command
290 it doesn't yet know that the nested field will be used as a command so
291 it cannot process the nested comment character as a comment).
293 GROUPING ARGUMENTS WITH DOUBLE-QUOTES
294 -------------------------------------
295 Normally each argument field ends at the next white space, but
296 double-quotes may be used to create arguments with embedded space.
298 If an argument field begins with a double-quote, then the argument isn't
299 terminated by white space (including newlines) or a semi-colon (see below
300 for information on semi-colons); instead it ends at the next double-quote
301 character.  The double-quotes are not included in the resulting argument.
302 For example, the command
304     set a "This is a single argument"
306 will pass two arguments to `set`:  'a' and 'This is a single argument'.
308 Within double-quotes, command substitutions, variable substitutions,
309 and backslash substitutions still occur, as described below.  If the
310 first character of a command field is not a quote, then quotes receive
311 no special interpretation in the parsing of that field.
313 GROUPING ARGUMENTS WITH BRACES
314 ------------------------------
315 Curly braces may also be used for grouping arguments.  They are similar
316 to quotes except for two differences.  First, they nest; this makes them
317 easier to use for complicated arguments like nested Tcl command strings.
318 Second, the substitutions described below for commands, variables, and
319 backslashes do *not* occur in arguments enclosed in braces, so braces
320 can be used to prevent substitutions where they are undesirable.
322 If an argument field begins with a left brace, then the argument ends
323 at the matching right brace.  Tcl will strip off the outermost layer
324 of braces and pass the information between the braces to the command
325 without any further modification.  For example, in the command
327     set a {xyz a {b c d}}
329 the `set` command will receive two arguments: 'a'
330 and 'xyz a {b c d}'.
332 When braces or quotes are in effect, the matching brace or quote need
333 not be on the same line as the starting quote or brace; in this case
334 the newline will be included in the argument field along with any other
335 characters up to the matching brace or quote.  For example, the `eval`
336 command takes one argument, which is a command string; `eval` invokes
337 the Tcl interpreter to execute the command string.  The command
339     eval {
340       set a 22
341       set b 33
342     }
344 will assign the value '22' to 'a' and '33' to 'b'.
346 If the first character of a command field is not a left
347 brace, then neither left nor right
348 braces in the field will be treated specially (except as part of
349 variable substitution; see below).
351 COMMAND SUBSTITUTION WITH BRACKETS
352 ----------------------------------
353 If an open bracket occurs in a field of a command, then command
354 substitution occurs (except for fields enclosed in braces).  All of the
355 text up to the matching close bracket is treated as a Tcl command and
356 executed immediately.  Then the result of that command is substituted
357 for the bracketed text.  For example, consider the command
359     set a [set b]
361 When the `set` command has only a single argument, it is the name of a
362 variable and `set` returns the contents of that variable.  In this case,
363 if variable 'b' has the value 'foo', then the command above is equivalent
364 to the command
366     set a foo
368 Brackets can be used in more complex ways.  For example, if the variable
369 'b' has the value 'foo' and the variable 'c' has the value 'gorp',
370 then the command
372     set a xyz[set b].[set c]
374 is equivalent to the command
376     set a xyzfoo.gorp
379 A bracketed command may contain multiple commands separated by newlines
380 or semi-colons in the usual fashion.  In this case the value of the last
381 command is used for substitution.  For example, the command
383     set a x[set b 22
384     expr $b+2]x
386 is equivalent to the command
388     set a x24x
391 If a field is enclosed in braces then the brackets and the characters
392 between them are not interpreted specially; they are passed through to
393 the argument verbatim.
395 VARIABLE SUBSTITUTION WITH $
396 ----------------------------
397 The dollar sign (+$+) may be used as a special shorthand form for
398 substituting variable values.  If +$+ appears in an argument that isn't
399 enclosed in braces then variable substitution will occur.  The characters
400 after the +$+, up to the first character that isn't a number, letter,
401 or underscore, are taken as a variable name and the string value of that
402 variable is substituted for the name.
404 For example, if variable 'foo' has the value 'test', then the command
406     set a $foo.c
408 is equivalent to the command
410     set a test.c
412 There are two special forms for variable substitution.  If the next
413 character after the name of the variable is an open parenthesis, then
414 the variable is assumed to be an array name, and all of the characters
415 between the open parenthesis and the next close parenthesis are taken as
416 an index into the array.  Command substitutions and variable substitutions
417 are performed on the information between the parentheses before it is
418 used as an index.
420 For example, if the variable 'x' is an array with one element named
421 'first' and value '87' and another element named '14' and value 'more',
422 then the command
424     set a xyz$x(first)zyx
426 is equivalent to the command
428     set a xyz87zyx
430 If the variable 'index' has the value '14', then the command
432     set a xyz$x($index)zyx
434 is equivalent to the command
436     set a xyzmorezyx
438 For more information on arrays, see VARIABLES AND ARRAYS below.
440 The second special form for variables occurs when the dollar sign is
441 followed by an open curly brace.  In this case the variable name consists
442 of all the characters up to the next curly brace.
444 Array references are not possible in this form:  the name between braces
445 is assumed to refer to a scalar variable.  For example, if variable
446 'foo' has the value 'test', then the command
448     set a abc${foo}bar
450 is equivalent to the command
452     set a abctestbar
455 Variable substitution does not occur in arguments that are enclosed in
456 braces:  the dollar sign and variable name are passed through to the
457 argument verbatim.
459 The dollar sign abbreviation is simply a shorthand form.  +$a+ is
460 completely equivalent to +[set a]+; it is provided as a convenience
461 to reduce typing.
463 SEPARATING COMMANDS WITH SEMI-COLONS
464 ------------------------------------
465 Normally, each command occupies one line (the command is terminated by a
466 newline character).  However, semi-colon (+;+) is treated as a command
467 separator character; multiple commands may be placed on one line by
468 separating them with a semi-colon.  Semi-colons are not treated as
469 command separators if they appear within curly braces or double-quotes.
471 BACKSLASH SUBSTITUTION
472 ----------------------
473 Backslashes may be used to insert non-printing characters into command
474 fields and also to insert special characters like braces and brackets
475 into fields without them being interpreted specially as described above.
477 The backslash sequences understood by the Tcl interpreter are
478 listed below.  In each case, the backslash
479 sequence is replaced by the given character:
480 [[BackslashSequences]]
481 +{backslash}b+::
482     Backspace (0x8)
484 +{backslash}f+::
485     Form feed (0xc)
487 +{backslash}n+::
488     Newline (0xa)
490 +{backslash}r+::
491     Carriage-return (0xd).
493 +{backslash}t+::
494     Tab (0x9).
496 +{backslash}v+::
497     Vertical tab (0xb).
499 +{backslash}{+::
500     Left brace ({).
502 +{backslash}}+::
503     Right brace (}).
505 +{backslash}[+::
506     Open bracket ([).
508 +{backslash}]+::
509     Close bracket (]).
511 +{backslash}$+::
512     Dollar sign ($).
514 +{backslash}<space>+::
515     Space ( ): doesn't terminate argument.
517 +{backslash};+::
518     Semi-colon: doesn't terminate command.
520 +{backslash}"+::
521     Double-quote.
523 +{backslash}<newline>+::
524     Nothing:  this joins two lines together
525     into a single line.  This backslash feature is unique in that
526     it will be applied even when the sequence occurs within braces.
528 +{backslash}{backslash}+::
529     Backslash ('{backslash}').
531 +{backslash}'ddd'+::
532     The digits +'ddd'+ (one, two, or three of them) give the octal value of
533     the character.  Note that Jim supports null characters in strings.
535 +{backslash}'unnnn'+::
536     The hex digits +'nnnn'+ (between one and four of them) give a unicode codepoint.
537     The UTF-8 encoding of the codepoint is inserted.
539 For example, in the command
541     set a \{x\[\ yz\141
543 the second argument to `set` will be +{x[ yza+.
545 If a backslash is followed by something other than one of the options
546 described above, then the backslash is transmitted to the argument
547 field without any special processing, and the Tcl scanner continues
548 normal processing with the next character.  For example, in the
549 command
551     set \*a \\\{foo
553 The first argument to `set` will be +{backslash}*a+ and the second
554 argument will be +{backslash}{foo+.
556 If an argument is enclosed in braces, then backslash sequences inside
557 the argument are parsed but no substitution occurs (except for
558 backslash-newline):  the backslash
559 sequence is passed through to the argument as is, without making
560 any special interpretation of the characters in the backslash sequence.
561 In particular, backslashed braces are not counted in locating the
562 matching right brace that terminates the argument.
563 For example, in the
564 command
566     set a {\{abc}
568 the second argument to `set` will be +{backslash}{abc+.
570 This backslash mechanism is not sufficient to generate absolutely
571 any argument structure; it only covers the
572 most common cases.  To produce particularly complicated arguments
573 it is probably easiest to use the `format` command along with
574 command substitution.
576 STRING AND LIST INDEX SPECIFICATIONS
577 ------------------------------------
579 Many string and list commands take one or more 'index' parameters which
580 specify a position in the string relative to the start or end of the string/list.
582 The index may be one of the following forms:
584 +integer+::
585     A simple integer, where '0' refers to the first element of the string
586     or list.
588 +integer+integer+ or::
589 +integer-integer+::
590     The sum or difference of the two integers. e.g. +2+3+ refers to the 5th element.
591     This is useful when used with (e.g.) +$i+1+ rather than the more verbose
592     +[expr {$i+1\}]+
594 +end+::
595     The last element of the string or list.
597 +end-integer+::
598     The 'nth-from-last' element of the string or list.
600 COMMAND SUMMARY
601 ---------------
602 1. A command is just a string.
603 2. Within a string commands are separated by newlines or semi-colons
604    (unless the newline or semi-colon is within braces or brackets
605    or is backslashed).
606 3. A command consists of fields.  The first field is the name of the command.
607    The other fields are strings that are passed to that command as arguments.
608 4. Fields are normally separated by white space.
609 5. Double-quotes allow white space and semi-colons to appear within
610    a single argument.
611    Command substitution, variable substitution, and backslash substitution
612    still occur inside quotes.
613 6. Braces defer interpretation of special characters.
614    If a field begins with a left brace, then it consists of everything
615    between the left brace and the matching right brace. The
616    braces themselves are not included in the argument.
617    No further processing is done on the information between the braces
618    except that backslash-newline sequences are eliminated.
619 7. If a field doesn't begin with a brace then backslash,
620    variable, and command substitution are done on the field.  Only a
621    single level of processing is done:  the results of one substitution
622    are not scanned again for further substitutions or any other
623    special treatment.  Substitution can
624    occur on any field of a command, including the command name
625    as well as the arguments.
626 8. If the first non-blank character of a command is a +\#+, everything
627    from the +#+ up through the next newline is treated as a comment
628    and ignored.
630 EXPRESSIONS
631 -----------
632 The second major interpretation applied to strings in Tcl is
633 as expressions.  Several commands, such as `expr`, `for`,
634 and `if`, treat one or more of their arguments as expressions
635 and call the Tcl expression processors ('Jim_ExprLong',
636 'Jim_ExprBoolean', etc.) to evaluate them.
638 The operators permitted in Tcl expressions are a subset of
639 the operators permitted in C expressions, and they have the
640 same meaning and precedence as the corresponding C operators.
641 Expressions almost always yield numeric results
642 (integer or floating-point values).
643 For example, the expression
645     8.2 + 6
647 evaluates to 14.2.
649 Tcl expressions differ from C expressions in the way that
650 operands are specified, and in that Tcl expressions support
651 non-numeric operands and string comparisons.
653 A Tcl expression consists of a combination of operands, operators,
654 and parentheses.
656 White space may be used between the operands and operators and
657 parentheses; it is ignored by the expression processor.
658 Where possible, operands are interpreted as integer values.
660 Integer values may be specified in decimal (the normal case), in octal (if the
661 first character of the operand is '0'), or in hexadecimal (if the first
662 two characters of the operand are '0x').
664 If an operand does not have one of the integer formats given
665 above, then it is treated as a floating-point number if that is
666 possible.  Floating-point numbers may be specified in any of the
667 ways accepted by an ANSI-compliant C compiler (except that the
668 'f', 'F', 'l', and 'L' suffixes will not be permitted in
669 most installations).  For example, all of the
670 following are valid floating-point numbers:  2.1, 3., 6e4, 7.91e+16.
672 If no numeric interpretation is possible, then an operand is left
673 as a string (and only a limited set of operators may be applied to
674 it).
676 1. Operands may be specified in any of the following ways:
678 2. As a numeric value, either integer or floating-point.
680 3. As a Tcl variable, using standard '$' notation.
681 The variable's value will be used as the operand.
683 4. As a string enclosed in double-quotes.
684 The expression parser will perform backslash, variable, and
685 command substitutions on the information between the quotes,
686 and use the resulting value as the operand
688 5. As a string enclosed in braces.
689 The characters between the open brace and matching close brace
690 will be used as the operand without any substitutions.
692 6. As a Tcl command enclosed in brackets.
693 The command will be executed and its result will be used as
694 the operand.
696 Where substitutions occur above (e.g. inside quoted strings), they
697 are performed by the expression processor.
698 However, an additional layer of substitution may already have
699 been performed by the command parser before the expression
700 processor was called.
702 As discussed below, it is usually best to enclose expressions
703 in braces to prevent the command parser from performing substitutions
704 on the contents.
706 For some examples of simple expressions, suppose the variable 'a' has
707 the value 3 and the variable 'b' has the value 6.  Then the expression
708 on the left side of each of the lines below will evaluate to the value
709 on the right side of the line:
711     $a + 3.1                6.1
712     2 + "$a.$b"             5.6
713     4*[llength "6 2"]       8
714     {word one} < "word $a"  0
716 The valid operators are listed below, grouped in decreasing order
717 of precedence:
718 [[OperatorPrecedence]]
719 +int() double() round() abs(), rand(), srand()+::
720     Unary functions (except rand() which takes no arguments)
721     * +'int()'+ converts the numeric argument to an integer by truncating down.
722     * +'double()'+ converts the numeric argument to floating point.
723     * +'round()'+ converts the numeric argument to the closest integer value.
724     * +'abs()'+ takes the absolute value of the numeric argument.
725     * +'rand()'+ takes the absolute value of the numeric argument.
726     * +'rand()'+ returns a pseudo-random floating-point value in the range (0,1).
727     * +'srand()'+ takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
729 +sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()+::
730     Unary math functions.
731     If Jim is compiled with math support, these functions are available.
733 +- + ~ !+::
734     Unary minus, unary plus, bit-wise NOT, logical NOT.  None of these operands
735     may be applied to string operands, and bit-wise NOT may be
736     applied only to integers.
738 +** pow(x,y)+::
739     Power. e.g. 'x^y^'. If Jim is compiled with math support, supports doubles and
740     integers. Otherwise supports integers only. (Note that the math-function form
741     has the same highest precedence)
743 +* / %+::
744     Multiply, divide, remainder.  None of these operands may be
745     applied to string operands, and remainder may be applied only
746     to integers.
748 ++ -+::
749     Add and subtract.  Valid for any numeric operands.
751 +<<  >> <<< >>>+::
752     Left and right shift, left and right rotate.  Valid for integer operands only.
754 +<  >  \<=  >=+::
755     Boolean less, greater, less than or equal, and greater than or equal.
756     Each operator produces 1 if the condition is true, 0 otherwise.
757     These operators may be applied to strings as well as numeric operands,
758     in which case string comparison is used.
760 +==  !=+::
761     Boolean equal and not equal.  Each operator produces a zero/one result.
762     Valid for all operand types. *Note* that values will be converted to integers
763     if possible, then floating point types, and finally strings will be compared.
764     It is recommended that 'eq' and 'ne' should be used for string comparison.
766 +eq ne+::
767     String equal and not equal.  Uses the string value directly without
768     attempting to convert to a number first.
770 +in ni+::
771     String in list and not in list. For 'in', result is 1 if the left operand (as a string)
772     is contained in the right operand (as a list), or 0 otherwise. The result for
773     +{$a ni $list}+ is equivalent to +{!($a in $list)}+.
775 +&+::
776     Bit-wise AND.  Valid for integer operands only.
778 +|+::
779     Bit-wise OR.  Valid for integer operands only.
781 +^+::
782     Bit-wise exclusive OR.  Valid for integer operands only.
784 +&&+::
785     Logical AND.  Produces a 1 result if both operands are non-zero, 0 otherwise.
786     Valid for numeric operands only (integers or floating-point).
788 +||+::
789     Logical OR.  Produces a 0 result if both operands are zero, 1 otherwise.
790     Valid for numeric operands only (integers or floating-point).
792 +x ? y : z+::
793     If-then-else, as in C.  If +'x'+
794     evaluates to non-zero, then the result is the value of +'y'+.
795     Otherwise the result is the value of +'z'+.
796     The +'x'+ operand must have a numeric value, while +'y'+ and +'z'+ can
797     be of any type.
799 See the C manual for more details on the results
800 produced by each operator.
801 All of the binary operators group left-to-right within the same
802 precedence level.  For example, the expression
804     4*2 < 7
806 evaluates to 0.
808 The +&&+, +||+, and +?:+ operators have 'lazy evaluation', just as
809 in C, which means that operands are not evaluated if they are not
810 needed to determine the outcome.  For example, in
812     $v ? [a] : [b]
814 only one of +[a]+ or +[b]+ will actually be evaluated,
815 depending on the value of +$v+.
817 All internal computations involving integers are done with the C
818 type 'long long' if available, or 'long' otherwise, and all internal
819 computations involving floating-point are done with the C type
820 'double'.
822 When converting a string to floating-point, exponent overflow is
823 detected and results in a Tcl error.
824 For conversion to integer from string, detection of overflow depends
825 on the behaviour of some routines in the local C library, so it should
826 be regarded as unreliable.
827 In any case, overflow and underflow are generally not detected
828 reliably for intermediate results.
830 Conversion among internal representations for integer, floating-point,
831 and string operands is done automatically as needed.
832 For arithmetic computations, integers are used until some
833 floating-point number is introduced, after which floating-point is used.
834 For example,
836     5 / 4
838 yields the result 1, while
840     5 / 4.0
841     5 / ( [string length "abcd"] + 0.0 )
843 both yield the result 1.25.
845 String values may be used as operands of the comparison operators,
846 although the expression evaluator tries to do comparisons as integer
847 or floating-point when it can.
848 If one of the operands of a comparison is a string and the other
849 has a numeric value, the numeric operand is converted back to
850 a string using the C 'sprintf' format specifier
851 '%d' for integers and '%g' for floating-point values.
852 For example, the expressions
854     "0x03" > "2"
855     "0y" < "0x12"
857 both evaluate to 1.  The first comparison is done using integer
858 comparison, and the second is done using string comparison after
859 the second operand is converted to the string '18'.
861 In general it is safest to enclose an expression in braces when
862 entering it in a command:  otherwise, if the expression contains
863 any white space then the Tcl interpreter will split it
864 among several arguments.  For example, the command
866     expr $a + $b
868 results in three arguments being passed to `expr`:  +$a+,
869 +\++, and +$b+.  In addition, if the expression isn't in braces
870 then the Tcl interpreter will perform variable and command substitution
871 immediately (it will happen in the command parser rather than in
872 the expression parser).  In many cases the expression is being
873 passed to a command that will evaluate the expression later (or
874 even many times if, for example, the expression is to be used to
875 decide when to exit a loop).  Usually the desired goal is to re-do
876 the variable or command substitutions each time the expression is
877 evaluated, rather than once and for all at the beginning.  For example,
878 the command
880     for {set i 1} $i<=10 {incr i} {...}        +** WRONG **+
882 is probably intended to iterate over all values of +i+ from 1 to 10.
883 After each iteration of the body of the loop, `for` will pass
884 its second argument to the expression evaluator to see whether or not
885 to continue processing.  Unfortunately, in this case the value of +i+
886 in the second argument will be substituted once and for all when the
887 `for` command is parsed.  If +i+ was 0 before the `for`
888 command was invoked then the second argument of `for` will be +0\<=10+
889 which will always evaluate to 1, even though +i+ eventually
890 becomes greater than 10.  In the above case the loop will never
891 terminate.  Instead, the expression should be placed in braces:
893     for {set i 1} {$i<=10} {incr i} {...}      +** RIGHT **+
895 This causes the substitution of 'i'
896 to be delayed; it will be re-done each time the expression is
897 evaluated, which is the desired result.
899 LISTS
900 -----
901 The third major way that strings are interpreted in Tcl is as lists.
902 A list is just a string with a list-like structure
903 consisting of fields separated by white space.  For example, the
904 string
906     Al Sue Anne John
908 is a list with four elements or fields.
909 Lists have the same basic structure as command strings, except
910 that a newline character in a list is treated as a field separator
911 just like space or tab.  Conventions for braces and quotes
912 and backslashes are the same for lists as for commands.  For example,
913 the string
915     a b\ c {d e {f g h}}
917 is a list with three elements:  +a+, +b c+, and +d e {f g h}+.
919 Whenever an element is extracted from a list, the same rules about
920 braces and quotes and backslashes are applied as for commands.  Thus in
921 the example above when the third element is extracted from the list,
922 the result is
924     d e {f g h}
926 (when the field was extracted, all that happened was to strip off
927 the outermost layer of braces).  Command substitution and
928 variable substitution are never
929 made on a list (at least, not by the list-processing commands; the
930 list can always be passed to the Tcl interpreter for evaluation).
932 The Tcl commands `concat`, `foreach`, `lappend`, `lindex`, `linsert`,
933 `list`, `llength`, `lrange`, `lreplace`, `lsearch`, and `lsort` allow
934 you to build lists, extract elements from them, search them, and perform
935 other list-related functions.
937 Advanced list commands include `lrepeat`, `lreverse`, `lmap`, `lassign`, `lset`.
939 LIST EXPANSION
940 --------------
942 A new addition to Tcl 8.5 is the ability to expand a list into separate
943 arguments. Support for this feature is also available in Jim.
945 Consider the following attempt to exec a list:
947     set cmd {ls -l}
948     exec $cmd
950 This will attempt to exec the a command named "ls -l", which will clearly not
951 work. Typically eval and concat are required to solve this problem, however
952 it can be solved much more easily with +\{*\}+.
954     exec {*}$cmd
956 This will expand the following argument into individual elements and then evaluate
957 the resulting command.
959 Note that the official Tcl syntax is +\{*\}+, however +\{expand\}+ is retained
960 for backward compatibility with experimental versions of this feature.
962 REGULAR EXPRESSIONS
963 -------------------
964 Tcl provides two commands that support string matching using regular
965 expressions, `regexp` and `regsub`, as well as `switch -regexp` and
966 `lsearch -regexp`.
968 Regular expressions may be implemented one of two ways. Either using the system's C library
969 POSIX regular expression support, or using the built-in regular expression engine.
970 The differences between these are described below.
972 *NOTE* Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (+ARE+).
974 POSIX Regular Expressions
975 ~~~~~~~~~~~~~~~~~~~~~~~~~
976 If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
977 this support will be used by default. The type of regular expressions supported are
978 Extended Regular Expressions (+ERE+) rather than Basic Regular Expressions (+BRE+).
979 See REG_EXTENDED in the documentation.
981 Using the system-supported POSIX regular expressions will typically
982 make for the smallest code size, but some features such as UTF-8
983 and +{backslash}w+, +{backslash}d+, +{backslash}s+ are not supported.
985 See regex(3) and regex(7) for full details.
987 Jim built-in Regular Expressions
988 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
989 The Jim built-in regulare expression engine may be selected with +./configure --with-jim-regexp+
990 or it will be selected automatically if UTF-8 support is enabled.
992 This engine supports UTF-8 as well as some +ARE+ features. The differences with both Tcl 7.x/8.x
993 and POSIX are highlighted below.
995 1. UTF-8 strings and patterns are both supported
996 2. Supported character classes: +[:alnum:]+, +[:digit:]+ and +[:space:]+
997 3. Supported shorthand character classes: +{backslash}w = +[:alnum:]+, +{backslash}d+ = +[:digit:],+ +{backslash}s+ = +[:space:]+
998 4. Character classes apply to ASCII characters only
999 5. Supported constraint escapes: +{backslash}m+ = +{backslash}<+ = start of word, +{backslash}M+ = +{backslash}>+ = end of word
1000 6. Backslash escapes may be used within regular expressions, such as +{backslash}n+ = newline, +{backslash}uNNNN+ = unicode
1001 7. Support for the +?+ non-greedy quantifier. e.g. +*?+
1002 7. Support for non-capuring parentheses +(?:...)+
1004 COMMAND RESULTS
1005 ---------------
1006 Each command produces two results:  a code and a string.  The
1007 code indicates whether the command completed successfully or not,
1008 and the string gives additional information.  The valid codes are
1009 defined in jim.h, and are:
1011 +JIM_OK(0)+::
1012     This is the normal return code, and indicates that the command completed
1013     successfully.  The string gives the command's return value.
1015 +JIM_ERR(1)+::
1016     Indicates that an error occurred; the string gives a message describing
1017     the error.
1019 +JIM_RETURN(2)+::
1020     Indicates that the `return` command has been invoked, and that the
1021     current procedure (or top-level command or `source` command)
1022     should return immediately.  The
1023     string gives the return value for the procedure or command.
1025 +JIM_BREAK(3)+::
1026     Indicates that the `break` command has been invoked, so the
1027     innermost loop should abort immediately.  The string should always
1028     be empty.
1030 +JIM_CONTINUE(4)+::
1031     Indicates that the `continue` command has been invoked, so the
1032     innermost loop should go on to the next iteration.  The string
1033     should always be empty.
1035 +JIM_SIGNAL(5)+::
1036     Indicates that a signal was caught while executing a commands.
1037     The string contains the name of the signal caught.
1038     See the `signal` and `catch` commands.
1040 +JIM_EXIT(6)+::
1041     Indicates that the command called the `exit` command.
1042     The string contains the exit code.
1044 Tcl programmers do not normally need to think about return codes,
1045 since +JIM_OK+ is almost always returned.  If anything else is returned
1046 by a command, then the Tcl interpreter immediately stops processing
1047 commands and returns to its caller.  If there are several nested
1048 invocations of the Tcl interpreter in progress, then each nested
1049 command will usually return the error to its caller, until eventually
1050 the error is reported to the top-level application code.  The
1051 application will then display the error message for the user.
1053 In a few cases, some commands will handle certain `error` conditions
1054 themselves and not return them upwards.  For example, the `for`
1055 command checks for the +JIM_BREAK+ code; if it occurs, then `for`
1056 stops executing the body of the loop and returns +JIM_OK+ to its
1057 caller.  The `for` command also handles +JIM_CONTINUE+ codes and the
1058 procedure interpreter handles +JIM_RETURN+ codes.  The `catch`
1059 command allows Tcl programs to catch errors and handle them without
1060 aborting command interpretation any further.
1062 The `info returncodes` command may be used to programmatically map between
1063 return codes and names.
1065 PROCEDURES
1066 ----------
1067 Tcl allows you to extend the command interface by defining
1068 procedures.  A Tcl procedure can be invoked just like any other Tcl
1069 command (it has a name and it receives one or more arguments).
1070 The only difference is that its body isn't a piece of C code linked
1071 into the program; it is a string containing one or more other
1072 Tcl commands.
1074 The `proc` command is used to create a new Tcl command procedure:
1076 +*proc* 'name arglist ?statics? body'+
1078 The new command is named +'name'+, and it replaces any existing command
1079 there may have been by that name. Whenever the new command is
1080 invoked, the contents of +'body'+ will be executed by the Tcl
1081 interpreter.
1083 +'arglist'+ specifies the formal arguments to the procedure.
1084 It consists of a list, possibly empty, of the following
1085 argument specifiers:
1087 +name+::
1088     Required Argument - A simple argument name.
1090 +name default+::
1091     Optional Argument - A two-element list consisting of the
1092     argument name, followed by the default value, which will
1093     be used if the corresponding argument is not supplied.
1095 +&name+::
1096     Reference Argument - The caller is expected to pass the name of
1097     an existing variable. An implicit `upvar 1 'origname' 'name'` is done
1098     to make the variable available in the proc scope.
1100 +*args*+::
1101     Variable Argument - The special name +'args'+, which is
1102     assigned all remaining arguments (including none) as a list. The
1103     variable argument may only be specified once. Note that
1104     the syntax +args newname+ may be used to retain the special
1105     behaviour of +'args'+ with a different local name. In this case,
1106     the variable is named +'newname'+ rather than +'args'+.
1108 When the command is invoked, a local variable will be created for each of
1109 the formal arguments to the procedure; its value will be the value
1110 of corresponding argument in the invoking command or the argument's
1111 default value.
1113 Arguments with default values need not be specified in a procedure
1114 invocation.  However, there must be enough actual arguments for all
1115 required arguments, and there must not be any extra actual arguments
1116 (unless the Variable Argument is specified).
1118 Actual arguments are assigned to formal arguments as in left-to-right
1119 order with the following precedence.
1121 1. Required Arguments (including Reference Arguments)
1122 2. Optional Arguments
1123 3. Variable Argument
1125 The following example illustrates precedence. Assume a procedure declaration:
1127     proc p {{a A} args b {c C} d} {...}
1129 This procedure requires at least two arguments, but can accept an unlimited number.
1130 The following table shows how various numbers of arguments are assigned.
1131 Values marked as +-+ are assigned the default value.
1133 [width="40%",frame="topbot",options="header"]
1134 |==============
1135 |Number of arguments|a|args|b|c|d
1136 |2|-|-|1|-|2
1137 |3|1|-|2|-|3
1138 |4|1|-|2|3|4
1139 |5|1|2|3|4|5
1140 |6|1|2,3|4|5|6
1141 |==============
1143 When +'body'+ is being executed, variable names normally refer to local
1144 variables, which are created automatically when referenced and deleted
1145 when the procedure returns.  One local variable is automatically created
1146 for each of the procedure's arguments.  Global variables can be
1147 accessed by invoking the `global` command or via the +::+ prefix.
1149 New in Jim
1150 ~~~~~~~~~~
1151 In addition to procedure arguments, Jim procedures may declare static variables.
1152 These variables scoped to the procedure and initialised at procedure definition.
1153 Either from the static variable definition, or from the enclosing scope.
1155 Consider the following example:
1157     jim> set a 1
1158     jim> proc a {} {a {b 2}} {
1159         set c 1
1160         puts "$a $b $c"
1161         incr a
1162         incr b
1163         incr c
1164     }
1165     jim> a
1166     1 2 1
1167     jim> a
1168     2 3 1
1170 The static variable +'a'+ has no initialiser, so it is initialised from
1171 the enclosing scope with the value 1. (Note that it is an error if there
1172 is no variable with the same name in the enclosing scope). However +'b'+
1173 has an initialiser, so it is initialised to 2.
1175 Unlike a local variable, the value of a static variable is retained across
1176 invocations of the procedure.
1178 See the `proc` command for information on
1179 how to define procedures and what happens when they are invoked.
1181 VARIABLES - SCALARS AND ARRAYS
1182 ------------------------------
1183 Tcl allows the definition of variables and the use of their values
1184 either through '$'-style variable substitution, the `set`
1185 command, or a few other mechanisms.
1187 Variables need not be declared:  a new variable will automatically
1188 be created each time a new variable name is used.
1190 Tcl supports two types of variables:  scalars and arrays.
1191 A scalar variable has a single value, whereas an array variable
1192 can have any number of elements, each with a name (called
1193 its 'index') and a value.
1195 Array indexes may be arbitrary strings; they need not be numeric.
1196 Parentheses are used refer to array elements in Tcl commands.
1197 For example, the command
1199     set x(first) 44
1201 will modify the element of 'x' whose index is 'first'
1202 so that its new value is '44'.
1204 Two-dimensional arrays can be simulated in Tcl by using indexes
1205 that contain multiple concatenated values.
1206 For example, the commands
1208     set a(2,3) 1
1209     set a(3,6) 2
1211 set the elements of 'a' whose indexes are '2,3' and '3,6'.
1213 In general, array elements may be used anywhere in Tcl that scalar
1214 variables may be used.
1216 If an array is defined with a particular name, then there may
1217 not be a scalar variable with the same name.
1219 Similarly, if there is a scalar variable with a particular
1220 name then it is not possible to make array references to the
1221 variable.
1223 To convert a scalar variable to an array or vice versa, remove
1224 the existing variable with the `unset` command.
1226 The `array` command provides several features for dealing
1227 with arrays, such as querying the names of all the elements of
1228 the array and converting between an array and a list.
1230 Variables may be either global or local.  If a variable
1231 name is used when a procedure isn't being executed, then it
1232 automatically refers to a global variable.  Variable names used
1233 within a procedure normally refer to local variables associated with that
1234 invocation of the procedure.  Local variables are deleted whenever
1235 a procedure exits.  Either `global` command may be used to request
1236 that a name refer to a global variable for the duration of the current
1237 procedure (this is somewhat analogous to 'extern' in C), or the variable
1238 may be explicitly scoped with the +::+ prefix. For example
1240     set a 1
1241     set b 2
1242     proc p {} {
1243         set c 3
1244         global a
1246         puts "$a $::b $c"
1247     }
1248     p
1250 will output:
1252     1 2 3
1254 ARRAYS AS LISTS IN JIM
1255 ----------------------
1256 Unlike Tcl, Jim can automatically convert between a list (with an even
1257 number of elements) and an array value. This is similar to the way Tcl
1258 can convert between a string and a list.
1260 For example:
1262   set a {1 one 2 two}
1263   puts $a(2)
1265 will output:
1267   two
1269 Thus `array set` is equivalent to `set` when the variable does not
1270 exist or is empty.
1272 The reverse is also true where an array will be converted into
1273 a list.
1275   set a(1) one; set a(2) two
1276   puts $a
1278 will output:
1280   1 one 2 two
1282 DICTIONARY VALUES
1283 -----------------
1284 Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
1285 of this command. Dictionaries provide efficient access to key-value
1286 pairs, just like arrays, but dictionaries are pure values. This
1287 means that you can pass them to a procedure just as a list or a
1288 string. Tcl dictionaries are therefore much more like Tcl lists,
1289 except that they represent a mapping from keys to values, rather
1290 than an ordered sequence.
1292 You can nest dictionaries, so that the value for a particular key
1293 consists of another dictionary. That way you can elegantly build
1294 complicated data structures, such as hierarchical databases. You
1295 can also combine dictionaries with other Tcl data structures. For
1296 instance, you can build a list of dictionaries that themselves
1297 contain lists.
1299 Dictionaries are values that contain an efficient, order-preserving
1300 mapping from arbitrary keys to arbitrary values. Each key in the
1301 dictionary maps to a single value. They have a textual format that
1302 is exactly that of any list with an even number of elements, with
1303 each mapping in the dictionary being represented as two items in
1304 the list. When a command takes a dictionary and produces a new
1305 dictionary based on it (either returning it or writing it back into
1306 the variable that the starting dictionary was read from) the new
1307 dictionary will have the same order of keys, modulo any deleted
1308 keys and with new keys added on to the end. When a string is
1309 interpreted as a dictionary and it would otherwise have duplicate
1310 keys, only the last value for a particular key is used; the others
1311 are ignored, meaning that, "apple banana" and "apple carrot apple
1312 banana" are equivalent dictionaries (with different string
1313 representations).
1315 Note that in Jim, arrays are implemented as dictionaries.
1316 Thus automatic conversion between lists and dictionaries applies
1317 as it does for arrays.
1319   jim> dict set a 1 one
1320   1 one
1321   jim> dict set a 2 two
1322   1 one 2 two
1323   jim> puts $a
1324   1 one 2 two
1325   jim> puts $a(2)
1326   two
1327   jim> dict set a 3 T three
1328   1 one 2 two 3 {T three}
1330 See the `dict` command for more details.
1332 GARBAGE COLLECTION, REFERENCES, LAMBDA
1333 --------------------------------------
1334 Unlike Tcl, Jim has some sophisticated support for functional programming.
1335 These are described briefly below.
1337 More information may be found at http://wiki.tcl.tk/13847
1339 References
1340 ~~~~~~~~~~
1341 A reference can be thought of as holding a value with one level of indirection,
1342 where the value may be garbage collected when unreferenced.
1343 Consider the following example:
1345     jim> set r [ref "One String" test]
1346     <reference.<test___>.00000000000000000000>
1347     jim> getref $r
1348     One String
1350 The operation `ref` creates a references to the value specified by the
1351 first argument. (The second argument is a "type" used for documentation purposes).
1353 The operation `getref` is the dereferencing operation which retrieves the value
1354 stored in the reference.
1356     jim> setref $r "New String"
1357     New String
1358     jim> getref $r
1359     New String
1361 The operation `setref` replaces the value stored by the reference. If the old value
1362 is no longer accessible by any reference, it will eventually be automatically be garbage
1363 collected.
1365 Garbage Collection
1366 ~~~~~~~~~~~~~~~~~~
1367 Normally, all values in Tcl are passed by value. As such values are copied and released
1368 automatically as necessary.
1370 With the introduction of references, it is possible to create values whose lifetime
1371 transcend their scope. To support this, case, the Jim system will periodically identify
1372 and discard objects which are no longer accessible by any reference.
1374 The `collect` command may be used to force garbage collection.  Consider a reference created
1375 with a finalizer:
1377     jim> proc f {ref value} { puts "Finaliser called for $ref,$value" }
1378     jim> set r [ref "One String" test f]
1379     <reference.<test___>.00000000000
1380     jim> collect
1381     0
1382     jim> set r ""
1383     jim> collect
1384     Finaliser called for <reference.<test___>.00000000000,One String
1385     1
1387 Note that once the reference, 'r', was modified so that it no longer
1388 contained a reference to the value, the garbage collector discarded
1389 the value (after calling the finalizer).
1391 The finalizer for a reference may be examined or changed with the `finalize` command
1393     jim> finalize $r
1394     f
1395     jim> finalize $r newf
1396     newf
1398 Lambda
1399 ~~~~~~
1400 Jim provides a garbage collected lambda function. This is a procedure
1401 which is able to create an anonymous procedure.  Consider:
1403     jim> set f [lambda {a} {{x 0}} { incr x $a }]
1404     jim> $f 1
1405     1
1406     jim> $f 2
1407     3
1408     jim> set f ""
1410 This create an anonymous procedure (with the name stored in 'f'), with a static variable
1411 which is incremented by the supplied value and the result returned.
1413 Once the procedure name is no longer accessible, it will automatically be deleted
1414 when the garbage collector runs.
1416 The procedure may also be delete immediately by renaming it "". e.g.
1418     jim> rename $f ""
1420 UTF-8 AND UNICODE
1421 -----------------
1422 If Jim is built with UTF-8 support enabled (configure --enable-utf),
1423 then most string-related commands become UTF-8 aware.  These include,
1424 but are not limited to, `string match`, `split`, `glob`, `scan` and
1425 `format`.
1427 UTF-8 encoding has many advantages, but one of the complications is that
1428 characters can take a variable number of bytes. Thus the addition of
1429 `string bytelength` which returns the number of bytes in a string,
1430 while `string length` returns the number of characters.
1432 If UTF-8 support is not enabled, all commands treat bytes as characters
1433 and `string bytelength` returns the same value as `string length`.
1435 Note that even if UTF-8 support is not enabled, the +{backslash}uNNNN+ syntax
1436 is still available to embed UTF-8 sequences.
1438 String Matching
1439 ~~~~~~~~~~~~~~~
1440 Commands such as `string match`, `lsearch -glob`, `array names` and others use string
1441 pattern matching rules. These commands support UTF-8. For example:
1443   string match a\[\ua0-\ubf\]b "a\u00a3b"
1445 format and scan
1446 ~~~~~~~~~~~~~~~
1447 +format %c+ allows a unicode codepoint to be be encoded. For example, the following will return
1448 a string with two bytes and one character. The same as +{backslash}ub5+
1450   format %c 0xb5
1452 `format` respects widths as character widths, not byte widths. For example, the following will
1453 return a string with three characters, not three bytes.
1455   format %.3s \ub5\ub6\ub7\ub8
1457 Similarly, +scan ... %c+ allows a UTF-8 to be decoded to a unicode codepoint. The following will set
1458 +'a'+ to 181 (0xb5) and +'b'+ to 65 (0x41).
1460   scan \u00b5A %c%c a b
1462 `scan %s` will also accept a character class, including unicode ranges.
1464 String Classes
1465 ~~~~~~~~~~~~~~
1466 `string is` has *not* been extended to classify UTF-8 characters. Therefore, the following
1467 will return 0, even though the string may be considered to be alphabetic.
1469   string is alpha \ub5Test
1471 This does not affect the string classes 'ascii', 'control', 'digit', 'double', 'integer' or 'xdigit'.
1473 Case Mapping and Conversion
1474 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1475 Jim provides a simplified unicode case mapping. This means that case conversion
1476 and comparison will not increase or decrease the number of characters in a string.
1478 `string toupper` will convert any lowercase letters to their uppercase equivalent.
1479 Any character which is not a letter or has no uppercase equivalent is left unchanged.
1480 Similarly for `string tolower`.
1482 Commands which perform case insensitive matches, such as `string compare -nocase`
1483 and `lsearch -nocase` fold both strings to uppercase before comparison.
1485 Invalid UTF-8 Sequences
1486 ~~~~~~~~~~~~~~~~~~~~~~~
1487 Some UTF-8 character sequences are invalid, such as those beginning with '0xff',
1488 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
1489 and those which end prematurely, such as a lone '0xc2'.
1491 In these situations, the offending bytes are treated as single characters. For example,
1492 the following returns 2.
1494   string bytelength \xff\xff
1496 Regular Expressions
1497 ~~~~~~~~~~~~~~~~~~~
1498 If UTF-8 support is enabled, the built-in regular expression engine will be
1499 selected which supports UTF-8 strings and patterns.
1501 See REGULAR EXPRESSIONS
1503 BUILT-IN COMMANDS
1504 -----------------
1505 The Tcl library provides the following built-in commands, which will
1506 be available in any application using Tcl.  In addition to these
1507 built-in commands, there may be additional commands defined by each
1508 application, plus commands defined as Tcl procedures.
1510 In the command syntax descriptions below, words in +*boldface*+ are
1511 literals that you type verbatim to Tcl.
1513 Words in +'italics'+ are meta-symbols; they serve as names for any of
1514 a range of values that you can type.
1516 Optional arguments or groups of arguments are indicated by enclosing them
1517 in +?question-marks?+.
1519 Ellipses (+\...+) indicate that any number of additional
1520 arguments or groups of arguments may appear, in the same format
1521 as the preceding argument(s).
1523 [[CommandIndex]]
1524 Command Index
1525 ~~~~~~~~~~~~~
1526 @INSERTINDEX@
1528 alarm
1529 ~~~~~
1530 +*alarm* 'seconds'+
1532 Delivers the +SIGALRM+ signal to the process after the given
1533 number of seconds. If the platform supports 'ualarm(3)' then
1534 the argument may be a floating point value. Otherwise it must
1535 be an integer.
1537 Note that unless a signal handler for +SIGALRM+ has been installed
1538 (see `signal`), the process will exit on this signal.
1540 alias
1541 ~~~~~
1542 +*alias* 'name args\...'+
1544 Creates a single word alias (`proc`) for one or more words. For example,
1545 the following creates an alias for the command `info exists`.
1547     alias e info exists
1548     if {[e var]} {
1549       ...
1550     }
1552 `alias` returns +'name'+, allowing it to be used with `local`.
1554 See also `proc`, `curry`, `lambda`, `local`.
1556 append
1557 ~~~~~~
1558 +*append* 'varName value ?value value ...?'+
1560 Append all of the +'value'+ arguments to the current value
1561 of variable +'varName'+.  If +'varName'+ doesn't exist,
1562 it is given a value equal to the concatenation of all the
1563 +'value'+ arguments.
1565 This command provides an efficient way to build up long
1566 variables incrementally.
1567 For example, "`append a $b`" is much more efficient than
1568 "`set a $a$b`" if +$a+ is long.
1570 array
1571 ~~~~~
1572 +*array* 'option arrayName ?arg\...?'+
1574 This command performs one of several operations on the
1575 variable given by +'arrayName'+.
1577 Note that in general, if the named array does not exist, the +'array'+ command behaves
1578 as though the array exists but is empty.
1580 The +'option'+ argument determines what action is carried out by the
1581 command.  The legal +'options'+ (which may be abbreviated) are:
1583 +*array exists* 'arrayName'+::
1584     Returns 1 if arrayName is an array variable, 0 if there is
1585     no variable by that name.  This command is essentially
1586     identical to `info exists`
1588 +*array get* 'arrayName ?pattern?'+::
1589     Returns a list containing pairs of elements. The first
1590     element in each pair is the name of an element in arrayName
1591     and the second element of each pair is the value of the
1592     array element. The order of the pairs is undefined. If
1593     pattern is not specified, then all of the elements of the
1594     array are included in the result. If pattern is specified,
1595     then only those elements whose names match pattern (using
1596     the matching rules of string match) are included. If arrayName
1597     isn't the name of an array variable, or if the array contains
1598     no elements, then an empty list is returned.
1600 +*array names* 'arrayName ?pattern?'+::
1601     Returns a list containing the names of all of the elements
1602     in the array that match pattern. If pattern is omitted then
1603     the command returns all of the element names in the array.
1604     If pattern is specified, then only those elements whose
1605     names match pattern (using the matching rules of string
1606     match) are included. If there are no (matching) elements
1607     in the array, or if arrayName isn't the name of an array
1608     variable, then an empty string is returned.
1610 +*array set* 'arrayName list'+::
1611     Sets the values of one or more elements in arrayName. list
1612     must have a form like that returned by array get, consisting
1613     of an even number of elements. Each odd-numbered element
1614     in list is treated as an element name within arrayName, and
1615     the following element in list is used as a new value for
1616     that array element. If the variable arrayName does not
1617     already exist and list is empty, arrayName is created with
1618     an empty array value.
1620 +*array size* 'arrayName'+::
1621     Returns the number of elements in the array. If arrayName
1622     isn't the name of an array then 0 is returned.
1624 +*array unset* 'arrayName ?pattern?'+::
1625     Unsets all of the elements in the array that match pattern
1626     (using the matching rules of string match). If arrayName
1627     isn't the name of an array variable or there are no matching
1628     elements in the array, no error will be raised. If pattern
1629     is omitted and arrayName is an array variable, then the
1630     command unsets the entire array. The command always returns
1631     an empty string.
1633 break
1634 ~~~~~
1635 +*break*+
1637 This command may be invoked only inside the body of a loop command
1638 such as `for` or `foreach` or `while`.  It returns a +JIM_BREAK+ code
1639 to signal the innermost containing loop command to return immediately.
1641 case
1642 ~~~~
1643 +*case* 'string' ?in? 'patList body ?patList body ...?'+
1645 +*case* 'string' ?in? {'patList body ?patList body ...?'}+
1647 *Note* that the `switch` command should generally be preferred unless compatibility
1648 with Tcl 6.x is desired.
1650 Match +'string'+ against each of the +'patList'+ arguments
1651 in order.  If one matches, then evaluate the following +'body'+ argument
1652 by passing it recursively to the Tcl interpreter, and return the result
1653 of that evaluation.  Each +'patList'+ argument consists of a single
1654 pattern or list of patterns.  Each pattern may contain any of the wild-cards
1655 described under `string match`.
1657 If a +'patList'+ argument is +default+, the corresponding body will be
1658 evaluated if no +'patList'+ matches +'string'+.  If no +'patList'+ argument
1659 matches +'string'+ and no default is given, then the `case` command returns
1660 an empty string.
1662 Two syntaxes are provided.
1664 The first uses a separate argument for each of the patterns and commands;
1665 this form is convenient if substitutions are desired on some of the
1666 patterns or commands.
1668 The second form places all of the patterns and commands together into
1669 a single argument; the argument must have proper list structure, with
1670 the elements of the list being the patterns and commands.
1672 The second form makes it easy to construct multi-line case commands,
1673 since the braces around the whole list make it unnecessary to include a
1674 backslash at the end of each line.
1676 Since the +'patList'+ arguments are in braces in the second form,
1677 no command or variable substitutions are performed on them;  this makes
1678 the behaviour of the second form different than the first form in some
1679 cases.
1681 Below are some examples of `case` commands:
1683     case abc in {a b} {format 1} default {format 2} a* {format 3}
1685 will return '3',
1687     case a in {
1688         {a b} {format 1}
1689         default {format 2}
1690         a* {format 3}
1691     }
1693 will return '1', and
1695     case xyz {
1696         {a b}
1697             {format 1}
1698         default
1699             {format 2}
1700         a*
1701             {format 3}
1702     }
1704 will return '2'.
1706 catch
1707 ~~~~~
1708 +*catch* ?-?no?'code \...'? ?--? 'command ?resultVarName? ?optionsVarName?'+
1710 The `catch` command may be used to prevent errors from aborting
1711 command interpretation.  `catch` evaluates +'command'+, and returns a
1712 +JIM_OK+ code, regardless of any errors that might occur while
1713 executing +'command'+ (with the possible exception of +JIM_SIGNAL+ -
1714 see below).
1716 The return value from `catch` is a decimal string giving the code
1717 returned by the Tcl interpreter after executing +'command'+.  This
1718 will be '0' (+JIM_OK+) if there were no errors in +'command'+; otherwise
1719 it will have a non-zero value corresponding to one of the exceptional
1720 return codes (see jim.h for the definitions of code values, or the
1721 `info returncodes` command).
1723 If the +'resultVarName'+ argument is given, then it gives the name
1724 of a variable; `catch` will set the value of the variable to the
1725 string returned from +'command'+ (either a result or an error message).
1727 If the +'optionsVarName'+ argument is given, then it gives the name
1728 of a variable; `catch` will set the value of the variable to a
1729 dictionary. For any return code other than +JIM_RETURN+, the value
1730 for the key +-code+ will be set to the return code. For +JIM_RETURN+
1731 it will be set to the code given in `return -code`. Additionally,
1732 for the return code +JIM_ERR+, the value of the key +-errorinfo+
1733 will contain the current stack trace (the same result as `info stacktrace`),
1734 the value of the key +-errorcode+ will contain the
1735 same value as the global variable $::errorCode, and the value of
1736 the key +-level+ will be the current return level (see `return -level`).
1737 This can be useful to rethrow an error:
1739     if {[catch {...} msg opts]} {
1740         ...maybe do something with the error...
1741         incr opts(-level)
1742         return {*}$opts $msg
1743     }
1745 Normally `catch` will +'not'+ catch any of the codes +JIM_EXIT+, +JIM_EVAL+ or +JIM_SIGNAL+.
1746 The set of codes which will be caught may be modified by specifying the one more codes before
1747 +'command'+.
1749 e.g. To catch +JIM_EXIT+ but not +JIM_BREAK+ or +JIM_CONTINUE+
1751     catch -exit -nobreak -nocontinue -- { ... }
1753 The use of +--+ is optional. It signifies that no more return code options follow.
1755 Note that if a signal marked as `signal handle` is caught with `catch -signal`, the return value
1756 (stored in +'resultVarName'+) is name of the signal caught.
1760 +*cd* 'dirName'+
1762 Change the current working directory to +'dirName'+.
1764 Returns an empty string.
1766 This command can potentially be disruptive to an application, so it may
1767 be removed in some applications.
1769 clock
1770 ~~~~~
1771 +*clock seconds*+::
1772     Returns the current time as seconds since the epoch.
1774 +*clock format* 'seconds' ?*-format* 'format?'+::
1775     Format the given time (seconds since the epoch) according to the given
1776     format. See strftime(3) for supported formats.
1777     If no format is supplied, "%c" is used.
1779 +*clock scan* 'str' *-format* 'format'+::
1780     Scan the given time string using the given format string.
1781     See strptime(3) for supported formats.
1783 close
1784 ~~~~~
1785 +*close* 'fileId'+
1787 +'fileId' *close*+
1789 Closes the file given by +'fileId'+.
1790 +'fileId'+ must be the return value from a previous invocation
1791 of the `open` command; after this command, it should not be
1792 used anymore.
1794 collect
1795 ~~~~~~~
1796 +*collect*+
1798 Normally reference garbage collection is automatically performed periodically.
1799 However it may be run immediately with the `collect` command.
1801 See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.
1803 concat
1804 ~~~~~~
1805 +*concat* 'arg ?arg \...?'+
1807 This command treats each argument as a list and concatenates them
1808 into a single list.  It permits any number of arguments.  For example,
1809 the command
1811     concat a b {c d e} {f {g h}}
1813 will return
1815     a b c d e f {g h}
1817 as its result.
1819 continue
1820 ~~~~~~~~
1821 +*continue*+
1823 This command may be invoked only inside the body of a loop command such
1824 as `for` or `foreach` or `while`.  It returns a  +JIM_CONTINUE+ code to
1825 signal the innermost containing loop command to skip the remainder of
1826 the loop's body but continue with the next iteration of the loop.
1828 curry
1829 ~~~~~
1830 +*alias* 'args\...'+
1832 Similar to `alias` except it creates an anonymous procedure (lambda) instead of
1833 a named procedure.
1835 the following creates a local, unnamed alias for the command `info exists`.
1837     set e [local curry info exists]
1838     if {[$e var]} {
1839       ...
1840     }
1842 `curry` returns the name of the procedure.
1844 See also `proc`, `alias`, `lambda`, `local`.
1846 dict
1847 ~~~~
1848 +*dict* 'option ?arg\...?'+
1850 Performs one of several operations on dictionary values.
1852 The +'option'+ argument determines what action is carried out by the
1853 command.  The legal +'options'+ are:
1855 +*dict create* '?key value \...?'+::
1856     Create and return a new dictionary value that contains each of
1857     the key/value mappings listed as  arguments (keys and values
1858     alternating, with each key being followed by its associated
1859     value.)
1861 +*dict exists* 'dictionary key ?key \...?'+::
1862     Returns a boolean value indicating whether the given key (or path
1863     of keys through a set of nested dictionaries) exists in the given
1864     dictionary value.  This returns a true value exactly when `dict get`
1865     on that path will succeed.
1867 +*dict get* 'dictionary ?key \...?'+::
1868     Given a dictionary value (first argument) and a key (second argument),
1869     this will retrieve the value for that key. Where several keys are
1870     supplied, the behaviour of the command shall be as if the result
1871     of "`dict get $dictVal $key`" was passed as the first argument to
1872     dict get with the remaining arguments as second (and possibly
1873     subsequent) arguments. This facilitates lookups in nested dictionaries.
1874     If no keys are provided, dict would return a list containing pairs
1875     of elements in a man- ner similar to array get. That is, the first
1876     element of each pair would be the key and the second element would
1877     be the value for that key.  It is an error to attempt to retrieve
1878     a value for a key that is not present in the dictionary.
1880 +*dict keys* 'dictionary ?pattern?'+::
1881     Returns a list of the keys in the dictionary.
1882     If pattern is specified, then only those keys whose
1883     names match +'pattern'+ (using the matching rules of string
1884     match) are included.
1886 +*dict merge* ?'dictionary \...'?+::
1887     Return a dictionary that contains the contents of each of the
1888     +'dictionary'+ arguments. Where two (or more) dictionaries
1889     contain a mapping for the same key, the resulting dictionary
1890     maps that key to the value according to the last dictionary on
1891     the command line containing a mapping for that key.
1893 +*dict set* 'dictionaryName key ?key \...? value'+::
1894     This operation takes the +'name'+ of a variable containing a dictionary
1895     value and places an updated dictionary value in that variable
1896     containing a mapping from the given key to the given value. When
1897     multiple keys are present, this operation creates or updates a chain
1898     of nested dictionaries.
1900 +*dict size* 'dictionary'+::
1901     Return the number of key/value mappings in the given dictionary value.
1903 +*dict unset* 'dictionaryName key ?key \...? value'+::
1904     This operation (the companion to `dict set`) takes the name of a
1905     variable containing a dictionary value and places an updated
1906     dictionary value in that variable that does not contain a mapping
1907     for the given key. Where multiple keys are present, this describes
1908     a path through nested dictionaries to the mapping to remove. At
1909     least one key must be specified, but the last key on the key-path
1910     need not exist. All other components on the path must exist.
1912 +*dict with* 'dictionaryName key ?key \...? script'+::
1913     Execute the Tcl script in +'script'+ with the value for each
1914     key in +'dictionaryName'+ mapped to a variable with the same
1915     name. Where one or more keys are given, these indicate a chain
1916     of nested dictionaries, with the innermost dictionary being the
1917     one opened out for the execution of body. Making +'dictionaryName'+
1918     unreadable will make the updates to the dictionary be discarded,
1919     and this also happens if the contents of +'dictionaryName'+ are
1920     adjusted so that the chain of dictionaries no longer exists.
1921     The result of `dict with` is (unless some kind of error occurs)
1922     the result of the evaluation of body.
1923  ::
1924     The variables are mapped in the scope enclosing the `dict with`;
1925     it is recommended that this command only be used in a local
1926     scope (procedure). Because of this, the variables set by
1927     `dict with` will continue to exist after the command finishes (unless
1928     explicitly unset). Note that changes to the contents of +'dictionaryName'+
1929     only happen when +'script'+ terminates.
1933 +*env* '?name? ?default?'+
1935 If +'name'+ is supplied, returns the value of +'name'+ from the initial
1936 environment (see getenv(3)). An error is returned if +'name'+ does not
1937 exist in the environment, unless +'default'+ is supplied - in which case
1938 that value is returned instead.
1940 If no arguments are supplied, returns a list of all environment variables
1941 and their values as +{name value \...}+
1943 See also the global variable +::env+
1947 +*eof* 'fileId'+
1949 +'fileId' *eof*+
1951 Returns 1 if an end-of-file condition has occurred on +'fileId'+,
1952 0 otherwise.
1954 +'fileId'+ must have been the return value from a previous call to `open`,
1955 or it may be +stdin+, +stdout+, or +stderr+ to refer to one of the
1956 standard I/O channels.
1958 error
1959 ~~~~~
1960 +*error* 'message ?stacktrace?'+
1962 Returns a +JIM_ERR+ code, which causes command interpretation to be
1963 unwound.  +'message'+ is a string that is returned to the application
1964 to indicate what went wrong.
1966 If the +'stacktrace'+ argument is provided and is non-empty,
1967 it is used to initialize the stacktrace.
1969 This feature is most useful in conjunction with the `catch` command:
1970 if a caught error cannot be handled successfully, +'stacktrace'+ can be used
1971 to return a stack trace reflecting the original point of occurrence
1972 of the error:
1974     catch {...} errMsg
1975     ...
1976     error $errMsg [info stacktrace]
1978 See also `errorInfo`, `info stacktrace`, `catch` and `return`
1980 errorInfo
1981 ~~~~~~~~~
1982 +*errorInfo* 'error ?stacktrace?'+
1984 Returns a human-readable representation of the given error message and stack trace.
1985 Typical usage is:
1987     if {[catch {...} error]} {
1988         puts stderr [errorInfo $error [info stacktrace]]
1989         exit 1
1990     }
1992 See also `error`.
1994 eval
1995 ~~~~
1996 +*eval* 'arg ?arg\...?'+
1998 `eval` takes one or more arguments, which together comprise a Tcl
1999 command (or collection of Tcl commands separated by newlines in the
2000 usual way).  `eval` concatenates all its arguments in the same
2001 fashion as the `concat` command, passes the concatenated string to the
2002 Tcl interpreter recursively, and returns the result of that
2003 evaluation (or any error generated by it).
2005 exec
2006 ~~~~
2007 +*exec* 'arg ?arg\...?'+
2009 This command treats its arguments as the specification
2010 of one or more UNIX commands to execute as subprocesses.
2011 The commands take the form of a standard shell pipeline;
2012 +|+ arguments separate commands in the
2013 pipeline and cause standard output of the preceding command
2014 to be piped into standard input of the next command (or +|&+ for
2015 both standard output and standard error).
2017 Under normal conditions the result of the `exec` command
2018 consists of the standard output produced by the last command
2019 in the pipeline.
2021 If any of the commands in the pipeline exit abnormally or
2022 are killed or suspended, then `exec` will return an error
2023 and the error message will include the pipeline's output followed by
2024 error messages describing the abnormal terminations.
2026 If any of the commands writes to its standard error file,
2027 then `exec` will return an error, and the error message
2028 will include the pipeline's output, followed by messages
2029 about abnormal terminations (if any), followed by the standard error
2030 output.
2032 If the last character of the result or error message
2033 is a newline then that character is deleted from the result
2034 or error message for consistency with normal
2035 Tcl return values.
2037 An +'arg'+ may have one of the following special forms:
2039 +>filename+::
2040     The standard output of the last command in the pipeline
2041     is redirected to the file.  In this situation `exec`
2042     will normally return an empty string.
2044 +>>filename+::
2045     As above, but append to the file.
2047 +>@fileId+::
2048     The standard output of the last command in the pipeline is
2049     redirected to the given (writable) file descriptor (e.g. stdout,
2050     stderr, or the result of `open`). In this situation `exec`
2051     will normally return an empty string.
2053 +2>filename+::
2054     The standard error of the last command in the pipeline
2055     is redirected to the file.
2057 +2>>filename+::
2058     As above, but append to the file.
2060 +2>@fileId+::
2061     The standard error of the last command in the pipeline is
2062     redirected to the given (writable) file descriptor.
2064 +2>@1+::
2065     The standard error of the last command in the pipeline is
2066     redirected to the same file descriptor as the standard output.
2068 +>&filename+::
2069     Both the standard output and standard error of the last command
2070     in the pipeline is redirected to the file.
2072 +>>&filename+::
2073     As above, but append to the file.
2075 +<filename+::
2076     The standard input of the first command in the pipeline
2077     is taken from the file.
2079 +<<string+::
2080     The standard input of the first command is taken as the
2081     given immediate value.
2083 +<@fileId+::
2084     The standard input of the first command in the pipeline
2085     is taken from the given (readable) file descriptor.
2087 If there is no redirection of standard input, standard error
2088 or standard output, these are connected to the corresponding
2089 input or output of the application.
2091 If the last +'arg'+ is +&+ then the command will be
2092 executed in background.
2093 In this case the standard output from the last command
2094 in the pipeline will
2095 go to the application's standard output unless
2096 redirected in the command, and error output from all
2097 the commands in the pipeline will go to the application's
2098 standard error file. The return value of exec in this case
2099 is a list of process ids (pids) in the pipeline.
2101 Each +'arg'+ becomes one word for a command, except for
2102 +|+, +<+, +<<+, +>+, and +&+ arguments, and the
2103 arguments that follow +<+, +<<+, and +>+.
2105 The first word in each command is taken as the command name;
2106 the directories in the PATH environment variable are searched for
2107 an executable by the given name.
2109 No `glob` expansion or other shell-like substitutions
2110 are performed on the arguments to commands.
2112 If the command fails, the global $::errorCode (and the -errorcode
2113 option in `catch`) will be set to a list, as follows:
2115 +*CHILDKILLED* 'pid sigName msg'+::
2116         This format is used when a child process has been killed
2117         because of a signal. The pid element will be the process's
2118         identifier (in decimal). The sigName element will be the
2119         symbolic name of the signal that caused the process to
2120         terminate; it will be one of the names from the include
2121         file signal.h, such as SIGPIPE. The msg element will be a
2122         short human-readable message describing the signal, such
2123         as "write on pipe with no readers" for SIGPIPE.
2125 +*CHILDSUSP* 'pid sigName msg'+::
2126         This format is used when a child process has been suspended
2127         because of a signal. The pid element will be the process's
2128         identifier, in decimal. The sigName element will be the
2129         symbolic name of the signal that caused the process to
2130         suspend; this will be one of the names from the include
2131         file signal.h, such as SIGTTIN. The msg element will be a
2132         short human-readable message describing the signal, such
2133         as "background tty read" for SIGTTIN.
2135 +*CHILDSTATUS* 'pid code'+::
2136         This format is used when a child process has exited with a
2137         non-zero exit status. The pid element will be the process's
2138         identifier (in decimal) and the code element will be the
2139         exit code returned by the process (also in decimal).
2141 The environment for the executed command is set from $::env (unless
2142 this variable is unset, in which case the original environment is used).
2144 exists
2145 ~~~~~~
2146 +*exists ?-var|-proc|-command?* 'name'+
2148 Checks the existence of the given variable, procedure or command
2149 respectively and returns 1 if it exists or 0 if not.  This command
2150 provides a more simplified/convenient version of `info exists`,
2151 `info procs` and `info commands`.
2153 If the type is omitted, a type of '-var' is used. The type may be abbreviated.
2155 exit
2156 ~~~~
2157 +*exit* '?returnCode?'+
2159 Terminate the process, returning +'returnCode'+ to the
2160 parent as the exit status.
2162 If +'returnCode'+ isn't specified then it defaults
2163 to 0.
2165 Note that exit can be caught with `catch`.
2167 expr
2168 ~~~~
2169 +*expr* 'arg'+
2171 Calls the expression processor to evaluate +'arg'+, and returns
2172 the result as a string.  See the section EXPRESSIONS above.
2174 Note that Jim supports a shorthand syntax for `expr` as +$(\...)+
2175 The following two are identical.
2177   set x [expr {3 * 2 + 1}]
2178   set x $(3 * 2 + 1)
2180 file
2181 ~~~~
2182 +*file* 'option name ?arg\...?'+
2184 Operate on a file or a file name.  +'name'+ is the name of a file.
2186 +'option'+ indicates what to do with the file name.  Any unique
2187 abbreviation for +'option'+ is acceptable.  The valid options are:
2189 +*file atime* 'name'+::
2190     Return a decimal string giving the time at which file +'name'+
2191     was last accessed.  The time is measured in the standard UNIX
2192     fashion as seconds from a fixed starting time (often January 1, 1970).
2193     If the file doesn't exist or its access time cannot be queried then an
2194     error is generated.
2196 +*file copy ?-force?* 'source target'+::
2197     Copies file +'source'+ to file +'target'+. The source file must exist.
2198     The target file must not exist, unless +-force+ is specified.
2200 +*file delete ?-force?* 'name\...'+::
2201     Deletes file or directory +'name'+. If the file or directory doesn't exist, nothing happens.
2202     If it can't be deleted, an error is generated. Non-empty directories will not be deleted
2203     unless the +-force+ options is given. In this case no errors will be generated, even
2204     if the file/directory can't be deleted.
2206 +*file dirname* 'name'+::
2207     Return all of the characters in +'name'+ up to but not including
2208     the last slash character.  If there are no slashes in +'name'+
2209     then return +.+ (a single dot).  If the last slash in +'name'+ is its first
2210     character, then return +/+.
2212 +*file executable* 'name'+::
2213     Return '1' if file +'name'+ is executable by
2214     the current user, '0' otherwise.
2216 +*file exists* 'name'+::
2217     Return '1' if file +'name'+ exists and the current user has
2218     search privileges for the directories leading to it, '0' otherwise.
2220 +*file extension* 'name'+::
2221     Return all of the characters in +'name'+ after and including the
2222     last dot in +'name'+.  If there is no dot in +'name'+ then return
2223     the empty string.
2225 +*file isdirectory* 'name'+::
2226     Return '1' if file +'name'+ is a directory,
2227     '0' otherwise.
2229 +*file isfile* 'name'+::
2230     Return '1' if file +'name'+ is a regular file,
2231     '0' otherwise.
2233 +*file join* 'arg\...'+::
2234     Joins multiple path components. Note that if any components is
2235     an absolute path, the preceding components are ignored.
2236     Thus +"`file` join /tmp /root"+ returns +"/root"+.
2238 +*file lstat* 'name varName'+::
2239     Same as 'stat' option (see below) except uses the +'lstat'+
2240     kernel call instead of +'stat'+.  This means that if +'name'+
2241     refers to a symbolic link the information returned in +'varName'+
2242     is for the link rather than the file it refers to.  On systems that
2243     don't support symbolic links this option behaves exactly the same
2244     as the 'stat' option.
2246 +*file mkdir* 'dir1 ?dir2\...?'+::
2247     Creates each directory specified. For each pathname +'dir'+ specified,
2248     this command will create all non-existing parent directories
2249     as well as +'dir'+ itself. If an existing directory is specified,
2250     then no action is taken and no error is returned. Trying to
2251     overwrite an existing file with a directory will result in an
2252     error.  Arguments are processed in the order specified, halting
2253     at the first error, if any.
2255 +*file mtime* 'name ?time?'+::
2256     Return a decimal string giving the time at which file +'name'+
2257     was last modified.  The time is measured in the standard UNIX
2258     fashion as seconds from a fixed starting time (often January 1, 1970).
2259     If the file doesn't exist or its modified time cannot be queried then an
2260     error is generated. If +'time'+ is given, sets the modification time
2261     of the file to the given value.
2263 +*file normalize* 'name'+::
2264     Return the normalized path of +'name'+. See 'realpath(3)'.
2266 +*file owned* 'name'+::
2267     Return '1' if file +'name'+ is owned by the current user,
2268     '0' otherwise.
2270 +*file readable* 'name'+::
2271     Return '1' if file +'name'+ is readable by
2272     the current user, '0' otherwise.
2274 +*file readlink* 'name'+::
2275     Returns the value of the symbolic link given by +'name'+ (i.e. the
2276     name of the file it points to).  If
2277     +'name'+ isn't a symbolic link or its value cannot be read, then
2278     an error is returned.  On systems that don't support symbolic links
2279     this option is undefined.
2281 +*file rename* 'oldname' 'newname'+::
2282     Renames the file from the old name to the new name.
2284 +*file rootname* 'name'+::
2285     Return all of the characters in +'name'+ up to but not including
2286     the last '.' character in the name.  If +'name'+ doesn't contain
2287     a dot, then return +'name'+.
2289 +*file size* 'name'+::
2290     Return a decimal string giving the size of file +'name'+ in bytes.
2291     If the file doesn't exist or its size cannot be queried then an
2292     error is generated.
2294 +*file stat* 'name varName'+::
2295     Invoke the 'stat' kernel call on +'name'+, and use the
2296     variable given by +'varName'+ to hold information returned from
2297     the kernel call.
2298     +'varName'+ is treated as an array variable,
2299     and the following elements of that variable are set: 'atime',
2300     'ctime', 'dev', 'gid', 'ino', 'mode', 'mtime',
2301     'nlink', 'size', 'type', 'uid'.
2302     Each element except 'type' is a decimal string with the value of
2303     the corresponding field from the 'stat' return structure; see the
2304     manual entry for 'stat' for details on the meanings of the values.
2305     The 'type' element gives the type of the file in the same form
2306     returned by the command `file type`.
2307     This command returns an empty string.
2309 +*file tail* 'name'+::
2310     Return all of the characters in +'name'+ after the last slash.
2311     If +'name'+ contains no slashes then return +'name'+.
2313 +*file tempfile* '?template?'+::
2314     Creates and returns the name of a unique temporary file. If +'template'+ is omitted, a
2315     default template will be used to place the file in /tmp. See 'mkstemp(3)' for
2316     the format of the template and security concerns.
2318 +*file type* 'name'+::
2319     Returns a string giving the type of file +'name'+, which will be
2320     one of +file+, +directory+, +characterSpecial+,
2321     +blockSpecial+, +fifo+, +link+, or +socket+.
2323 +*file writable* 'name'+::
2324     Return '1' if file +'name'+ is writable by
2325     the current user, '0' otherwise.
2327 The `file` commands that return 0/1 results are often used in
2328 conditional or looping commands, for example:
2330     if {![file exists foo]} {
2331         error {bad file name}
2332     } else {
2333         ...
2334     }
2336 finalize
2337 ~~~~~~~~
2338 +*finalize* 'reference ?command?'+
2340 If +'command'+ is omitted, returns the finalizer command for the given reference.
2342 Otherwise, sets a new finalizer command for the given reference. +'command'+ may be
2343 the empty string to remove the current finalizer.
2345 The reference must be a valid reference create with the `ref`
2346 command.
2348 See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.
2350 flush
2351 ~~~~~
2352 +*flush* 'fileId'+
2354 +'fileId' *flush*+
2356 Flushes any output that has been buffered for +'fileId'+.  +'fileId'+ must
2357 have been the return value from a previous call to `open`, or it may be
2358 +stdout+ or +stderr+ to access one of the standard I/O streams; it must
2359 refer to a file that was opened for writing.  This command returns an
2360 empty string.
2364 +*for* 'start test next body'+
2366 `for` is a looping command, similar in structure to the C `for` statement.
2367 The +'start'+, +'next'+, and +'body'+ arguments must be Tcl command strings,
2368 and +'test'+ is an expression string.
2370 The `for` command first invokes the Tcl interpreter to execute +'start'+.
2371 Then it repeatedly evaluates +'test'+ as an expression; if the result is
2372 non-zero it invokes the Tcl interpreter on +'body'+, then invokes the Tcl
2373 interpreter on +'next'+, then repeats the loop.  The command terminates
2374 when +'test'+ evaluates to 0.
2376 If a `continue` command is invoked within +'body'+ then any remaining
2377 commands in the current execution of +'body'+ are skipped; processing
2378 continues by invoking the Tcl interpreter on +'next'+, then evaluating
2379 +'test'+, and so on.
2381 If a `break` command is invoked within +'body'+ or +'next'+, then the `for`
2382 command will return immediately.
2384 The operation of `break` and `continue` are similar to the corresponding
2385 statements in C.
2387 `for` returns an empty string.
2389 foreach
2390 ~~~~~~~
2391 +*foreach* 'varName list body'+
2393 +*foreach* 'varList list ?varList2 list2 \...? body'+
2395 In this command, +'varName'+ is the name of a variable, +'list'+
2396 is a list of values to assign to +'varName'+, and +'body'+ is a
2397 collection of Tcl commands.
2399 For each field in +'list'+ (in order from left to right), `foreach` assigns
2400 the contents of the field to +'varName'+ (as if the `lindex` command
2401 had been used to extract the field), then calls the Tcl interpreter to
2402 execute +'body'+.
2404 If instead of being a simple name, +'varList'+ is used, multiple assignments
2405 are made each time through the loop, one for each element of +'varList'+.
2407 For example, if there are two elements in +'varList'+ and six elements in
2408 the list, the loop will be executed three times.
2410 If the length of the list doesn't evenly divide by the number of elements
2411 in +'varList'+, the value of the remaining variables in the last iteration
2412 of the loop are undefined.
2414 The `break` and `continue` statements may be invoked inside +'body'+,
2415 with the same effect as in the `for` command.
2417 `foreach` returns an empty string.
2419 format
2420 ~~~~~~
2421 +*format* 'formatString ?arg \...?'+
2423 This command generates a formatted string in the same way as the
2424 C 'sprintf' procedure (it uses 'sprintf' in its
2425 implementation).  +'formatString'+ indicates how to format
2426 the result, using +%+ fields as in 'sprintf', and the additional
2427 arguments, if any, provide values to be substituted into the result.
2429 All of the 'sprintf' options are valid; see the 'sprintf'
2430 man page for details.  Each +'arg'+ must match the expected type
2431 from the +%+ field in +'formatString'+; the `format` command
2432 converts each argument to the correct type (floating, integer, etc.)
2433 before passing it to 'sprintf' for formatting.
2435 The only unusual conversion is for +%c+; in this case the argument
2436 must be a decimal string, which will then be converted to the corresponding
2437 ASCII character value.
2439 `format` does backslash substitution on its +'formatString'+
2440 argument, so backslash sequences in +'formatString'+ will be handled
2441 correctly even if the argument is in braces.
2443 The return value from `format` is the formatted string.
2445 getref
2446 ~~~~~~
2447 +*getref* 'reference'+
2449 Returns the string associated with +'reference'+. The reference must
2450 be a valid reference create with the `ref` command.
2452 See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.
2454 gets
2455 ~~~~
2456 +*gets* 'fileId ?varName?'+
2458 +'fileId' *gets* '?varName?'+
2460 Reads the next line from the file given by +'fileId'+ and discards
2461 the terminating newline character.
2463 If +'varName'+ is specified, then the line is placed in the variable
2464 by that name and the return value is a count of the number of characters
2465 read (not including the newline).
2467 If the end of the file is reached before reading
2468 any characters then -1 is returned and +'varName'+ is set to an
2469 empty string.
2471 If +'varName'+ is not specified then the return value will be
2472 the line (minus the newline character) or an empty string if
2473 the end of the file is reached before reading any characters.
2475 An empty string will also be returned if a line contains no characters
2476 except the newline, so `eof` may have to be used to determine
2477 what really happened.
2479 If the last character in the file is not a newline character, then
2480 `gets` behaves as if there were an additional newline character
2481 at the end of the file.
2483 +'fileId'+ must be +stdin+ or the return value from a previous
2484 call to `open`; it must refer to a file that was opened
2485 for reading.
2487 glob
2488 ~~~~
2489 +*glob* ?*-nocomplain*? 'pattern ?pattern \...?'+
2491 This command performs filename globbing, using csh rules.  The returned
2492 value from `glob` is the list of expanded filenames.
2494 If +-nocomplain+ is specified as the first argument then an empty
2495 list may be returned;  otherwise an error is returned if the expanded
2496 list is empty.  The +-nocomplain+ argument must be provided
2497 exactly: an abbreviation will not be accepted.
2499 global
2500 ~~~~~~
2502 +*global* 'varName ?varName \...?'+
2504 This command is ignored unless a Tcl procedure is being interpreted.
2505 If so, then it declares each given +'varName'+ to be a global variable
2506 rather than a local one.  For the duration of the current procedure
2507 (and only while executing in the current procedure), any reference to
2508 +'varName'+ will be bound to a global variable instead
2509 of a local one.
2511 An alternative to using `global` is to use the +::+ prefix
2512 to explicitly name a variable in the global scope.
2516 +*if* 'expr1' ?*then*? 'body1' *elseif* 'expr2' ?*then*? 'body2' *elseif* \... ?*else*? ?'bodyN'?+
2518 The `if` command evaluates +'expr1'+ as an expression (in the same way
2519 that `expr` evaluates its argument).  The value of the expression must
2520 be numeric; if it is non-zero then +'body1'+ is executed by passing it to
2521 the Tcl interpreter.
2523 Otherwise +'expr2'+ is evaluated as an expression and if it is non-zero
2524 then +'body2'+ is executed, and so on.
2526 If none of the expressions evaluates to non-zero then +'bodyN'+ is executed.
2528 The +then+ and +else+ arguments are optional "noise words" to make the
2529 command easier to read.
2531 There may be any number of +elseif+ clauses, including zero.  +'bodyN'+
2532 may also be omitted as long as +else+ is omitted too.
2534 The return value from the command is the result of the body script that
2535 was executed, or an empty string if none of the expressions was non-zero
2536 and there was no +'bodyN'+.
2538 incr
2539 ~~~~
2540 +*incr* 'varName ?increment?'+
2542 Increment the value stored in the variable whose name is +'varName'+.
2543 The value of the variable must be integral.
2545 If +'increment'+ is supplied then its value (which must be an
2546 integer) is added to the value of variable +'varName'+;  otherwise
2547 1 is added to +'varName'+.
2549 The new value is stored as a decimal string in variable +'varName'+
2550 and also returned as result.
2552 If the variable does not exist, the variable is implicitly created
2553 and set to +0+ first.
2555 info
2556 ~~~~
2558 +*info* 'option ?arg\...?'+::
2560 Provide information about various internals to the Tcl interpreter.
2561 The legal +'option'+'s (which may be abbreviated) are:
2563 +*info args* 'procname'+::
2564     Returns a list containing the names of the arguments to procedure
2565     +'procname'+, in order.  +'procname'+ must be the name of a
2566     Tcl command procedure.
2568 +*info body* 'procname'+::
2569     Returns the body of procedure +'procname'+.  +'procname'+ must be
2570     the name of a Tcl command procedure.
2572 +*info channels*+::
2573     Returns a list of all open file handles from `open` or `socket`
2575 +*info commands* ?'pattern'?+::
2576     If +'pattern'+ isn't specified, returns a list of names of all the
2577     Tcl commands, including both the built-in commands written in C and
2578     the command procedures defined using the `proc` command.
2579     If +'pattern'+ is specified, only those names matching +'pattern'+
2580     are returned.  Matching is determined using the same rules as for
2581     `string match`.
2583 +*info complete* 'command' ?'missing'?+::
2584     Returns 1 if +'command'+ is a complete Tcl command in the sense of
2585     having no unclosed quotes, braces, brackets or array element names,
2586     If the command doesn't appear to be complete then 0 is returned.
2587     This command is typically used in line-oriented input environments
2588     to allow users to type in commands that span multiple lines;  if the
2589     command isn't complete, the script can delay evaluating it until additional
2590     lines have been typed to complete the command. If +'varName'+ is specified, the
2591     missing character is stored in the variable with that name.
2593 +*info exists* 'varName'+::
2594     Returns '1' if the variable named +'varName'+ exists in the
2595     current context (either as a global or local variable), returns '0'
2596     otherwise.
2598 +*info frame* ?'number'?+::
2599     If +'number'+ is not specified, this command returns a number
2600     which is the same result as `info level` - the current stack frame level.
2601     If +'number'+ is specified, then the result is a list consisting of the procedure,
2602     filename and line number for the procedure call at level +'number'+ on the stack.
2603     If +'number'+ is positive then it selects a particular stack level (1 refers
2604     to the top-most active procedure, 2 to the procedure it called, and
2605     so on); otherwise it gives a level relative to the current level
2606     (0 refers to the current procedure, -1 to its caller, and so on).
2607     The level has an identical meaning to `info level`.
2609 +*info globals* ?'pattern'?+::
2610     If +'pattern'+ isn't specified, returns a list of all the names
2611     of currently-defined global variables.
2612     If +'pattern'+ is specified, only those names matching +'pattern'+
2613     are returned.  Matching is determined using the same rules as for
2614     `string match`.
2616 +*info hostname*+::
2617     An alias for `os.gethostname` for compatibility with Tcl 6.x
2619 +*info level* ?'number'?+::
2620     If +'number'+ is not specified, this command returns a number
2621     giving the stack level of the invoking procedure, or 0 if the
2622     command is invoked at top-level.  If +'number'+ is specified,
2623     then the result is a list consisting of the name and arguments for the
2624     procedure call at level +'number'+ on the stack.  If +'number'+
2625     is positive then it selects a particular stack level (1 refers
2626     to the top-most active procedure, 2 to the procedure it called, and
2627     so on); otherwise it gives a level relative to the current level
2628     (0 refers to the current procedure, -1 to its caller, and so on).
2629     See the `uplevel` command for more information on what stack
2630     levels mean.
2632 +*info locals* ?'pattern'?+::
2633     If +'pattern'+ isn't specified, returns a list of all the names
2634     of currently-defined local variables, including arguments to the
2635     current procedure, if any.  Variables defined with the `global`
2636     and `upvar` commands will not be returned.  If +'pattern'+ is
2637     specified, only those names matching +'pattern'+ are returned.
2638     Matching is determined using the same rules as for `string match`.
2640 +*info nameofexecutable*+::
2641     Returns the name of the binary file from which the application
2642     was invoked. A full path will be returned, unless the path
2643     can't be determined, in which case the empty string will be returned.
2645 +*info procs* ?'pattern'?+::
2646     If +'pattern'+ isn't specified, returns a list of all the
2647     names of Tcl command procedures.
2648     If +'pattern'+ is specified, only those names matching +'pattern'+
2649     are returned.  Matching is determined using the same rules as for
2650     `string match`.
2652 +*info references*+::
2653     Returns a list of all references which have not yet been garbage
2654     collected.
2656 +*info returncodes* ?'code'?+::
2657     Returns a list representing the mapping of standard return codes
2658     to names. e.g. +{0 ok 1 error 2 return \...}+. If a code is given,
2659     instead returns the name for the given code.
2661 +*info script*+::
2662     If a Tcl script file is currently being evaluated (i.e. there is a
2663     call to 'Jim_EvalFile' active or there is an active invocation
2664     of the `source` command), then this command returns the name
2665     of the innermost file being processed.  Otherwise the command returns an
2666     empty string.
2668 +*info source* 'script'+::
2669     Returns the original source location of the given script as a list of
2670     +{filename linenumber}+. If the source location can't be determined, the
2671     list +{{} 0}+ is returned.
2673 +*info stacktrace*+::
2674     After an error is caught with `catch`, returns the stack trace as a list
2675     of +{procedure filename line \...}+.
2677 +*info version*+::
2678     Returns the version number for this version of Jim in the form +*x.yy*+.
2680 +*info vars* ?'pattern'?+::
2681     If +'pattern'+ isn't specified,
2682     returns a list of all the names of currently-visible variables, including
2683     both locals and currently-visible globals.
2684     If +'pattern'+ is specified, only those names matching +'pattern'+
2685     are returned.  Matching is determined using the same rules as for
2686     `string match`.
2688 join
2689 ~~~~
2690 +*join* 'list ?joinString?'+
2692 The +'list'+ argument must be a valid Tcl list.  This command returns the
2693 string formed by joining all of the elements of +'list'+ together with
2694 +'joinString'+ separating each adjacent pair of elements.
2696 The +'joinString'+ argument defaults to a space character.
2698 kill
2699 ~~~~
2700 +*kill* ?'SIG'|*-0*? 'pid'+
2702 Sends the given signal to the process identified by +'pid'+.
2704 The signal may be specified by name or number in one of the following forms:
2706 * +TERM+
2707 * +SIGTERM+
2708 * +-TERM+
2709 * +15+
2710 * +-15+
2712 The signal name may be in either upper or lower case.
2714 The special signal name +-0+ simply checks that a signal +'could'+ be sent.
2716 If no signal is specified, SIGTERM is used.
2718 An error is raised if the signal could not be delivered.
2720 lambda
2721 ~~~~~~
2722 +*lambda* 'args ?statics? body'+
2724 The `lambda` command is identical to `proc`, except rather than
2725 creating a named procedure, it creates an anonymous procedure and returns
2726 the name of the procedure.
2728 See `proc` and GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.
2730 lappend
2731 ~~~~~~~
2732 +*lappend* 'varName value ?value value \...?'+
2734 Treat the variable given by +'varName'+ as a list and append each of
2735 the +'value'+ arguments to that list as a separate element, with spaces
2736 between elements.
2738 If +'varName'+ doesn't exist, it is created as a list with elements given
2739 by the +'value'+ arguments. `lappend` is similar to `append` except that
2740 each +'value'+ is appended as a list element rather than raw text.
2742 This command provides a relatively efficient way to build up large lists.
2743 For example,
2745     lappend a $b
2747 is much more efficient than
2749     set a [concat $a [list $b]]
2751 when +$a+ is long.
2753 lassign
2754 ~~~~~~~
2755 +*lassign* 'list varName ?varName \...?'+
2757 This command treats the value +'list'+ as a list and assigns successive elements from that list to
2758 the variables given by the +'varName'+ arguments in order. If there are more variable names than
2759 list elements, the remaining variables are set to the empty string. If there are more list ele-
2760 ments than variables, a list of unassigned elements is returned.
2762     jim> lassign {1 2 3} a b; puts a=$a,b=$b
2763     3
2764     a=1,b=2
2766 local
2767 ~~~~~
2768 +*local* 'args'+
2770 Executes it's arguments as a command (per `eval`) and considers the return
2771 value to be a procedure name, which is marked as having local scope.
2772 This means that when the current procedure exits, the specified
2773 procedure is deleted. This can be useful with `lambda` or simply
2774 local procedures.
2776 In addition, if a command already exists with the same name,
2777 the existing command will be kept rather than deleted, and may be called
2778 via `upcall`. The previous command will be restored when the current
2779 command is deleted. See `upcall` for more details.
2781 In this example, a local procedure is created. Note that the procedure
2782 continues to have global scope while it is active.
2784     proc outer {} {
2785       # proc ... returns "inner" which is marked local
2786       local proc inner {} {
2787         # will be deleted when 'outer' exits
2788       }
2790       inner
2791       ...
2792     }
2794 In this example, the lambda is deleted at the end of the procedure rather
2795 than waiting until garbage collection.
2797     proc outer {} {
2798       set x [lambda inner {args} {
2799         # will be deleted when 'outer' exits
2800       }]
2801       # Use 'function' here which simply returns $x
2802       local function $x
2804       $x ...
2805       ...
2806     }
2808 loop
2809 ~~~~
2810 +*loop* 'var first limit ?incr? body'+
2812 Similar to `for` except simpler and possibly more efficient.
2813 With a positive increment, equivalent to:
2815   for {set var $first} {$var < $limit} {incr var $incr} $body
2817 If +'incr'+ is not specified, 1 is used.
2818 Note that setting the loop variable inside the loop does not
2819 affect the loop count.
2821 lindex
2822 ~~~~~~
2823 +*lindex* 'list index'+
2825 Treats +'list'+ as a Tcl list and returns element +'index'+ from it
2826 (0 refers to the first element of the list).
2827 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
2829 In extracting the element, +'lindex'+ observes the same rules concerning
2830 braces and quotes and backslashes as the Tcl command interpreter; however,
2831 variable substitution and command substitution do not occur.
2833 If +'index'+ is negative or greater than or equal to the number of elements
2834 in +'value'+, then an empty string is returned.
2836 linsert
2837 ~~~~~~~
2838 +*linsert* 'list index element ?element element \...?'+
2840 This command produces a new list from +'list'+ by inserting all
2841 of the +'element'+ arguments just before the element +'index'+
2842 of +'list'+. Each +'element'+ argument will become
2843 a separate element of the new list. If +'index'+ is less than
2844 or equal to zero, then the new elements are inserted at the
2845 beginning of the list. If +'index'+ is greater than or equal
2846 to the number of elements in the list, then the new elements are
2847 appended to the list.
2849 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
2851 list
2852 ~~~~
2854 +*list* 'arg ?arg \...?'+
2856 This command returns a list comprised of all the arguments, +'arg'+. Braces
2857 and backslashes get added as necessary, so that the `lindex` command
2858 may be used on the result to re-extract the original arguments, and also
2859 so that `eval` may be used to execute the resulting list, with
2860 +'arg1'+ comprising the command's name and the other args comprising
2861 its arguments. `list` produces slightly different results than
2862 `concat`:  `concat` removes one level of grouping before forming
2863 the list, while `list` works directly from the original arguments.
2864 For example, the command
2866     list a b {c d e} {f {g h}}
2868 will return
2870     a b {c d e} {f {g h}}
2872 while `concat` with the same arguments will return
2874     a b c d e f {g h}
2876 llength
2877 ~~~~~~~
2878 +*llength* 'list'+
2880 Treats +'list'+ as a list and returns a decimal string giving
2881 the number of elements in it.
2883 lset
2884 ~~~~
2885 +*lset* 'varName ?index ..? newValue'+
2887 Sets an element in a list.
2889 The `lset` command accepts a parameter, +'varName'+, which it interprets
2890 as the name of a variable containing a Tcl list. It also accepts
2891 zero or more indices into the list. Finally, it accepts a new value
2892 for an element of varName. If no indices are presented, the command
2893 takes the form:
2895     lset varName newValue
2897 In this case, newValue replaces the old value of the variable
2898 varName.
2900 When presented with a single index, the `lset` command
2901 treats the content of the varName variable as a Tcl list. It addresses
2902 the index'th element in it (0 refers to the first element of the
2903 list). When interpreting the list, `lset` observes the same rules
2904 concerning braces and quotes and backslashes as the Tcl command
2905 interpreter; however, variable substitution and command substitution
2906 do not occur. The command constructs a new list in which the
2907 designated element is replaced with newValue. This new list is
2908 stored in the variable varName, and is also the return value from
2909 the `lset` command.
2911 If index is negative or greater than or equal to the number of
2912 elements in $varName, then an error occurs.
2914 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
2916 If additional index arguments are supplied, then each argument is
2917 used in turn to address an element within a sublist designated by
2918 the previous indexing operation, allowing the script to alter
2919 elements in sublists. The command,
2921     lset a 1 2 newValue
2923 replaces element 2 of sublist 1 with +'newValue'+.
2925 The integer appearing in each index argument must be greater than
2926 or equal to zero. The integer appearing in each index argument must
2927 be strictly less than the length of the corresponding list. In other
2928 words, the `lset` command cannot change the size of a list. If an
2929 index is outside the permitted range, an error is reported.
2931 lmap
2932 ~~~~
2934 +*lmap* 'varName list body'+
2936 +*lmap* 'varList list ?varList2 list2 \...? body'+
2938 `lmap` is a "collecting" `foreach` which returns a list of its results.
2940 For example:
2942     jim> lmap i {1 2 3 4 5} {expr $i*$i}
2943     1 4 9 16 25
2944     jim> lmap a {1 2 3} b {A B C} {list $a $b}
2945     {1 A} {2 B} {3 C}
2947 If the body invokes `continue`, no value is added for this iteration.
2948 If the body invokes `break`, the loop ends and no more values are added.
2950 load
2951 ~~~~
2952 +*load* 'filename'+
2954 Loads the dynamic extension, +'filename'+. Generally the filename should have
2955 the extension +.so+. The initialisation function for the module must be based
2956 on the name of the file. For example loading +hwaccess.so+ will invoke
2957 the initialisation function, +Jim_hwaccessInit+. Normally the `load` command
2958 should not be used directly. Instead it is invoked automatically by `package require`.
2960 lrange
2961 ~~~~~~
2962 +*lrange* 'list first last'+
2964 +'list'+ must be a valid Tcl list. This command will return a new
2965 list consisting of elements +'first'+ through +'last'+, inclusive.
2967 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
2969 If +'last'+ is greater than or equal to the number of elements
2970 in the list, then it is treated as if it were +end+.
2972 If +'first'+ is greater than +'last'+ then an empty string
2973 is returned.
2975 Note: +"`lrange` 'list first first'"+ does not always produce the
2976 same result as +"`lindex` 'list first'"+ (although it often does
2977 for simple fields that aren't enclosed in braces); it does, however,
2978 produce exactly the same results as +"`list` [`lindex` 'list first']"+
2980 lreplace
2981 ~~~~~~~~
2983 +*lreplace* 'list first last ?element element \...?'+
2985 Returns a new list formed by replacing one or more elements of
2986 +'list'+ with the +'element'+ arguments.
2988 +'first'+ gives the index in +'list'+ of the first element
2989 to be replaced.
2991 If +'first'+ is less than zero then it refers to the first
2992 element of +'list'+;  the element indicated by +'first'+
2993 must exist in the list.
2995 +'last'+ gives the index in +'list'+ of the last element
2996 to be replaced;  it must be greater than or equal to +'first'+.
2998 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
3000 The +'element'+ arguments specify zero or more new arguments to
3001 be added to the list in place of those that were deleted.
3003 Each +'element'+ argument will become a separate element of
3004 the list.
3006 If no +'element'+ arguments are specified, then the elements
3007 between +'first'+ and +'last'+ are simply deleted.
3009 lrepeat
3010 ~~~~~~~~
3011 +*lrepeat* 'number element1 ?element2 \...?'+
3013 Build a list by repeating elements +'number'+ times (which must be
3014 a positive integer).
3016     jim> lrepeat 3 a b
3017     a b a b a b
3019 lreverse
3020 ~~~~~~~~
3021 +*lreverse* 'list'+
3023 Returns the list in reverse order.
3025     jim> lreverse {1 2 3}
3026     3 2 1
3028 lsearch
3029 ~~~~~~~
3030 +*lsearch* '?options? list pattern'+
3032 This command searches the elements +'list'+ to see if one of them matches +'pattern'+. If so, the
3033 command returns the index of the first matching element (unless the options -all, -inline or -bool are
3034 specified.) If not, the command returns -1. The option arguments indicates how the elements of
3035 the list are to be matched against pattern and must have one of the values below:
3037 *Note* that this command is different from Tcl in that default match type is +-exact+ rather than +-glob+.
3039 +'-exact'+::
3040     +'pattern'+ is a literal string that is compared for exact equality against each list element.
3041     This is the default.
3043 +'-glob'+::
3044     +'pattern'+ is a glob-style pattern which is matched against each list element using the same
3045     rules as the string match command.
3047 +'-regexp'+::
3048     +'pattern'+ is treated as a regular expression and matched against each list element using
3049     the rules described by `regexp`.
3051 +'-all'+::
3052     Changes the result to be the list of all matching indices (or all matching values if
3053     +-inline+ is specified as well). If indices are returned, the indices will be in numeric
3054     order. If values are returned, the order of the values will be the order of those values
3055     within the input list.
3057 +'-inline'+::
3058     The matching value is returned instead of its index (or an empty string if no value
3059     matches). If +-all+ is also specified, then the result of the command is the list of all
3060     values that matched. The +-inline+ and +-bool' options are mutually exclusive.
3062 +'-bool'+::
3063     Changes the result to '1' if a match was found, or '0' otherwise. If +-all+ is also specified,
3064     the result will be a list of '0' and '1' for each element of the list depending upon whether
3065     the corresponding element matches. The +-inline+ and +-bool+ options are mutually exclusive.
3067 +'-not'+::
3068     This negates the sense of the match, returning the index (or value
3069     if +-inline+ is specified) of the first non-matching value in the
3070     list. If +-bool+ is also specified, the '0' will be returned if a
3071     match is found, or '1' otherwise. If +-all+ is also specified,
3072     non-matches will be returned rather than matches.
3074 +'-nocase'+::
3075     Causes comparisons to be handled in a case-insensitive manner.
3077 lsort
3078 ~~~~~
3079 +*lsort* ?*-index* 'listindex'? ?*-integer*|*-command* 'cmdname'? ?*-decreasing*|*-increasing*? 'list'+
3081 Sort the elements of +'list'+, returning a new list in sorted order.
3082 By default, ASCII sorting is used, with the result in increasing order.
3084 If +-integer+ is specified, numeric sorting is used.
3086 If +-command 'cmdname'+ is specified, +'cmdname'+ is treated as a command
3087 name. For each comparison, +'cmdname $value1 $value2+' is called which
3088 should compare the values and return an integer less than, equal
3089 to, or greater than zero if the +'$value1'+ is to be considered less
3090 than, equal to, or greater than +'$value2'+, respectively.
3092 If +-decreasing+ is specified, the resulting list is in the opposite
3093 order to what it would be otherwise. +-increasing+ is the default.
3095 If +-index 'listindex'+ is specified, each element of the list is treated as a list and
3096 the given index is extracted from the list for comparison. The list index may
3097 be any valid list index, such as +1+, +end+ or +end-2+.
3099 If +-index 'listindex'+ is specified, each element of the list is treated as a list and
3100 the given index is extracted from the list for comparison. The list index may
3101 be any valid list index, such as +1+, +end+ or +end-2+.
3103 open
3104 ~~~~
3105 +*open* 'fileName ?access?'+
3107 +*open* '|command-pipeline ?access?'+
3109 Opens a file and returns an identifier
3110 that may be used in future invocations
3111 of commands like `read`, `puts`, and `close`.
3112 +'fileName'+ gives the name of the file to open.
3114 The +'access'+ argument indicates the way in which the file is to be accessed.
3115 It may have any of the following values:
3117 +r+::
3118     Open the file for reading only; the file must already exist.
3120 +r\++::
3121     Open the file for both reading and writing; the file must
3122     already exist.
3124 +w+::
3125     Open the file for writing only. Truncate it if it exists. If it doesn't
3126     exist, create a new file.
3128 +w\++::
3129     Open the file for reading and writing. Truncate it if it exists.
3130     If it doesn't exist, create a new file.
3132 +a+::
3133     Open the file for writing only. The file must already exist, and the file
3134     is positioned so that new data is appended to the file.
3136 +a\++::
3137     Open the file for reading and writing. If the file doesn't
3138     exist, create a new empty file. Set the initial access position
3139     to the end of the file.
3141 +'access'+ defaults to 'r'.
3143 If a file is opened for both reading and writing, then `seek`
3144 must be invoked between a read and a write, or vice versa.
3146 If the first character of +'fileName'+ is "|" then the remaining
3147 characters of +'fileName'+ are treated as a list of arguments that
3148 describe a command pipeline to invoke, in the same style as the
3149 arguments for exec. In this case, the channel identifier returned
3150 by open may be used to write to the command's input pipe or read
3151 from its output pipe, depending on the value of +'access'+. If write-only
3152 access is used (e.g. +'access'+ is 'w'), then standard output for the
3153 pipeline is directed to the current standard output unless overridden
3154 by the command. If read-only access is used (e.g. +'access'+ is r),
3155 standard input for the pipeline is taken from the current standard
3156 input unless overridden by the command.
3158 The `pid` command may be used to return the process ids of the commands
3159 forming the command pipeline.
3161 See also `socket`, `pid`, `exec`
3163 package
3164 ~~~~~~~
3165 +*package provide* 'name ?version?'+
3167 Indicates that the current script provides the package named +'name'+.
3168 If no version is specified, '1.0' is used.
3170 Any script which provides a package may include this statement
3171 as the first statement, although it is not required.
3173 +*package require* 'name ?version?'*+
3175 Searches for the package with the given +'name'+ by examining each path
3176 in '$::auto_path' and trying to load '$path/$name.so' as a dynamic extension,
3177 or '$path/$name.tcl' as a script package.
3179 The first such file which is found is considered to provide the the package.
3180 (The version number is ignored).
3182 If '$name.so' exists, it is loaded with the `load` command,
3183 otherwise if '$name.tcl' exists it is loaded with the `source` command.
3185 If `load` or `source` fails, `package require` will fail immediately.
3186 No further attempt will be made to locate the file.
3190 +*pid*+
3192 +*pid* 'fileId'+
3194 The first form returns the process identifier of the current process.
3196 The second form accepts a handle returned by `open` and returns a list
3197 of the process ids forming the pipeline in the same form as `exec ... &`.
3198 If 'fileId' represents a regular file handle rather than a command pipeline,
3199 the empty string is returned instead.
3201 See also `open`, `exec`
3203 proc
3204 ~~~~
3205 +*proc* 'name args ?statics? body'+
3207 The `proc` command creates a new Tcl command procedure, +'name'+.
3208 When the new command is invoked, the contents of +'body'+ will be executed.
3209 Tcl interpreter. +'args'+ specifies the formal arguments to the procedure.
3210 If specified, +'static'+, declares static variables which are bound to the
3211 procedure.
3213 See PROCEDURES for detailed information about Tcl procedures.
3215 The `proc` command returns +'name'+ (which is useful with `local`).
3217 When a procedure is invoked, the procedure's return value is the
3218 value specified in a `return` command.  If the procedure doesn't
3219 execute an explicit `return`, then its return value is the value
3220 of the last command executed in the procedure's body.
3222 If an error occurs while executing the procedure body, then the
3223 procedure-as-a-whole will return that same error.
3225 puts
3226 ~~~~
3227 +*puts* ?*-nonewline*? '?fileId? string'+
3229 +'fileId' *puts* ?*-nonewline*? 'string'+
3231 Writes the characters given by +'string'+ to the file given
3232 by +'fileId'+. +'fileId'+ must have been the return
3233 value from a previous call to `open`, or it may be
3234 +stdout+ or +stderr+ to refer to one of the standard I/O
3235 channels; it must refer to a file that was opened for
3236 writing.
3238 In the first form, if no +'fileId'+ is specified then it defaults to +stdout+.
3239 `puts` normally outputs a newline character after +'string'+,
3240 but this feature may be suppressed by specifying the +-nonewline+
3241 switch.
3243 Output to files is buffered internally by Tcl; the `flush`
3244 command may be used to force buffered characters to be output.
3248 +*pwd*+
3250 Returns the path name of the current working directory.
3252 rand
3253 ~~~~
3254 +*rand* '?min? ?max?'+
3256 Returns a random integer between +'min'+ (defaults to 0) and +'max'+
3257 (defaults to the maximum integer).
3259 If only one argument is given, it is interpreted as +'max'+.
3261 range
3262 ~~~~
3263 +*range* '?start? end ?step?'+
3265 Returns a list of integers starting at +'start'+ (defaults to 0)
3266 and ranging up to but not including +'end'+ in steps of +'step'+ defaults to 1).
3268     jim> range 5
3269     0 1 2 3 4
3270     jim> range 2 5
3271     2 3 4
3272     jim> range 2 10 4
3273     2 6
3274     jim> range 7 4 -2
3275     7 5
3277 read
3278 ~~~~
3279 +*read* ?*-nonewline*? 'fileId'+
3281 +'fileId' *read* ?*-nonewline*?+
3283 +*read* 'fileId numBytes'+
3285 +'fileId' *read* 'numBytes'+
3288 In the first form, all of the remaining bytes are read from the file
3289 given by +'fileId'+; they are returned as the result of the command.
3290 If the +-nonewline+ switch is specified then the last
3291 character of the file is discarded if it is a newline.
3293 In the second form, the extra argument specifies how many bytes to read;
3294 exactly this many bytes will be read and returned, unless there are fewer than
3295 +'numBytes'+ bytes left in the file; in this case, all the remaining
3296 bytes are returned.
3298 +'fileId'+ must be +stdin+ or the return value from a previous call
3299 to `open`; it must refer to a file that was opened for reading.
3301 regexp
3302 ~~~~~~
3303 +*regexp ?-nocase? ?-line? ?-indices? ?-start* 'offset'? *?-all? ?-inline? ?--?* 'exp string ?matchVar? ?subMatchVar subMatchVar \...?'+
3305 Determines whether the regular expression +'exp'+ matches part or
3306 all of +'string'+ and returns 1 if it does, 0 if it doesn't.
3308 See REGULAR EXPRESSIONS above for complete information on the
3309 syntax of +'exp'+ and how it is matched against +'string'+.
3311 If additional arguments are specified after +'string'+ then they
3312 are treated as the names of variables to use to return
3313 information about which part(s) of +'string'+ matched +'exp'+.
3314 +'matchVar'+ will be set to the range of +'string'+ that
3315 matched all of +'exp'+. The first +'subMatchVar'+ will contain
3316 the characters in +'string'+ that matched the leftmost parenthesized
3317 subexpression within +'exp'+, the next +'subMatchVar'+ will
3318 contain the characters that matched the next parenthesized
3319 subexpression to the right in +'exp'+, and so on.
3321 Normally, +'matchVar'+ and the each +'subMatchVar'+ are set to hold the
3322 matching characters from `string`, however see +-indices+ and
3323 +-inline+ below.
3325 If there are more values for +'subMatchVar'+ than parenthesized subexpressions
3326 within +'exp'+, or if a particular subexpression in +'exp'+ doesn't
3327 match the string (e.g. because it was in a portion of the expression
3328 that wasn't matched), then the corresponding +'subMatchVar'+ will be
3329 set to +"-1 -1"+ if +-indices+ has been specified or to an empty
3330 string otherwise.
3332 The following switches modify the behaviour of +'regexp'+
3334 +*-nocase*+::
3335     Causes upper-case and lower-case characters to be treated as
3336     identical during the matching process.
3338 +*-line*+::
3339     Use newline-sensitive matching. By default, newline
3340     is a completely ordinary character with no special meaning in
3341     either REs or strings. With this flag, +[^+ bracket expressions
3342     and +.+ never match newline, a +^+ anchor matches the null
3343     string after any newline in the string in addition to its normal
3344     function, and the +$+ anchor matches the null string before any
3345     newline in the string in addition to its normal function.
3347 +*-indices*+::
3348     Changes what is stored in the subMatchVars. Instead of
3349     storing the matching characters from string, each variable
3350     will contain a list of two decimal strings giving the indices
3351     in string of the first and last characters in the matching
3352     range of characters.
3354 +*-start* 'offset'+::
3355     Specifies a character index offset into the string at which to start
3356     matching the regular expression. If +-indices+ is
3357     specified, the indices will be indexed starting from the
3358     absolute beginning of the input string. +'offset'+ will be
3359     constrained to the bounds of the input string.
3361 +*-all*+::
3362     Causes the regular expression to be matched as many times as possible
3363     in the string, returning the total number of matches found. If this
3364     is specified with match variables, they will contain information
3365     for the last match only.
3367 +*-inline*+::
3368     Causes the command to return, as a list, the data that would otherwise
3369     be placed in match variables. When using +-inline+, match variables
3370     may not be specified. If used with +-all+, the list will be concatenated
3371     at each iteration, such that a flat list is always returned. For
3372     each match iteration, the command will append the overall match
3373     data, plus one element for each subexpression in the regular
3374     expression.
3376 +*--*+::
3377     Marks the end of switches. The argument following this one will be
3378     treated as +'exp'+ even if it starts with a +-+.
3380 regsub
3381 ~~~~~~
3382 +*regsub ?-nocase? ?-all? ?-line? ?-start* 'offset'? ?*--*? 'exp string subSpec ?varName?'+
3384 This command matches the regular expression +'exp'+ against
3385 +'string'+ using the rules described in REGULAR EXPRESSIONS
3386 above.
3388 If +'varName'+ is specified, the commands stores +'string'+ to +'varName'+
3389 with the substitutions detailed below, and returns the number of
3390 substitutions made (normally 1 unless +-all+ is specified).
3391 This is 0 if there were no matches.
3393 If +'varName'+ is not specified, the substituted string will be returned
3394 instead.
3396 When copying +'string'+, the portion of +'string'+ that
3397 matched +'exp'+ is replaced with +'subSpec'+.
3398 If +'subSpec'+ contains a +&+ or +{backslash}0+, then it is replaced
3399 in the substitution with the portion of +'string'+ that
3400 matched +'exp'+.
3402 If +'subSpec'+ contains a +{backslash}n+, where +'n'+ is a digit
3403 between 1 and 9, then it is replaced in the substitution with
3404 the portion of +'string'+ that matched the +''+n+''+-th
3405 parenthesized subexpression of +'exp'+.
3406 Additional backslashes may be used in +'subSpec'+ to prevent special
3407 interpretation of +&+ or +{backslash}0+ or +{backslash}n+ or
3408 backslash.
3410 The use of backslashes in +'subSpec'+ tends to interact badly
3411 with the Tcl parser's use of backslashes, so it's generally
3412 safest to enclose +'subSpec'+ in braces if it includes
3413 backslashes.
3415 The following switches modify the behaviour of +'regsub'+
3417 +*-nocase*+::
3418     Upper-case characters in +'string'+ are converted to lower-case
3419     before matching against +'exp'+;  however, substitutions
3420     specified by +'subSpec'+ use the original unconverted form
3421     of +'string'+.
3423 +*-all*+::
3424     All ranges in +'string'+ that match +'exp'+ are found and substitution
3425     is performed for each of these ranges, rather than only the
3426     first. The +&+ and +{backslash}n+ sequences are handled for
3427     each substitution using the information from the corresponding
3428     match.
3430 +*-line*+::
3431     Use newline-sensitive matching. By default, newline
3432     is a completely ordinary character with no special meaning in
3433     either REs or strings.  With this flag, +[^+ bracket expressions
3434     and +.+ never match newline, a +^+ anchor matches the null
3435     string after any newline in the string in addition to its normal
3436     function, and the +$+ anchor matches the null string before any
3437     newline in the string in addition to its normal function.
3439 +*-start* 'offset'+::
3440     Specifies a character index offset into the string at which to
3441     start matching the regular expression. +'offset'+ will be
3442     constrained to the bounds of the input string.
3444 +*--*+::
3445     Marks the end of switches. The argument following this one will be
3446     treated as +'exp'+ even if it starts with a +-+.
3450 +*ref* 'string tag ?finalizer?'+
3452 Create a new reference containing +'string'+ of type +'tag'+.
3453 If +'finalizer'+ is specified, it is a command which will be invoked
3454 when the a garbage collection cycle runs and this reference is
3455 no longer accessible.
3457 The finalizer is invoked as:
3459   +finalizer 'reference string'+
3461 See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.
3463 rename
3464 ~~~~~~
3465 +*rename* 'oldName newName'+
3467 Rename the command that used to be called +'oldName'+ so that it
3468 is now called +'newName'+.  If +'newName'+ is an empty string
3469 (e.g. {}) then +'oldName'+ is deleted.  The `rename` command
3470 returns an empty string as result.
3472 return
3473 ~~~~~~
3474 +*return* ?*-code* 'code'? ?*-errorinfo* 'stacktrace'? ?*-errorcode* 'errorcode'? ?*-level* 'n'? ?'value'?+
3476 Return immediately from the current procedure (or top-level command
3477 or `source` command), with +'value'+ as the return value.  If +'value'+
3478 is not specified, an empty string will be returned as result.
3480 If +-code+ is specified (as either a number or ok, error, break,
3481 continue, signal, return or exit), this code will be used instead
3482 of +JIM_OK+. This is generally useful when implementing flow of control
3483 commands.
3485 If +-level+ is specified and greater than 1, it has the effect of delaying
3486 the new return code from +-code+. This is useful when rethrowing an error
3487 from `catch`. See the implementation of try/catch in tclcompat.tcl for
3488 an example of how this is done.
3490 Note: The following options are only used when +-code+ is JIM_ERR.
3492 If +-errorinfo+ is specified (as returned from `info stacktrace`)
3493 it is used to initialize the stacktrace.
3495 If +-errorcode+ is specified, it is used to set the global variable $::errorCode.
3497 scan
3498 ~~~~
3499 +*scan* 'string format varName1 ?varName2 \...?'+
3501 This command parses fields from an input string in the same fashion
3502 as the C 'sscanf' procedure.  +'string'+ gives the input to be parsed
3503 and +'format'+ indicates how to parse it, using '%' fields as in
3504 'sscanf'.  All of the 'sscanf' options are valid; see the 'sscanf'
3505 man page for details.  Each +'varName'+ gives the name of a variable;
3506 when a field is scanned from +'string'+, the result is converted back
3507 into a string and assigned to the corresponding +'varName'+.  The
3508 only unusual conversion is for '%c'.  For '%c' conversions a single
3509 character value is converted to a decimal string, which is then
3510 assigned to the corresponding +'varName'+; no field width may be
3511 specified for this conversion.
3513 seek
3514 ~~~~
3515 +*seek* 'fileId offset ?origin?'+
3517 +'fileId' *seek* 'offset ?origin?'+
3519 Change the current access position for +'fileId'+.
3520 The +'offset'+ and +'origin'+ arguments specify the position at
3521 which the next read or write will occur for +'fileId'+.
3522 +'offset'+ must be a number (which may be negative) and +'origin'+
3523 must be one of the following:
3525 +*start*+::
3526     The new access position will be +'offset'+ bytes from the start
3527     of the file.
3529 +*current*+::
3530     The new access position will be +'offset'+ bytes from the current
3531     access position; a negative +'offset'+ moves the access position
3532     backwards in the file.
3534 +*end*+::
3535     The new access position will be +'offset'+ bytes from the end of
3536     the file.  A negative +'offset'+ places the access position before
3537     the end-of-file, and a positive +'offset'+ places the access position
3538     after the end-of-file.
3540 The +'origin'+ argument defaults to +start+.
3542 +'fileId'+ must have been the return value from a previous call to
3543 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
3544 of the standard I/O channels.
3546 This command returns an empty string.
3550 +*set* 'varName ?value?'+
3552 Returns the value of variable +'varName'+.
3554 If +'value'+ is specified, then set the value of +'varName'+ to +'value'+,
3555 creating a new variable if one doesn't already exist, and return
3556 its value.
3558 If +'varName'+ contains an open parenthesis and ends with a
3559 close parenthesis, then it refers to an array element:  the characters
3560 before the open parenthesis are the name of the array, and the characters
3561 between the parentheses are the index within the array.
3562 Otherwise +'varName'+ refers to a scalar variable.
3564 If no procedure is active, then +'varName'+ refers to a global
3565 variable.
3567 If a procedure is active, then +'varName'+ refers to a parameter
3568 or local variable of the procedure, unless the +'global'+ command
3569 has been invoked to declare +'varName'+ to be global.
3571 The +::+ prefix may also be used to explicitly reference a variable
3572 in the global scope.
3574 setref
3575 ~~~~~~
3576 +*setref* 'reference string'+
3578 Store a new string in +'reference'+, replacing the existing string.
3579 The reference must be a valid reference create with the `ref`
3580 command.
3582 See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.
3584 signal
3585 ~~~~~~
3586 Command for signal handling.
3588 See `kill` for the different forms which may be used to specify signals.
3590 Commands which return a list of signal names do so using the canonical form:
3591 "+SIGINT SIGTERM+".
3593 +*signal handle* ?'signals \...'?+::
3594     If no signals are given, returns a list of all signals which are currently
3595     being handled.
3596     If signals are specified, these are added to the list of signals currently
3597     being handled.
3599 +*signal ignore* ?'signals \...'?+::
3600     If no signals are given, returns a lists all signals which are currently
3601     being ignored.
3602     If signals are specified, these are added to the list of signals
3603     currently being ignored. These signals are still delivered, but
3604     are not considered by `catch -signal` or `try -signal`. Use
3605     `signal check` to determine which signals have occurred but
3606     been ignored.
3608 +*signal default* ?'signals \...'?+::
3609     If no signals are given, returns a lists all signals which are currently have
3610     the default behaviour.
3611     If signals are specified, these are added to the list of signals which have
3612     the default behaviour.
3614 +*signal check ?-clear?* ?'signals \...'?+::
3615     Returns a list of signals which have been delivered to the process
3616     but are 'ignored'. If signals are specified, only that set of signals will
3617     be checked, otherwise all signals will be checked.
3618     If +-clear+ is specified, any signals returned are removed and will not be
3619     returned by subsequent calls to `signal check` unless delivered again.
3621 +*signal throw* ?'signal'?+::
3622     Raises the given signal, which defaults to +SIGINT+ if not specified.
3623     The behaviour is identical to:
3625         kill signal [pid]
3627 Note that `signal handle` and `signal ignore` represent two forms of signal
3628 handling. `signal handle` is used in conjunction with `catch -signal` or `try -signal`
3629 to immediately abort execution when the signal is delivered. Alternatively, `signal ignore`
3630 is used in conjunction with `signal check` to handle signal synchronously. Consider the
3631 two examples below.
3633 Prevent a processing from taking too long
3635     signal handle SIGALRM
3636     alarm 20
3637     try -signal {
3638         .. possibly long running process ..
3639         alarm 0
3640     } on signal {sig} {
3641         puts stderr "Process took too long"
3642     }
3644 Handle SIGHUP to reconfigure:
3646     signal ignore SIGHUP
3647     while {1} {
3648         ... handle configuration/reconfiguration ...
3649         while {[signal check -clear SIGHUP] eq ""} {
3650             ... do processing ..
3651         }
3652         # Received SIGHUP, so reconfigure
3653     }
3655 sleep
3656 ~~~~~
3657 +*sleep* 'seconds'+
3659 Pauses for the given number of seconds, which may be a floating
3660 point value less than one to sleep for less than a second, or an
3661 integer to sleep for one or more seconds.
3663 source
3664 ~~~~~~
3665 +*source* 'fileName'+
3667 Read file +'fileName'+ and pass the contents to the Tcl interpreter
3668 as a sequence of commands to execute in the normal fashion.  The return
3669 value of `source` is the return value of the last command executed
3670 from the file.  If an error occurs in executing the contents of the
3671 file, then the `source` command will return that error.
3673 If a `return` command is invoked from within the file, the remainder of
3674 the file will be skipped and the `source` command will return
3675 normally with the result from the `return` command.
3677 split
3678 ~~~~~
3679 +*split* 'string ?splitChars?'+
3681 Returns a list created by splitting +'string'+ at each character
3682 that is in the +'splitChars'+ argument.
3684 Each element of the result list will consist of the
3685 characters from +'string'+ between instances of the
3686 characters in +'splitChars'+.
3688 Empty list elements will be generated if +'string'+ contains
3689 adjacent characters in +'splitChars'+, or if the first or last
3690 character of +'string'+ is in +'splitChars'+.
3692 If +'splitChars'+ is an empty string then each character of
3693 +'string'+ becomes a separate element of the result list.
3695 +'splitChars'+ defaults to the standard white-space characters.
3696 For example,
3698     split "comp.unix.misc" .
3700 returns +'"comp unix misc"'+ and
3702     split "Hello world" {}
3704 returns +'"H e l l o { } w o r l d"'+.
3706 stackdump
3707 ~~~~~~~~~
3709 +*stackdump* 'stacktrace'+
3711 Creates a human readable representation of a stack trace.
3713 stacktrace
3714 ~~~~~~~~~~
3716 +*stacktrace*+
3718 Returns a live stack trace as a list of +proc file line proc file line \...+.
3719 Iteratively uses `info frame` to create the stack trace. This stack trace is in the
3720 same form as produced by `catch` and `info stacktrace`
3722 See also `stackdump`.
3724 string
3725 ~~~~~~
3727 +*string* 'option arg ?arg \...?'+
3729 Perform one of several string operations, depending on +'option'+.
3730 The legal options (which may be abbreviated) are:
3732 +*string bytelength* 'string'+::
3733     Returns the length of the string in bytes. This will return
3734     the same value as `string length` if UTF-8 support is not enabled,
3735     or if the string is composed entirely of ASCII characters.
3736     See UTF-8 AND UNICODE.
3738 +*string byterange* 'string first last'+::
3739     Like `string range` except works on bytes rather than characters.
3740     These commands are identical if UTF-8 support is not enabled.
3742 +*string compare ?-nocase?* 'string1 string2'+::
3743     Perform a character-by-character comparison of strings +'string1'+ and
3744     +'string2'+ in the same way as the C 'strcmp' procedure.  Return
3745     -1, 0, or 1, depending on whether +'string1'+ is lexicographically
3746     less than, equal to, or greater than +'string2'+.
3747     Performs a case-insensitive comparison if +-nocase+ is specified.
3749 +*string equal ?-nocase?* 'string1 string2'+::
3750     Returns 1 if the strings are equal, or 0 otherwise.
3751     Performs a case-insensitive comparison if +-nocase+ is specified.
3753 +*string first* 'string1 string2 ?firstIndex?'+::
3754     Search +'string2'+ for a sequence of characters that exactly match
3755     the characters in +'string1'+.  If found, return the index of the
3756     first character in the first such match within +'string2'+.  If not
3757     found, return -1. If +'firstIndex'+ is specified, matching will start
3758     from +'firstIndex'+ of +'string1'+.
3759  ::
3760     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'firstIndex'+.
3762 +*string index* 'string charIndex'+::
3763     Returns the +'charIndex'+'th character of the +'string'+
3764     argument.  A +'charIndex'+ of 0 corresponds to the first
3765     character of the string.
3766     If +'charIndex'+ is less than 0 or greater than
3767     or equal to the length of the string then an empty string is
3768     returned.
3769  ::
3770     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'charIndex'+.
3772 +*string is* 'class' ?*-strict*? 'string'+::
3773     Returns 1 if +'string'+ is a valid member of the specified character
3774     class, otherwise returns 0. If +-strict+ is specified, then an
3775     empty string returns 0, otherwise an empty string will return 1
3776     on any class. The following character classes are recognized
3777     (the class name can be abbreviated):
3778   ::
3779   +alnum+;;  Any alphabet or digit character.
3780   +alpha+;;  Any alphabet character.
3781   +ascii+;;  Any character with a value less than 128 (those that are in the 7-bit ascii range).
3782   +control+;; Any control character.
3783   +digit+;;  Any digit character.
3784   +double+;; Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
3785              In case of under/overflow in the value, 0 is returned.
3786   +graph+;;  Any printing character, except space.
3787   +integer+;; Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
3788   +lower+;;  Any lower case alphabet character.
3789   +print+;;  Any printing character, including space.
3790   +punct+;;  Any punctuation character.
3791   +space+;;  Any space character.
3792   +upper+;;  Any upper case alphabet character.
3793   +xdigit+;; Any hexadecimal digit character ([0-9A-Fa-f]).
3794  ::
3795     Note that string classification does +'not'+ respect UTF-8. See UTF-8 AND UNICODE
3797 +*string last* 'string1 string2 ?lastIndex?'+::
3798     Search +'string2'+ for a sequence of characters that exactly match
3799     the characters in +'string1'+.  If found, return the index of the
3800     first character in the last such match within +'string2'+.  If there
3801     is no match, then return -1. If +'lastIndex'+ is specified, only characters
3802     up to +'lastIndex'+ of +'string2'+ will be considered in the match.
3803  ::
3804     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'lastIndex'+.
3806 +*string length* 'string'+::
3807     Returns a decimal string giving the number of characters in +'string'+.
3808     If UTF-8 support is enabled, this may be different than the number of bytes.
3809     See UTF-8 AND UNICODE
3811 +*string map ?-nocase?* 'mapping string'+::
3812     Replaces substrings in +'string'+ based on the key-value pairs in
3813     +'mapping'+, which is a list of +key value key value \...+ as in the form
3814     returned by `array get`. Each instance of a key in the string will be
3815     replaced with its corresponding value.  If +-nocase+ is specified, then
3816     matching is done without regard to case differences. Both key and value may
3817     be multiple characters.  Replacement is done in an ordered manner, so the
3818     key appearing first in the list will be checked first, and so on. +'string'+ is
3819     only iterated over once, so earlier key replacements will have no affect for
3820     later key matches. For example,
3822       string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc
3824  ::
3825     will return the string +01321221+.
3826  ::
3827     Note that if an earlier key is a prefix of a later one, it will completely mask the later
3828     one.  So if the previous example is reordered like this,
3830       string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc
3832  ::
3833     it will return the string +02c322c222c+.
3835 +*string match ?-nocase?* 'pattern string'+::
3836     See if +'pattern'+ matches +'string'+; return 1 if it does, 0
3837     if it doesn't.  Matching is done in a fashion similar to that
3838     used by the C-shell.  For the two strings to match, their contents
3839     must be identical except that the following special sequences
3840     may appear in +'pattern'+:
3842     +*+;;
3843         Matches any sequence of characters in +'string'+,
3844         including a null string.
3846     +?+;;
3847         Matches any single character in +'string'+.
3849     +['chars']+;;
3850         Matches any character in the set given by +'chars'+.
3851         If a sequence of the form +'x-y'+ appears in +'chars'+,
3852         then any character between +'x'+ and +'y'+, inclusive,
3853         will match.
3855     +{backslash}x+;;
3856         Matches the single character +'x'+.  This provides a way of
3857         avoiding the special interpretation of the characters +{backslash}*?[]+
3858         in +'pattern'+.
3859  ::
3860     Performs a case-insensitive comparison if +-nocase+ is specified.
3862 +*string range* 'string first last'+::
3863     Returns a range of consecutive characters from +'string'+, starting
3864     with the character whose index is +'first'+ and ending with the
3865     character whose index is +'last'+.  An index of 0 refers to the
3866     first character of the string.
3867  ::
3868     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
3869  ::
3870     If +'first'+ is less than zero then it is treated as if it were zero, and
3871     if +'last'+ is greater than or equal to the length of the string then
3872     it is treated as if it were +end+.  If +'first'+ is greater than
3873     +'last'+ then an empty string is returned.
3875 +*string repeat* 'string count'+::
3876     Returns a new string consisting of +'string'+ repeated +'count'+ times.
3878 +*string reverse* 'string'+::
3879     Returns a string that is the same length as +'string'+ but
3880     with its characters in the reverse order.
3882 +*string tolower* 'string'+::
3883     Returns a value equal to +'string'+ except that all upper case
3884     letters have been converted to lower case.
3886 +*string toupper* 'string'+::
3887     Returns a value equal to +'string'+ except that all lower case
3888     letters have been converted to upper case.
3890 +*string trim* 'string ?chars?'+::
3891     Returns a value equal to +'string'+ except that any leading
3892     or trailing characters from the set given by +'chars'+ are
3893     removed.
3894     If +'chars'+ is not specified then white space is removed
3895     (spaces, tabs, newlines, and carriage returns).
3897 +*string trimleft* 'string ?chars?'+::
3898     Returns a value equal to +'string'+ except that any
3899     leading characters from the set given by +'chars'+ are
3900     removed.
3901     If +'chars'+ is not specified then white space is removed
3902     (spaces, tabs, newlines, and carriage returns).
3904 +*string trimright* 'string ?chars?'+::
3905     Returns a value equal to +'string'+ except that any
3906     trailing characters from the set given by +'chars'+ are
3907     removed.
3908     If +'chars'+ is not specified then white space is removed
3909     (spaces, tabs, newlines, and carriage returns).
3910     Null characters are always removed.
3912 subst
3913 ~~~~~
3914 +*subst ?-nobackslashes? ?-nocommands? ?-novariables?* 'string'+
3916 This command performs variable substitutions, command substitutions,
3917 and backslash substitutions on its string argument and returns the
3918 fully-substituted result. The substitutions are performed in exactly
3919 the same way as for Tcl commands. As a result, the string argument
3920 is actually substituted twice, once by the Tcl parser in the usual
3921 fashion for Tcl commands, and again by the subst command.
3923 If any of the +-nobackslashes+, +-nocommands+, or +-novariables+ are
3924 specified, then the corresponding substitutions are not performed.
3925 For example, if +-nocommands+ is specified, no command substitution
3926 is performed: open and close brackets are treated as ordinary
3927 characters with no special interpretation.
3929 *Note*: when it performs its substitutions, subst does not give any
3930 special treatment to double quotes or curly braces. For example,
3931 the following script returns +xyz \{44\}+, not +xyz \{$a\}+.
3933     set a 44
3934     subst {xyz {$a}}
3937 switch
3938 ~~~~~~
3939 +*switch* '?options? string pattern body ?pattern body \...?'+
3941 +*switch* '?options? string {pattern body ?pattern body \...?}'+
3943 The `switch` command matches its string argument against each of
3944 the pattern arguments in order. As soon as it finds a pattern that
3945 matches string it evaluates the following body and returns the
3946 result of that evaluation. If the last pattern argument is default
3947 then it matches anything. If no pattern argument matches string and
3948 no default is given, then the `switch` command returns an empty string.
3949 If the initial arguments to switch start with - then they are treated
3950 as options. The following options are currently supported:
3952     +-exact+::
3953         Use exact matching when comparing string to a
3954         pattern. This is the default.
3956     +-glob+::
3957         When matching string to the patterns, use glob-style
3958         matching (i.e. the same as implemented by the string
3959         match command).
3961     +-regexp+::
3962         When matching string to the patterns, use regular
3963         expression matching (i.e. the same as implemented
3964         by the regexp command).
3966     +-command 'commandname'+::
3967         When matching string to the patterns, use the given command, which
3968         must be a single word. The command is invoked as
3969         'commandname pattern string', or 'commandname -nocase pattern string'
3970         and must return 1 if matched, or 0 if not.
3972     +--+::
3973         Marks the end of options. The argument following
3974         this one will be treated as string even if it starts
3975         with a +-+.
3977 Two syntaxes are provided for the pattern and body arguments. The
3978 first uses a separate argument for each of the patterns and commands;
3979 this form is convenient if substitutions are desired on some of the
3980 patterns or commands. The second form places all of the patterns
3981 and commands together into a single argument; the argument must
3982 have proper list structure, with the elements of the list being the
3983 patterns and commands. The second form makes it easy to construct
3984 multi-line `switch` commands, since the braces around the whole list
3985 make it unnecessary to include a backslash at the end of each line.
3986 Since the pattern arguments are in braces in the second form, no
3987 command or variable substitutions are performed on them; this makes
3988 the behaviour of the second form different than the first form in
3989 some cases.
3991 If a body is specified as +-+ it means that the body for the next
3992 pattern should also be used as the body for this pattern (if the
3993 next pattern also has a body of +-+ then the body after that is
3994 used, and so on). This feature makes it possible to share a single
3995 body among several patterns.
3997 Below are some examples of `switch` commands:
3999     switch abc a - b {format 1} abc {format 2} default {format 3}
4001 will return 2,
4003     switch -regexp aaab {
4004            ^a.*b$ -
4005            b {format 1}
4006            a* {format 2}
4007            default {format 3}
4008     }
4010 will return 1, and
4012     switch xyz {
4013            a -
4014            b {format 1}
4015            a* {format 2}
4016            default {format 3}
4017     }
4019 will return 3.
4021 tailcall
4022 ~~~~~~~~
4023 +*tailcall* 'cmd ?arg\...?'+
4025 The `tailcall` command provides an optimised way of invoking a command whilst replacing
4026 the current call frame. This is similar to 'exec' in Bourne Shell.
4028 The following are identical except the first immediately replaces the current call frame.
4030   tailcall a b c
4032   return [uplevel 1 a b c]
4034 `tailcall` is useful for a dispatch mechanism:
4036   proc a {cmd args} {
4037     tailcall sub_$cmd {*}$args
4038   }
4039   proc sub_cmd1 ...
4040   proc sub_cmd2 ...
4042 tell
4043 ~~~~
4044 +*tell* 'fileId'+
4046 +'fileId' *tell*+
4048 Returns a decimal string giving the current access position in
4049 +'fileId'+.
4051 +'fileId'+ must have been the return value from a previous call to
4052 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
4053 of the standard I/O channels.
4055 throw
4056 ~~~~~
4057 +*throw* 'code ?msg?'+
4059 This command throws an exception (return) code along with an optional message.
4060 This command is mostly for convenient usage with `try`.
4062 The command +throw break+ is equivalent to +break+.
4063 The command +throw 20 message+ can be caught with an +on 20 \...+ clause to `try`.
4065 time
4066 ~~~~
4067 +*time* 'command ?count?'+
4069 This command will call the Tcl interpreter +'count'+
4070 times to execute +'command'+ (or once if +'count'+ isn't
4071 specified).  It will then return a string of the form
4073     503 microseconds per iteration
4075 which indicates the average amount of time required per iteration,
4076 in microseconds.
4078 Time is measured in elapsed time, not CPU time.
4082 +*try* '?catchopts? tryscript' ?*on* 'returncodes {?resultvar? ?optsvar?} handlerscript \...'? ?*finally* 'finalscript'?+
4084 The `try` command is provided as a convenience for exception handling.
4086 This interpeter first evaluates +'tryscript'+ under the effect of the catch
4087 options +'catchopts'+ (e.g. +-signal -noexit --+, see `catch`).
4089 It then evaluates the script for the first matching 'on' handler
4090 (there many be zero or more) based on the return code from the `try`
4091 section. For example a normal +JIM_ERR+ error will be matched by
4092 an 'on error' handler.
4094 Finally, any +'finalscript'+ is evaluated.
4096 The result of this command is the result of +'tryscript'+, except in the
4097 case where an exception occurs in a matching 'on' handler script or the 'finally' script,
4098 in which case the result is this new exception.
4100 The specified +'returncodes'+ is a list of return codes either as names ('ok', 'error', 'break', etc.)
4101 or as integers.
4103 If +'resultvar'+ and +'optsvar'+ are specified, they are set as for `catch` before evaluating
4104 the matching handler.
4106 For example:
4108     set f [open input]
4109     try -signal {
4110         process $f
4111     } on {continue break} {} {
4112         error "Unexpected break/continue"
4113     } on error {msg opts} {
4114         puts "Dealing with error"
4115         return {*}$opts $msg
4116     } on signal sig {
4117         puts "Got signal: $sig"
4118     } finally {
4119         $f close
4120     }
4122 If break, continue or error are raised, they are dealt with by the matching
4123 handler.
4125 In any case, the file will be closed via the 'finally' clause.
4127 See also `throw`, `catch`, `return`, `error`.
4129 unknown
4130 ~~~~~~~
4131 +*unknown* 'cmdName ?arg arg ...?'+
4133 This command doesn't actually exist as part of Tcl, but Tcl will
4134 invoke it if it does exist.
4136 If the Tcl interpreter encounters a command name for which there
4137 is not a defined command, then Tcl checks for the existence of
4138 a command named `unknown`.
4140 If there is no such command, then the interpreter returns an
4141 error.
4143 If the `unknown` command exists, then it is invoked with
4144 arguments consisting of the fully-substituted name and arguments
4145 for the original non-existent command.
4147 The `unknown` command typically does things like searching
4148 through library directories for a command procedure with the name
4149 +'cmdName'+, or expanding abbreviated command names to full-length,
4150 or automatically executing unknown commands as UNIX sub-processes.
4152 In some cases (such as expanding abbreviations) `unknown` will
4153 change the original command slightly and then (re-)execute it.
4154 The result of the `unknown` command is used as the result for
4155 the original non-existent command.
4157 unset
4158 ~~~~~
4159 +*unset ?-nocomplain? ?--?* '?name name ...?'+
4161 Remove variables.
4162 Each +'name'+ is a variable name, specified in any of the
4163 ways acceptable to the `set` command.
4165 If a +'name'+ refers to an element of an array, then that
4166 element is removed without affecting the rest of the array.
4168 If a +'name'+ consists of an array name with no parenthesized
4169 index, then the entire array is deleted.
4171 The `unset` command returns an empty string as result.
4173 An error occurs if any of the variables doesn't exist, unless '-nocomplain'
4174 is specified. The '--' argument may be specified to stop option processing
4175 in case the variable name may be '-nocomplain'.
4177 upcall
4178 ~~~~~~~
4179 +*upcall* 'command ?args ...?'+
4181 May be used from within a proc defined as `local` `proc` in order to call
4182 the previous, hidden version of the same command.
4184 If there is no previous definition of the command, an error is returned.
4186 uplevel
4187 ~~~~~~~
4188 +*uplevel* '?level? command ?command ...?'+
4190 All of the +'command'+ arguments are concatenated as if they had
4191 been passed to `concat`; the result is then evaluated in the
4192 variable context indicated by +'level'+.  `uplevel` returns
4193 the result of that evaluation.  If +'level'+ is an integer, then
4194 it gives a distance (up the procedure calling stack) to move before
4195 executing the command.  If +'level'+ consists of +\#+ followed by
4196 a number then the number gives an absolute level number.  If +'level'+
4197 is omitted then it defaults to +1+.  +'level'+ cannot be
4198 defaulted if the first +'command'+ argument starts with a digit or +#+.
4200 For example, suppose that procedure 'a' was invoked
4201 from top-level, and that it called 'b', and that 'b' called 'c'.
4202 Suppose that 'c' invokes the `uplevel` command.  If +'level'+
4203 is +1+ or +#2+  or omitted, then the command will be executed
4204 in the variable context of 'b'.  If +'level'+ is +2+ or +#1+
4205 then the command will be executed in the variable context of 'a'.
4207 If +'level'+ is '3' or +#0+ then the command will be executed
4208 at top-level (only global variables will be visible).
4209 The `uplevel` command causes the invoking procedure to disappear
4210 from the procedure calling stack while the command is being executed.
4211 In the above example, suppose 'c' invokes the command
4213     uplevel 1 {set x 43; d}
4215 where 'd' is another Tcl procedure.  The `set` command will
4216 modify the variable 'x' in 'b's context, and 'd' will execute
4217 at level 3, as if called from 'b'.  If it in turn executes
4218 the command
4220     uplevel {set x 42}
4222 then the `set` command will modify the same variable 'x' in 'b's
4223 context:  the procedure 'c' does not appear to be on the call stack
4224 when 'd' is executing.  The command `info level` may
4225 be used to obtain the level of the current procedure.
4227 `uplevel` makes it possible to implement new control
4228 constructs as Tcl procedures (for example, `uplevel` could
4229 be used to implement the `while` construct as a Tcl procedure).
4231 upvar
4232 ~~~~~
4233 +*upvar* '?level? otherVar myVar ?otherVar myVar ...?'+
4235 This command arranges for one or more local variables in the current
4236 procedure to refer to variables in an enclosing procedure call or
4237 to global variables.
4239 +'level'+ may have any of the forms permitted for the `uplevel`
4240 command, and may be omitted if the first letter of the first +'otherVar'+
4241 isn't +#+ or a digit (it defaults to '1').
4243 For each +'otherVar'+ argument, `upvar` makes the variable
4244 by that name in the procedure frame given by +'level'+ (or at
4245 global level, if +'level'+ is +#0+) accessible
4246 in the current procedure by the name given in the corresponding
4247 +'myVar'+ argument.
4249 The variable named by +'otherVar'+ need not exist at the time of the
4250 call;  it will be created the first time +'myVar'+ is referenced, just like
4251 an ordinary variable.
4253 `upvar` may only be invoked from within procedures.
4255 `upvar` returns an empty string.
4257 The `upvar` command simplifies the implementation of call-by-name
4258 procedure calling and also makes it easier to build new control constructs
4259 as Tcl procedures.
4260 For example, consider the following procedure:
4262     proc add2 name {
4263         upvar $name x
4264         set x [expr $x+2]
4265     }
4267 'add2' is invoked with an argument giving the name of a variable,
4268 and it adds two to the value of that variable.
4269 Although 'add2' could have been implemented using `uplevel`
4270 instead of `upvar`, `upvar` makes it simpler for 'add2'
4271 to access the variable in the caller's procedure frame.
4273 while
4274 ~~~~~
4275 +*while* 'test body'+
4277 The +'while'+ command evaluates +'test'+ as an expression
4278 (in the same way that `expr` evaluates its argument).
4279 The value of the expression must be numeric; if it is non-zero
4280 then +'body'+ is executed by passing it to the Tcl interpreter.
4282 Once +'body'+ has been executed then +'test'+ is evaluated
4283 again, and the process repeats until eventually +'test'+
4284 evaluates to a zero numeric value.  `continue`
4285 commands may be executed inside +'body'+ to terminate the current
4286 iteration of the loop, and `break`
4287 commands may be executed inside +'body'+ to cause immediate
4288 termination of the `while` command.
4290 The `while` command always returns an empty string.
4292 OPTIONAL-EXTENSIONS
4293 -------------------
4295 The following extensions may or may not be available depending upon
4296 what options were selected when Jim Tcl was built.
4298 [[cmd_1]]
4299 posix: os.fork, os.wait, os.gethostname, os.getids, os.uptime
4300 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4301 +*os.fork*+::
4302     Invokes 'fork(2)' and returns the result.
4304 +*os.wait -nohang* 'pid'+::
4305     Invokes waitpid(2), with WNOHANG if +-nohang+ is specified.
4306     Returns a list of 3 elements.
4308    {0 none 0} if -nohang is specified, and the process is still alive.
4310    {-1 error <error-description>} if the process does not exist or has already been waited for.
4312    {<pid> exit <exit-status>} if the process exited normally.
4314    {<pid> signal <signal-number>} if the process terminated on a signal.
4316    {<pid> other 0} otherwise (core dump, stopped, continued, etc.)
4318 +*os.gethostname*+::
4319     Invokes 'gethostname(3)' and returns the result.
4321 +*os.getids*+::
4322     Returns the various user/group ids for the current process.
4324     jim> os.getids
4325     uid 1000 euid 1000 gid 100 egid 100
4327 +*os.uptime*+::
4328     Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.
4330 ANSI I/O (aio) and EVENTLOOP API
4331 --------------------------------
4332 Jim provides an alternative object-based API for I/O.
4334 See `open` and `socket` for commands which return an I/O handle.
4338 +$handle *read ?-nonewline?* '?len?'+::
4339     Read and return bytes from the stream. To eof if no len.
4341 +$handle *gets* '?var?'+::
4342     Read one line and return it or store it in the var
4344 +$handle *puts ?-nonewline?* 'str'+::
4345     Write the string, with newline unless -nonewline
4347 +$handle *copyto* 'tofd ?size?'+::
4348     Copy bytes to the file descriptor +'tofd'+. If +'size'+ is specified, at most
4349     that many bytes will be copied. Otherwise copying continues until the end
4350     of the input file. Returns the number of bytes actually copied.
4352 +$handle *flush*+::
4353     Flush the stream
4355 +$handle *filename*+::
4356     Returns the original filename associated with the handle.
4357     Handles returned by `socket` give the socket type instead of a filename.
4359 +$handle *eof*+::
4360     Returns 1 if stream is at eof
4362 +$handle *close*+::
4363     Closes the stream
4365 +$handle *seek* 'offset' *?start|current|end?*+::
4366     Seeks in the stream (default 'current')
4368 +$handle *tell*+::
4369     Returns the current seek position
4371 +$handle *filename*+::
4372     Returns the original filename used when opening the file.
4373     If the handle was returned from `socket`, the type of the
4374     handle is returned instead.
4376 +$handle *ndelay ?0|1?*+::
4377     Set O_NDELAY (if arg). Returns current/new setting.
4378     Note that in general ANSI I/O interacts badly with non-blocking I/O.
4379     Use with care.
4381 +$handle *buffering none|line|full*+::
4382     Sets the buffering mode of the stream.
4384 +$handle *accept*+::
4385     Server socket only: Accept a connection and return stream
4387 +$handle *sendto* 'str ?hostname:?port'+::
4388     Sends the string, +'str'+, to the given address via the socket using sendto(2).
4389     This is intended for udp sockets and may give an error or behave in unintended
4390     ways for other handle types.
4391     Returns the number of bytes written.
4393 +$handle *recvfrom* 'maxlen ?addrvar?'+::
4394     Receives a message from the handle via recvfrom(2) and returns it.
4395     At most +'maxlen'+ bytes are read.
4396     If +'addrvar'+ is specified, the sending address of the message is stored in
4397     the named variable in the form 'addr:port'. See `socket` for details.
4399 fconfigure
4400 ~~~~~~~~~~
4401 +*fconfigure* 'handle' *?-blocking 0|1? ?-buffering noneline|full? ?-translation* 'mode'?+::
4402     For compatibility with Tcl, a limited form of the `fconfigure`
4403     command is supported.
4404     * `fconfigure ... -blocking` maps to `aio ndelay`
4405     * `fconfigure ... -buffering` maps to `aio buffering`
4406     * `fconfigure ... -translation` is accepted but ignored
4408 [[cmd_2]]
4409 eventloop: after, vwait, update
4410 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4412 The following commands allow a script to be invoked when the given condition occurs.
4413 If no script is given, returns the current script. If the given script is the empty, the
4414 handler is removed.
4416 +$handle *readable* '?readable-script?'+::
4417     Sets or returns the script for when the socket is readable.
4419 +$handle *writable* '?writable-script?'+::
4420     Sets or returns the script for when the socket is writable.
4422 +$handle *onexception* '?exception-script?'+::
4423     Sets or returns the script for when when oob data received.
4425 For compatibility with 'Tcl', these may be prefixed with `fileevent`.  e.g.
4427  ::
4428     +fileevent $handle *readable* '\...'+
4430 Time-based execution is also available via the eventloop API.
4432 +*after* 'ms'+::
4433     Sleeps for the given number of milliseconds. No events are
4434     processed during this time.
4436 +*after* 'ms'|*idle* script ?script \...?'+::
4437     The scripts are concatenated and executed after the given
4438     number of milliseconds have elapsed.  If 'idle' is specified,
4439     the script will run the next time the event loop is processed
4440     with `vwait` or `update`. The script is only run once and
4441     then removed.  Returns an event id.
4443 +*after cancel* 'id|command'+::
4444     Cancels an `after` event with the given event id or matching
4445     command (script).  Returns the number of milliseconds
4446     remaining until the event would have fired.  Returns the
4447     empty string if no matching event is found.
4449 +*after info* '?id?'+::
4450     If +'id'+ is not given, returns a list of current `after`
4451     events.  If +'id'+ is given, returns a list containing the
4452     associated script and either 'timer' or 'idle' to indicated
4453     the type of the event. An error occurs if +'id'+ does not
4454     match an event.
4456 +*vwait* 'variable'+::
4457     A call to `vwait` is enters the eventloop. `vwait` processes
4458     events until the named (global) variable changes or all
4459     event handlers are removed. The variable need not exist
4460     beforehand.  If there are no event handlers defined, `vwait`
4461     returns immediately.
4463 +*update ?idletasks?*+::
4464     A call to `update` enters the eventloop to process expired events, but
4465     no new events. If 'idletasks' is specified, only expired time events are handled,
4466     not file events.
4467     Returns once handlers have been run for all expired events.
4469 Scripts are executed at the global scope. If an error occurs during a handler script,
4470 an attempt is made to call (the user-defined command) `bgerror` with the details of the error.
4471 If the `bgerror` commands does not exist, it is printed to stderr instead.
4473 If a file event handler script generates an error, the handler is automatically removed
4474 to prevent infinite errors. (A time event handler is always removed after execution).
4476 +*bgerror* 'error'+::
4477     Called when an event handler script generates an error.
4479 socket
4480 ~~~~~~
4481 Various socket types may be created.
4483 +*socket unix* 'path'+::
4484     A unix domain socket client.
4486 +*socket unix.server* 'path'+::
4487     A unix domain socket server.
4489 +*socket ?-ipv6? stream* 'addr:port'+::
4490     A TCP socket client.
4492 +*socket ?-ipv6? stream.server* '?addr:?port'+::
4493     A TCP socket server (+'addr'+ defaults to +0.0.0.0+ for IPv4 or +[::]+ for IPv6).
4495 +*socket ?-ipv6? dgram* ?'addr:port'?+::
4496     A UDP socket client. If the address is not specified,
4497     the client socket will be unbound and 'sendto' must be used
4498     to indicated the destination.
4500 +*socket ?-ipv6? dgram.server* 'addr:port'+::
4501     A UDP socket server.
4503 +*socket pipe*+::
4504     A pipe. Note that unlike all other socket types, this command returns
4505     a list of two channels: {read write}
4507 This command creates a socket connected (client) or bound (server) to the given
4508 address.
4510 The returned value is channel and may generally be used with the various file I/O
4511 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.
4513     set f [socket stream www.google.com:80]
4514     aio.sockstream1
4515     $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
4516     $f gets
4517     HTTP/1.0 302 Found
4518     $f close
4520 Server sockets, however support only 'accept', which is most useful in conjunction with
4521 the EVENTLOOP API.
4523     set f [socket stream.server 80]
4524     $f readable {
4525         set client [$f accept]
4526         $client gets $buf
4527         ...
4528         $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
4529         $client close
4530     }
4531     vwait done
4533 The address, +'addr'+, can be given in one of the following forms:
4535 1. For IPv4 socket types, an IPv4 address such as 192.168.1.1
4536 2. For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
4537 3. A hostname
4539 Note that on many systems, listening on an IPv6 address such as [::] will
4540 also accept requests via IPv4.
4542 Where a hostname is specified, the +'first'+ returned address is used
4543 which matches the socket type is used.
4545 The special type 'pipe' isn't really a socket.
4547     lassign [socket pipe] r w
4549     # Must close $w after exec
4550     exec ps >@$w &
4551     $w close
4553     $r readable ...
4555 syslog
4556 ~~~~~~
4557 +*syslog* '?options? ?priority? message'+
4559 This  command sends message to system syslog facility with given
4560 priority. Valid priorities are:
4562     emerg, alert, crit, err, error, warning, notice, info, debug
4564 If a message is specified, but no priority is specified, then a
4565 priority of info is used.
4567 By default, facility user is used and the value of global tcl variable
4568 argv0 is used as ident string. However, any of the following options
4569 may be specified before priority to control these parameters:
4571 +*-facility* 'value'+::
4572     Use specified facility instead of user. The following
4573     values for facility are recognized:
4575     authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
4576     uucp, local0-local7
4578 +*-ident* 'string'+::
4579     Use given string instead of argv0 variable for ident string.
4581 +*-options* 'integer'+::
4582     Set syslog options such as +LOG_CONS+, +LOG_NDELAY+. You should
4583     use numeric values of those from your system syslog.h file,
4584     because I haven't got time to implement yet another hash
4585     table.
4587 pack: pack, unpack
4588 ~~~~~~~~~~~~~~~~~~
4589 The optional 'pack' extension provides commands to encode and decode binary strings.
4591 +*pack* 'varName value' *-intle|-intbe|-str* 'bitwidth ?bitoffset?'+::
4592     Packs the binary representation of +'value'+ into the variable
4593     +'varName'+. The value is packed according to the given type
4594     (integer/string, big-endian/little-endian), width and bit offset.
4595     The variable is created if necessary (like `append`).
4596     Ihe variable is expanded if necessary.
4598 +*unpack* 'binvalue' *-intbe|-intle|-uintbe|-uintle|-str* 'bitpos bitwidth'+::
4599     Unpacks bits from +'binvalue'+ at bit position +'bitpos'+ and with +'bitwidth'+.
4600     Interprets the value according to the type (integer/string, big-endian/little-endian
4601     and signed/unsigned) and returns it. For integer types, +'bitwidth'+
4602     may be up to the size of a Jim Tcl integer (typically 64 bits). For the string type,
4603     both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
4604     access outside the length of the value will return 0 for integer types or the empty string
4605     for the string type.
4607 binary
4608 ~~~~~~
4609 The optional, pure-Tcl 'binary' extension provides the Tcl-compatible `binary scan` and `binary format`
4610 commands based on the low-level `pack` and `unpack` commands.
4612 See the Tcl documentation at: http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm
4614 Note that packing and unpacking of floating point values is not supported.
4616 oo: class, super
4617 ~~~~~~~~~~~~~~~~
4618 The optional, pure-Tcl 'oo' extension provides object-oriented (OO) support for Jim Tcl.
4620 See the online documentation (http://jim.berlios.de/documentation/oo/) for more details.
4622 +*class* 'classname ?baseclasses? classvars'+::
4623     Create a new class, +'classname'+, with the given dictionary
4624     (+'classvars'+) as class variables. These are the initial variables
4625     which all newly created objects of this class are initialised with.
4626     If a list of baseclasses is given, methods and instance variables
4627     are inherited.
4629 +*super* 'method ?args \...?'+::
4630     From within a method, invokes the given method on the base class.
4631     Note that this will only call the last baseclass given.
4633 tree
4634 ~~~~
4635 The optional, pure-Tcl 'tree' extension implements an OO, general purpose tree structure
4636 similar to that provided by tcllib ::struct::tree (http://tcllib.sourceforge.net/doc/struct_tree.html)
4638 A tree is a collection of nodes, where each node (except the root node) has a single parent
4639 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.
4641 +*tree*+::
4642     Creates and returns a new tree object with a single node named "root".
4643     All operations on the tree are invoked through this object.
4645 +$tree *destroy*+::
4646     Destroy the tree and all it's nodes. (Note that the the tree will also
4647     be automatically garbage collected once it goes out of scope).
4649 +$tree *set* 'nodename key value'+::
4650     Set the value for the given attribute key.
4652 +$tree *lappend* 'nodename key value \...'+::
4653     Append to the (list) value(s) for the given attribute key, or set if not yet set.
4655 +$tree *keyexists* 'nodename key'+::
4656     Returns 1 if the given attribute key exists.
4658 +$tree *get* 'nodename key'+::
4659     Returns the value associated with the given attribute key.
4661 +$tree *getall* 'nodename'+::
4662     Returns the entire attribute dictionary associated with the given key.
4664 +$tree *depth* 'nodename'+::
4665     Returns the depth of the given node. The depth of "root" is 0.
4667 +$tree *parent* 'nodename'+::
4668     Returns the node name of the parent node, or "" for the root node.
4670 +$tree *numchildren* 'nodename'+::
4671     Returns the number of child nodes.
4673 +$tree *children* 'nodename'+::
4674     Returns a list of the child nodes.
4676 +$tree *next* 'nodename'+::
4677     Returns the next sibling node, or "" if none.
4679 +$tree *insert* 'nodename ?index?'+::
4680     Add a new child node to the given node. The index is a list index
4681     such as +3+ or +end-2+. The default index is +end+.
4682     Returns the name of the newly added node.
4684 +$tree *walk* 'nodename' *dfs|bfs* {'actionvar nodevar'} 'script'+::
4685     Walks the tree starting from the given node, either breadth first (+bfs+)
4686     depth first (+dfs+).
4687     The value +"enter"+ or +"exit"+ is stored in variable +'actionvar'+.
4688     The name of each node is stored in +'nodevar'+.
4689     The script is evaluated twice for each node, on entry and exit.
4691 +$tree *dump*+::
4692     Dumps the tree contents to stdout
4694 [[BuiltinVariables]]
4695 BUILT-IN VARIABLES
4696 ------------------
4698 The following global variables are created automatically
4699 by the Tcl library.
4701 +*env*+::
4702     This variable is set by Jim as an array
4703     whose elements are the environment variables for the process.
4704     Reading an element will return the value of the corresponding
4705     environment variable.
4706     This array is initialised at startup from the `env` command.
4707     It may be modified and will affect the environment passed to
4708     commands invoked with `exec`.
4710 +*platform_tcl*+::
4711     This variable is set by Jim as an array containing information
4712     about the platform on which Jim was built. Currently this includes
4713     'os' and 'platform'.
4715 +*auto_path*+::
4716     This variable contains a list of paths to search for packages.
4717     It defaults to a location based on where jim is installed
4718     (e.g. +/usr/local/lib/jim+), but may be changed by +jimsh+
4719     or the embedding application. Note that +jimsh+ will consider
4720     the environment variable +$JIMLIB+ to be a list of colon-separated
4721     list of paths to add to +*auto_path*+.
4723 +*errorCode*+::
4724     This variable holds the value of the -errorcode return
4725     option set by the most recent error that occurred in this
4726     interpreter. This list value represents additional information
4727     about the error in a form that is easy to process with
4728     programs. The first element of the list identifies a general
4729     class of errors, and determines the format of the rest of
4730     the list. The following formats for -errorcode return options
4731     are used by the Tcl core; individual applications may define
4732     additional formats. Currently only `exec` sets this variable.
4733     Otherwise it will be +NONE+.
4735 The following global variables are set by jimsh.
4737 +*tcl_interactive*+::
4738     This variable is set to 1 if jimsh is started in interactive mode
4739     or 0 otherwise.
4741 +*tcl_platform*+::
4742     This variable is set by Jim as an array containing information
4743     about the platform upon which Jim was built. The following is an
4744     example of the contents of this array.
4746     tcl_platform(byteOrder)     = littleEndian
4747     tcl_platform(os)            = Darwin
4748     tcl_platform(platform)      = unix
4749     tcl_platform(pointerSize)   = 8
4750     tcl_platform(threaded)      = 0
4751     tcl_platform(wordSize)      = 8
4752     tcl_platform(pathSeparator) = :
4754 +*argv0*+::
4755     If jimsh is invoked to run a script, this variable contains the name
4756     of the script.
4758 +*argv*+::
4759     If jimsh is invoked to run a script, this variable contains a list
4760     of any arguments supplied to the script.
4762 +*argc*+::
4763     If jimsh is invoked to run a script, this variable contains the number
4764     of arguments supplied to the script.
4766 +*jim_argv0*+::
4767     The value of argv[0] when jimsh was invoked.
4769 CHANGES IN PREVIOUS RELEASES
4770 ----------------------------
4772 === In v0.63 ===
4774 1. `source` now checks that a script is complete (.i.e. not missing a brace)
4775 2. 'info complete' now uses the real parser and so is 100% accurate
4776 3. Better access to live stack frames with 'info frame', `stacktrace` and `stackdump`
4777 4. `tailcall` no longer loses stack trace information
4778 5. Add `alias` and `curry`
4779 6. `lambda`, `alias` and `curry` are implemented via `tailcall` for efficiency
4780 7. `local` allows procedures to be deleted automatically at the end of the current procedure
4781 8. udp sockets are now supported for both clients and servers.
4782 9. vfork-based exec is now working correctly
4783 10. Add 'file tempfile'
4784 11. Add 'socket pipe'
4785 12. Enhance 'try ... on ... finally' to be more Tcl 8.6 compatible
4786 13. It is now possible to `return` from within `try`
4787 14. IPv6 support is now included
4788 15. Add 'string is'
4789 16. Event handlers works better if an error occurs. eof handler has been removed.
4790 17. `exec` now sets $::errorCode, and catch sets opts(-errorcode) for exit status
4791 18. Command pipelines via open "|..." are now supported
4792 19. `pid` can now return pids of a command pipeline
4793 20. Add 'info references'
4794 21. Add support for 'after +'ms'+', 'after idle', 'after info', `update`
4795 22. `exec` now sets environment based on $::env
4796 23. Add 'dict keys'
4797 24. Add support for 'lsort -index'
4799 === In v0.62 ===
4801 1. Add support to `exec` for '>&', '>>&', '|&', '2>@1'
4802 2. Fix `exec` error messages when special token (e.g. '>') is the last token
4803 3. Fix `subst` handling of backslash escapes.
4804 4. Allow abbreviated options for `subst`
4805 5. Add support for `return`, `break`, `continue` in subst
4806 6. Many `expr` bug fixes
4807 7. Add support for functions in `expr` (e.g. int(), abs()), and also 'in', 'ni' list operations
4808 8. The variable name argument to `regsub` is now optional
4809 9. Add support for 'unset -nocomplain'
4810 10. Add support for list commands: `lassign`, `lrepeat`
4811 11. Fully-functional `lsearch` is now implemented
4812 12. Add 'info nameofexecutable' and 'info returncodes'
4813 13. Allow `catch` to determine what return codes are caught
4814 14. Allow `incr` to increment an unset variable by first setting to 0
4815 15. Allow 'args' and optional arguments to the left or required arguments in `proc`
4816 16. Add 'file copy'
4817 17. Add 'try ... finally' command
4820 LICENCE
4821 -------
4823  Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
4824  Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
4825  Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
4826  Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
4827  Copyright 2008 Andrew Lunn <andrew@lunn.ch>
4828  Copyright 2008 Duane Ellis <openocd@duaneellis.com>
4829  Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
4830  Copyright 2009 Steve Bennett <steveb@workware.net.au>
4832 [literal]
4833  Redistribution and use in source and binary forms, with or without
4834  modification, are permitted provided that the following conditions
4835  are met:
4836  1. Redistributions of source code must retain the above copyright
4837     notice, this list of conditions and the following disclaimer.
4838  2. Redistributions in binary form must reproduce the above
4839     copyright notice, this list of conditions and the following
4840     disclaimer in the documentation and/or other materials
4841     provided with the distribution.
4843  THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
4844  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
4845  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
4846  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
4847  JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
4848  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
4849  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4850  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4851  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4852  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4853  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
4854  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4856  The views and conclusions contained in the software and documentation
4857  are those of the authors and should not be interpreted as representing
4858  official policies, either expressed or implied, of the Jim Tcl Project.