docs: Fix typo in unix domain datagram support
[jimtcl.git] / jim_tcl.txt
blob77c4b357393ce51a1746ad956d4ab04de98bd027
1 Jim Tcl(n)
2 ==========
4 NAME
5 ----
6 Jim Tcl v0.78+ - reference manual for the Jim Tcl scripting language
8 SYNOPSIS
9 --------
11   cc <source> -ljim
15   jimsh [<scriptfile>|-]
16   jimsh -e '<immediate-script>'
17   jimsh --version
18   jimsh --help
21 .Quick Index
22 * <<CommandIndex,Command Reference>>
23 * <<OperatorPrecedence,Operator Precedence>>
24 * <<BuiltinVariables, Builtin Variables>>
25 * <<BackslashSequences, Backslash Sequences>>
27 INTRODUCTION
28 ------------
29 Jim Tcl is a small footprint reimplementation of the Tcl scripting language.
30 The core language engine is compatible with Tcl 8.5+, while implementing
31 a significant subset of the Tcl 8.6 command set, plus additional features
32 available only in Jim Tcl.
34 Some notable differences with Tcl 8.5/8.6 are:
36 1. Object-based I/O (aio), but with a Tcl-compatibility layer
37 2. I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
38 3. Integers are 64bit
39 4. Support for references (`ref`/`getref`/`setref`) and garbage collection
40 5. Builtin dictionary type (`dict`) with some limitations compared to Tcl 8.6
41 6. `env` command to access environment variables
42 7. Operating system features: `os.fork`, `os.uptime`, `wait`, `signal`, `alarm`, `sleep`
43 8. Much better error reporting. `info stacktrace` as a replacement for '$errorInfo', '$errorCode'
44 9. Support for "static" variables in procedures
45 10. Threads and coroutines are not supported
46 11. Command and variable traces are not supported
47 12. Built-in command line editing
48 13. Expression shorthand syntax: +$(...)+
49 14. Modular build allows many features to be omitted or built as dynamic, loadable modules
50 15. Highly suitable for use in an embedded environment
51 16. Support for UDP, IPv6, Unix-Domain sockets in addition to TCP sockets
53 RECENT CHANGES
54 --------------
55 Changes since 0.78
56 ~~~~~~~~~~~~~~~~~~
57 1. Add `file mtimeus` for high resolution file timestamps
58 2. `aio` now supports datagram Unix-Domain sockets
60 Changes between 0.77 and 0.78
61 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62 1. Add serial/tty support with `aio tty`
63 2. Add support for 'jimsh -'
64 3. Add hidden '-commands' option to many commands
65 4. Add scriptable autocompletion support in interactive mode with `tcl::autocomplete`
66 5. Add `aio sockopt`
67 6. Add scriptable autocompletion support with `history completion`
68 7. Add support for `tree delete`
69 8. Add support for `defer` and '$jim::defer'
70 9. Renamed `os.wait` to `wait`, now more Tcl-compatible and compatible with `exec ... &`
71 10. `pipe` is now a synonym for `socket pipe`
72 11. Closing a pipe open with `open |...` now returns Tcl-like status
73 12. It is now possible to used `exec` redirection with a pipe opened with `open |...`
74 13. Interactive line editing now supports multiline mode if $::history::multiline is set
76 Changes between 0.76 and 0.77
77 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78 1. Add support for `aio sync`
79 2. Add SSL and TLS support in aio
80 3. Added `zlib`
81 4. Added support for boolean constants in `expr`
82 5. `string is` now supports 'boolean' class
83 6. Add support for `aio lock` and `aio unlock`
84 7. Add new `interp` command
86 Changes between 0.75 and 0.76
87 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88 1. `glob` now supports the +-tails+ option
89 2. Add support for `string cat`
90 3. Allow `info source` to add source info
92 Changes between 0.74 and 0.75
93 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94 1. `binary`, `pack` and `unpack` now support floating point
95 2. `file copy` +-force+ handles source and target as the same file
96 3. `format` now supports +%b+ for binary conversion
97 4. `lsort` now supports +-unique+ and +-real+
98 5. Add support for half-close with `aio close` +?r|w?+
99 6. Add `socket pair` for a bidirectional pipe
100 7. Add '--random-hash' to randomise hash tables for greater security
101 8. `dict` now supports 'for', 'values', 'incr', 'append', 'lappend', 'update', 'info' and 'replace'
102 9. `file stat` no longer requires the variable name
103 10. Add support for `file link`
105 Changes between 0.73 and 0.74
106 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107 1. Numbers with leading zeros are treated as decimal, not octal
108 2. Add `aio isatty`
109 3. Add LFS (64 bit) support for `aio seek`, `aio tell`, `aio copyto`, `file copy`
110 4. `string compare` and `string equal` now support '-length'
111 5. `glob` now supports '-directory'
113 Changes between 0.72 and 0.73
114 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115 1. Built-in regexp now support non-capturing parentheses: (?:...)
116 2. Add `string replace`
117 3. Add `string totitle`
118 4. Add `info statics`
119 5. Add +build-jim-ext+ for easy separate building of loadable modules (extensions)
120 6. `local` now works with any command, not just procs
121 7. Add `info alias` to access the target of an alias
122 8. UTF-8 encoding past the basic multilingual plane (BMP) is supported
123 9. Add `tcl::prefix`
124 10. Add `history`
125 11. Most extensions are now enabled by default
126 12. Add support for namespaces and the `namespace` command
127 13. Add `apply`
129 Changes between 0.71 and 0.72
130 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131 1. procs now allow 'args' and optional parameters in any position
132 2. Add Tcl-compatible expr functions, `rand()`, `srand()` and `pow()`
133 3. Add support for the '-force' option to `file delete`
134 4. Better diagnostics when `source` fails to load a script with a missing quote or bracket
135 5. New +tcl_platform(pathSeparator)+
136 6. Add support settings the modification time with `file mtime`
137 7. `exec` is now fully supported on win32 (mingw32)
138 8. `file join`, `pwd`, `glob` etc. now work for mingw32
139 9. Line editing is now supported for the win32 console (mingw32)
140 10. Add `aio listen` command
142 Changes between 0.70 and 0.71
143 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144 1. Allow 'args' to be renamed in procs
145 2. Add +$(...)+ shorthand syntax for expressions
146 3. Add automatic reference variables in procs with +&var+ syntax
147 4. Support +jimsh --version+
148 5. Additional variables in +tcl_platform()+
149 6. `local` procs now push existing commands and `upcall` can call them
150 7. Add `loop` command (TclX compatible)
151 8. Add `aio buffering` command
152 9. `info complete` can now return the missing character
153 10. `binary format` and `binary scan` are now (optionally) supported
154 11. Add `string byterange`
155 12. Built-in regexp now support non-greedy repetition (*?, +?, ??)
157 TCL INTRODUCTION
158 -----------------
159 Tcl stands for 'tool command language' and is pronounced
160 'http://www.oxforddictionaries.com/definition/american_english/tickle[tickle]'.
161 It is actually two things: a language and a library.
163 First, Tcl is a simple textual language, intended primarily for
164 issuing commands to interactive programs such as text editors,
165 debuggers, illustrators, and shells.  It has a simple syntax and is also
166 programmable, so Tcl users can write command procedures to provide more
167 powerful commands than those in the built-in set.
169 Second, Tcl is a library package that can be embedded in application
170 programs.  The Tcl library consists of a parser for the Tcl language,
171 routines to implement the Tcl built-in commands, and procedures that
172 allow each application to extend Tcl with additional commands specific
173 to that application.  The application program generates Tcl commands and
174 passes them to the Tcl parser for execution.  Commands may be generated
175 by reading characters from an input source, or by associating command
176 strings with elements of the application's user interface, such as menu
177 entries, buttons, or keystrokes.
179 When the Tcl library receives commands it parses them into component
180 fields and executes built-in commands directly.  For commands implemented
181 by the application, Tcl calls back to the application to execute the
182 commands.  In many cases commands will invoke recursive invocations of the
183 Tcl interpreter by passing in additional strings to execute (procedures,
184 looping commands, and conditional commands all work in this way).
186 An application program gains three advantages by using Tcl for its command
187 language.  First, Tcl provides a standard syntax:  once users know Tcl,
188 they will be able to issue commands easily to any Tcl-based application.
189 Second, Tcl provides programmability.  All a Tcl application needs
190 to do is to implement a few application-specific low-level commands.
191 Tcl provides many utility commands plus a general programming interface
192 for building up complex command procedures.  By using Tcl, applications
193 need not re-implement these features.
195 Third, Tcl can be used as a common language for communicating between
196 applications.  Inter-application communication is not built into the
197 Tcl core described here, but various add-on libraries, such as the Tk
198 toolkit, allow applications to issue commands to each other.  This makes
199 it possible for applications to work together in much more powerful ways
200 than was previously possible.
202 Fourth, Jim Tcl includes a command processor, +jimsh+, which can be
203 used to run standalone Tcl scripts, or to run Tcl commands interactively.
205 This manual page focuses primarily on the Tcl language.  It describes
206 the language syntax and the built-in commands that will be available
207 in any application based on Tcl.  The individual library procedures are
208 described in more detail in separate manual pages, one per procedure.
210 JIMSH COMMAND INTERPRETER
211 -------------------------
212 A simple, but powerful command processor, +jimsh+, is part of Jim Tcl.
213 It may be invoked in interactive mode as:
215   jimsh
217 or to process the Tcl script in a file with:
219   jimsh filename
221 or to process the Tcl script from standard input:
223   jimsh -
225 It may also be invoked to execute an immediate script with:
227   jimsh -e "script"
229 Interactive Mode
230 ~~~~~~~~~~~~~~~~
231 Interactive mode reads Tcl commands from standard input, evaluates
232 those commands and prints the results.
234   $ jimsh
235   Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
236   . info version
237   0.73
238   . lsort [info commands p*]
239   package parray pid popen proc puts pwd
240   . foreach i {a b c} {
241   {> puts $i
242   {> }
243   a
244   b
245   c
246   . bad
247   invalid command name "bad"
248   [error] . exit
249   $
251 If +jimsh+ is configured with line editing (it is by default) and a VT-100-compatible
252 terminal is detected, Emacs-style line editing commands are available, including:
253 arrow keys, +\^W+ to erase a word, +\^U+ to erase the line, +^R+ for reverse incremental search
254 in history. Additionally, the +h+ command may be used to display the command history.
256 Command line history is automatically saved and loaded from +~/.jim_history+
258 In interactive mode, +jimsh+ automatically runs the script +~/.jimrc+ at startup
259 if it exists.
261 INTERPRETERS
262 ------------
263 The central data structure in Tcl is an interpreter (C type 'Jim_Interp').
264 An interpreter consists of a set of command bindings, a set of variable
265 values, and a few other miscellaneous pieces of state.  Each Tcl command
266 is interpreted in the context of a particular interpreter.
268 Some Tcl-based applications will maintain multiple interpreters
269 simultaneously, each associated with a different widget or portion of
270 the application.  Interpreters are relatively lightweight structures.
271 They can be created and deleted quickly, so application programmers should
272 feel free to use multiple interpreters if that simplifies the application.
274 DATA TYPES
275 ----------
276 Tcl supports only one type of data:  strings.  All commands, all arguments
277 to commands, all command results, and all variable values are strings.
279 Where commands require numeric arguments or return numeric results,
280 the arguments and results are passed as strings.  Many commands expect
281 their string arguments to have certain formats, but this interpretation
282 is up to the individual commands.  For example, arguments often contain
283 Tcl command strings, which may get executed as part of the commands.
284 The easiest way to understand the Tcl interpreter is to remember that
285 everything is just an operation on a string.  In many cases Tcl constructs
286 will look similar to more structured constructs from other languages.
287 However, the Tcl constructs are not structured at all; they are just
288 strings of characters, and this gives them a different behaviour than
289 the structures they may look like.
291 Although the exact interpretation of a Tcl string depends on who is doing
292 the interpretation, there are three common forms that strings take:
293 commands, expressions, and lists.  The major sections below discuss
294 these three forms in more detail.
296 BASIC COMMAND SYNTAX
297 --------------------
298 The Tcl language has syntactic similarities to both the Unix shells
299 and Lisp.  However, the interpretation of commands is different
300 in Tcl than in either of those other two systems.
301 A Tcl command string consists of one or more commands separated
302 by newline characters or semi-colons.
303 Each command consists of a collection of fields separated by
304 white space (spaces or tabs).
305 The first field must be the name of a command, and the
306 additional fields, if any, are arguments that will be passed to
307 that command.  For example, the command:
309     set a 22
311 has three fields:  the first, `set`, is the name of a Tcl command, and
312 the last two, 'a' and '22', will be passed as arguments to
313 the `set` command.  The command name may refer either to a built-in
314 Tcl command, an application-specific command bound in with the library
315 procedure 'Jim_CreateCommand', or a command procedure defined with the
316 `proc` built-in command.
318 Arguments are passed literally as text strings.  Individual commands may
319 interpret those strings in any fashion they wish.  The `set` command,
320 for example, will treat its first argument as the name of a variable
321 and its second argument as a string value to assign to that variable.
322 For other commands arguments may be interpreted as integers, lists,
323 file names, or Tcl commands.
325 Command names should normally be typed completely (e.g. no abbreviations).
326 However, if the Tcl interpreter cannot locate a command it invokes a
327 special command named `unknown` which attempts to find or create the
328 command.
330 For example, at many sites `unknown` will search through library
331 directories for the desired command and create it as a Tcl procedure if
332 it is found.  The `unknown` command often provides automatic completion
333 of abbreviated commands, but usually only for commands that were typed
334 interactively.
336 It's probably a bad idea to use abbreviations in command scripts and
337 other forms that will be re-used over time:  changes to the command set
338 may cause abbreviations to become ambiguous, resulting in scripts that
339 no longer work.
341 COMMENTS
342 --------
343 If the first non-blank character in a command is +\#+, then everything
344 from the +#+ up through the next newline character is treated as
345 a comment and ignored.  When comments are embedded inside nested
346 commands (e.g. fields enclosed in braces) they must have properly-matched
347 braces (this is necessary because when Tcl parses the top-level command
348 it doesn't yet know that the nested field will be used as a command so
349 it cannot process the nested comment character as a comment).
351 GROUPING ARGUMENTS WITH DOUBLE-QUOTES
352 -------------------------------------
353 Normally each argument field ends at the next white space, but
354 double-quotes may be used to create arguments with embedded space.
356 If an argument field begins with a double-quote, then the argument isn't
357 terminated by white space (including newlines) or a semi-colon (see below
358 for information on semi-colons); instead it ends at the next double-quote
359 character.  The double-quotes are not included in the resulting argument.
360 For example, the command
362     set a "This is a single argument"
364 will pass two arguments to `set`:  'a' and 'This is a single argument'.
366 Within double-quotes, command substitutions, variable substitutions,
367 and backslash substitutions still occur, as described below.  If the
368 first character of a command field is not a quote, then quotes receive
369 no special interpretation in the parsing of that field.
371 GROUPING ARGUMENTS WITH BRACES
372 ------------------------------
373 Curly braces may also be used for grouping arguments.  They are similar
374 to quotes except for two differences.  First, they nest; this makes them
375 easier to use for complicated arguments like nested Tcl command strings.
376 Second, the substitutions described below for commands, variables, and
377 backslashes do *not* occur in arguments enclosed in braces, so braces
378 can be used to prevent substitutions where they are undesirable.
380 If an argument field begins with a left brace, then the argument ends
381 at the matching right brace.  Tcl will strip off the outermost layer
382 of braces and pass the information between the braces to the command
383 without any further modification.  For example, in the command
385     set a {xyz a {b c d}}
387 the `set` command will receive two arguments: 'a'
388 and 'xyz a {b c d}'.
390 When braces or quotes are in effect, the matching brace or quote need
391 not be on the same line as the starting quote or brace; in this case
392 the newline will be included in the argument field along with any other
393 characters up to the matching brace or quote.  For example, the `eval`
394 command takes one argument, which is a command string; `eval` invokes
395 the Tcl interpreter to execute the command string.  The command
397     eval {
398       set a 22
399       set b 33
400     }
402 will assign the value '22' to 'a' and '33' to 'b'.
404 If the first character of a command field is not a left
405 brace, then neither left nor right
406 braces in the field will be treated specially (except as part of
407 variable substitution; see below).
409 COMMAND SUBSTITUTION WITH BRACKETS
410 ----------------------------------
411 If an open bracket occurs in a field of a command, then command
412 substitution occurs (except for fields enclosed in braces).  All of the
413 text up to the matching close bracket is treated as a Tcl command and
414 executed immediately.  Then the result of that command is substituted
415 for the bracketed text.  For example, consider the command
417     set a [set b]
419 When the `set` command has only a single argument, it is the name of a
420 variable and `set` returns the contents of that variable.  In this case,
421 if variable 'b' has the value 'foo', then the command above is equivalent
422 to the command
424     set a foo
426 Brackets can be used in more complex ways.  For example, if the variable
427 'b' has the value 'foo' and the variable 'c' has the value 'gorp',
428 then the command
430     set a xyz[set b].[set c]
432 is equivalent to the command
434     set a xyzfoo.gorp
437 A bracketed command may contain multiple commands separated by newlines
438 or semi-colons in the usual fashion.  In this case the value of the last
439 command is used for substitution.  For example, the command
441     set a x[set b 22
442     expr $b+2]x
444 is equivalent to the command
446     set a x24x
449 If a field is enclosed in braces then the brackets and the characters
450 between them are not interpreted specially; they are passed through to
451 the argument verbatim.
453 VARIABLE SUBSTITUTION WITH $
454 ----------------------------
455 The dollar sign (+$+) may be used as a special shorthand form for
456 substituting variable values.  If +$+ appears in an argument that isn't
457 enclosed in braces then variable substitution will occur.  The characters
458 after the +$+, up to the first character that isn't a number, letter,
459 or underscore, are taken as a variable name and the string value of that
460 variable is substituted for the name.
462 For example, if variable 'foo' has the value 'test', then the command
464     set a $foo.c
466 is equivalent to the command
468     set a test.c
470 There are two special forms for variable substitution.  If the next
471 character after the name of the variable is an open parenthesis, then
472 the variable is assumed to be an array name, and all of the characters
473 between the open parenthesis and the next close parenthesis are taken as
474 an index into the array.  Command substitutions and variable substitutions
475 are performed on the information between the parentheses before it is
476 used as an index.
478 For example, if the variable 'x' is an array with one element named
479 'first' and value '87' and another element named '14' and value 'more',
480 then the command
482     set a xyz$x(first)zyx
484 is equivalent to the command
486     set a xyz87zyx
488 If the variable 'index' has the value '14', then the command
490     set a xyz$x($index)zyx
492 is equivalent to the command
494     set a xyzmorezyx
496 For more information on arrays, see VARIABLES AND ARRAYS below.
498 The second special form for variables occurs when the dollar sign is
499 followed by an open curly brace.  In this case the variable name consists
500 of all the characters up to the next curly brace.
502 Array references are not possible in this form:  the name between braces
503 is assumed to refer to a scalar variable.  For example, if variable
504 'foo' has the value 'test', then the command
506     set a abc${foo}bar
508 is equivalent to the command
510     set a abctestbar
513 Variable substitution does not occur in arguments that are enclosed in
514 braces:  the dollar sign and variable name are passed through to the
515 argument verbatim.
517 The dollar sign abbreviation is simply a shorthand form.  +$a+ is
518 completely equivalent to +[set a]+; it is provided as a convenience
519 to reduce typing.
521 SEPARATING COMMANDS WITH SEMI-COLONS
522 ------------------------------------
523 Normally, each command occupies one line (the command is terminated by a
524 newline character).  However, semi-colon (+;+) is treated as a command
525 separator character; multiple commands may be placed on one line by
526 separating them with a semi-colon.  Semi-colons are not treated as
527 command separators if they appear within curly braces or double-quotes.
529 BACKSLASH SUBSTITUTION
530 ----------------------
531 Backslashes may be used to insert non-printing characters into command
532 fields and also to insert special characters like braces and brackets
533 into fields without them being interpreted specially as described above.
535 The backslash sequences understood by the Tcl interpreter are
536 listed below.  In each case, the backslash
537 sequence is replaced by the given character:
538 [[BackslashSequences]]
539 +{backslash}b+::
540     Backspace (0x8)
542 +{backslash}f+::
543     Form feed (0xc)
545 +{backslash}n+::
546     Newline (0xa)
548 +{backslash}r+::
549     Carriage-return (0xd).
551 +{backslash}t+::
552     Tab (0x9).
554 +{backslash}v+::
555     Vertical tab (0xb).
557 +{backslash}{+::
558     Left brace ({).
560 +{backslash}}+::
561     Right brace (}).
563 +{backslash}[+::
564     Open bracket ([).
566 +{backslash}]+::
567     Close bracket (]).
569 +{backslash}$+::
570     Dollar sign ($).
572 +{backslash}<space>+::
573     Space ( ): doesn't terminate argument.
575 +{backslash};+::
576     Semi-colon: doesn't terminate command.
578 +{backslash}"+::
579     Double-quote.
581 +{backslash}<newline>+::
582     Nothing:  this joins two lines together
583     into a single line.  This backslash feature is unique in that
584     it will be applied even when the sequence occurs within braces.
586 +{backslash}{backslash}+::
587     Backslash ('{backslash}').
589 +{backslash}ddd+::
590     The digits +'ddd'+ (one, two, or three of them) give the octal value of
591     the character.  Note that Jim supports null characters in strings.
593 +{backslash}unnnn+::
594 +{backslash}u\{nnn\}+::
595 +{backslash}Unnnnnnnn+::
596     The UTF-8 encoding of the unicode codepoint represented by the hex digits, +'nnnn'+, is inserted.
597     The 'u' form allows for one to four hex digits.
598     The 'U' form allows for one to eight hex digits.
599     The 'u\{nnn\}' form allows for one to eight hex digits, but makes it easier to insert
600     characters UTF-8 characters which are followed by a hex digit.
602 For example, in the command
604     set a \{x\[\ yz\141
606 the second argument to `set` will be +{x[ yza+.
608 If a backslash is followed by something other than one of the options
609 described above, then the backslash is transmitted to the argument
610 field without any special processing, and the Tcl scanner continues
611 normal processing with the next character.  For example, in the
612 command
614     set \*a \\\{foo
616 The first argument to `set` will be +{backslash}*a+ and the second
617 argument will be +{backslash}{foo+.
619 If an argument is enclosed in braces, then backslash sequences inside
620 the argument are parsed but no substitution occurs (except for
621 backslash-newline):  the backslash
622 sequence is passed through to the argument as is, without making
623 any special interpretation of the characters in the backslash sequence.
624 In particular, backslashed braces are not counted in locating the
625 matching right brace that terminates the argument.
626 For example, in the
627 command
629     set a {\{abc}
631 the second argument to `set` will be +{backslash}{abc+.
633 This backslash mechanism is not sufficient to generate absolutely
634 any argument structure; it only covers the
635 most common cases.  To produce particularly complicated arguments
636 it is probably easiest to use the `format` command along with
637 command substitution.
639 STRING AND LIST INDEX SPECIFICATIONS
640 ------------------------------------
642 Many string and list commands take one or more 'index' parameters which
643 specify a position in the string relative to the start or end of the string/list.
645 The index may be one of the following forms:
647 +integer+::
648     A simple integer, where '0' refers to the first element of the string
649     or list.
651 +integer+integer+ or::
652 +integer-integer+::
653     The sum or difference of the two integers. e.g. +2+3+ refers to the 5th element.
654     This is useful when used with (e.g.) +$i+1+ rather than the more verbose
655     +[expr {$i+1\}]+
657 +end+::
658     The last element of the string or list.
660 +end-integer+::
661     The 'nth-from-last' element of the string or list.
663 COMMAND SUMMARY
664 ---------------
665 1. A command is just a string.
666 2. Within a string commands are separated by newlines or semi-colons
667    (unless the newline or semi-colon is within braces or brackets
668    or is backslashed).
669 3. A command consists of fields.  The first field is the name of the command.
670    The other fields are strings that are passed to that command as arguments.
671 4. Fields are normally separated by white space.
672 5. Double-quotes allow white space and semi-colons to appear within
673    a single argument.
674    Command substitution, variable substitution, and backslash substitution
675    still occur inside quotes.
676 6. Braces defer interpretation of special characters.
677    If a field begins with a left brace, then it consists of everything
678    between the left brace and the matching right brace. The
679    braces themselves are not included in the argument.
680    No further processing is done on the information between the braces
681    except that backslash-newline sequences are eliminated.
682 7. If a field doesn't begin with a brace then backslash,
683    variable, and command substitution are done on the field.  Only a
684    single level of processing is done:  the results of one substitution
685    are not scanned again for further substitutions or any other
686    special treatment.  Substitution can
687    occur on any field of a command, including the command name
688    as well as the arguments.
689 8. If the first non-blank character of a command is a +\#+, everything
690    from the +#+ up through the next newline is treated as a comment
691    and ignored.
693 EXPRESSIONS
694 -----------
695 The second major interpretation applied to strings in Tcl is
696 as expressions.  Several commands, such as `expr`, `for`,
697 and `if`, treat one or more of their arguments as expressions
698 and call the Tcl expression processors ('Jim_ExprLong',
699 'Jim_ExprBoolean', etc.) to evaluate them.
701 The operators permitted in Tcl expressions are a subset of
702 the operators permitted in C expressions, and they have the
703 same meaning and precedence as the corresponding C operators.
704 Expressions almost always yield numeric results
705 (integer or floating-point values).
706 For example, the expression
708     8.2 + 6
710 evaluates to 14.2.
712 Tcl expressions differ from C expressions in the way that
713 operands are specified, and in that Tcl expressions support
714 non-numeric operands and string comparisons.
716 A Tcl expression consists of a combination of operands, operators,
717 and parentheses.
719 White space may be used between the operands and operators and
720 parentheses; it is ignored by the expression processor.
721 Where possible, operands are interpreted as integer values.
723 Integer values may be specified in decimal (the normal case) or in
724 hexadecimal (if the first two characters of the operand are '0x').
725 Note that Jim Tcl does *not* treat numbers with leading zeros as octal.
727 If an operand does not have one of the integer formats given
728 above, then it is treated as a floating-point number if that is
729 possible.  Floating-point numbers may be specified in any of the
730 ways accepted by an ANSI-compliant C compiler (except that the
731 'f', 'F', 'l', and 'L' suffixes will not be permitted in
732 most installations).  For example, all of the
733 following are valid floating-point numbers:  2.1, 3., 6e4, 7.91e+16.
735 If no numeric interpretation is possible, then an operand is left
736 as a string (and only a limited set of operators may be applied to
737 it).
739 String constants representing boolean constants
740 (+'0'+, +'1'+, +'false'+, +'off'+, +'no'+, +'true'+, +'on'+, +'yes'+)
741 are also recognized and can be used in logical operations.
743 1. Operands may be specified in any of the following ways:
745 2. As a numeric value, either integer or floating-point.
747 3. As one of valid boolean constants
749 4. As a Tcl variable, using standard '$' notation.
750 The variable's value will be used as the operand.
752 5. As a string enclosed in double-quotes.
753 The expression parser will perform backslash, variable, and
754 command substitutions on the information between the quotes,
755 and use the resulting value as the operand
757 6. As a string enclosed in braces.
758 The characters between the open brace and matching close brace
759 will be used as the operand without any substitutions.
761 7. As a Tcl command enclosed in brackets.
762 The command will be executed and its result will be used as
763 the operand.
765 Where substitutions occur above (e.g. inside quoted strings), they
766 are performed by the expression processor.
767 However, an additional layer of substitution may already have
768 been performed by the command parser before the expression
769 processor was called.
771 As discussed below, it is usually best to enclose expressions
772 in braces to prevent the command parser from performing substitutions
773 on the contents.
775 For some examples of simple expressions, suppose the variable 'a' has
776 the value 3 and the variable 'b' has the value 6.  Then the expression
777 on the left side of each of the lines below will evaluate to the value
778 on the right side of the line:
780     $a + 3.1                6.1
781     2 + "$a.$b"             5.6
782     4*[llength "6 2"]       8
783     {word one} < "word $a"  0
785 The valid operators are listed below, grouped in decreasing order
786 of precedence:
787 [[OperatorPrecedence]]
788 +int() double() round() abs(), rand(), srand()+::
789     Unary functions (except rand() which takes no arguments)
790     * +'int()'+ converts the numeric argument to an integer by truncating down.
791     * +'double()'+ converts the numeric argument to floating point.
792     * +'round()'+ converts the numeric argument to the closest integer value.
793     * +'abs()'+ takes the absolute value of the numeric argument.
794     * +'rand()'+ returns a pseudo-random floating-point value in the range (0,1).
795     * +'srand()'+ takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
797 +sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()+::
798     Unary math functions.
799     If Jim is compiled with math support, these functions are available.
801 +- + ~ !+::
802     Unary minus, unary plus, bit-wise NOT, logical NOT.  None of these operands
803     may be applied to string operands, and bit-wise NOT may be
804     applied only to integers.
806 +** pow(x,y)+::
807     Power. e.g. 'x^y^'. If Jim is compiled with math support, supports doubles and
808     integers. Otherwise supports integers only. (Note that the math-function form
809     has the same highest precedence)
811 +* / %+::
812     Multiply, divide, remainder.  None of these operands may be
813     applied to string operands, and remainder may be applied only
814     to integers.
816 ++ -+::
817     Add and subtract.  Valid for any numeric operands.
819 +<<  >> <<< >>>+::
820     Left and right shift, left and right rotate.  Valid for integer operands only.
822 +<  >  \<=  >=+::
823     Boolean less, greater, less than or equal, and greater than or equal.
824     Each operator produces 1 if the condition is true, 0 otherwise.
825     These operators may be applied to strings as well as numeric operands,
826     in which case string comparison is used.
828 +==  !=+::
829     Boolean equal and not equal.  Each operator produces a zero/one result.
830     Valid for all operand types. *Note* that values will be converted to integers
831     if possible, then floating point types, and finally strings will be compared.
832     It is recommended that 'eq' and 'ne' should be used for string comparison.
834 +eq ne+::
835     String equal and not equal.  Uses the string value directly without
836     attempting to convert to a number first.
838 +in ni+::
839     String in list and not in list. For 'in', result is 1 if the left operand (as a string)
840     is contained in the right operand (as a list), or 0 otherwise. The result for
841     +{$a ni $list}+ is equivalent to +{!($a in $list)}+.
843 +&+::
844     Bit-wise AND.  Valid for integer operands only.
846 +|+::
847     Bit-wise OR.  Valid for integer operands only.
849 +^+::
850     Bit-wise exclusive OR.  Valid for integer operands only.
852 +&&+::
853     Logical AND.  Produces a 1 result if both operands are non-zero, 0 otherwise.
854     Valid for numeric operands only (integers or floating-point).
856 +||+::
857     Logical OR.  Produces a 0 result if both operands are zero, 1 otherwise.
858     Valid for numeric operands only (integers or floating-point).
860 +x ? y : z+::
861     If-then-else, as in C.  If +'x'+
862     evaluates to non-zero, then the result is the value of +'y'+.
863     Otherwise the result is the value of +'z'+.
864     The +'x'+ operand must have a numeric value, while +'y'+ and +'z'+ can
865     be of any type.
867 See the C manual for more details on the results
868 produced by each operator.
869 All of the binary operators group left-to-right within the same
870 precedence level.  For example, the expression
872     4*2 < 7
874 evaluates to 0.
876 The +&&+, +||+, and +?:+ operators have 'lazy evaluation', just as
877 in C, which means that operands are not evaluated if they are not
878 needed to determine the outcome.  For example, in
880     $v ? [a] : [b]
882 only one of +[a]+ or +[b]+ will actually be evaluated,
883 depending on the value of +$v+.
885 All internal computations involving integers are done with the C
886 type 'long long' if available, or 'long' otherwise, and all internal
887 computations involving floating-point are done with the C type
888 'double'.
890 When converting a string to floating-point, exponent overflow is
891 detected and results in a Tcl error.
892 For conversion to integer from string, detection of overflow depends
893 on the behaviour of some routines in the local C library, so it should
894 be regarded as unreliable.
895 In any case, overflow and underflow are generally not detected
896 reliably for intermediate results.
898 Conversion among internal representations for integer, floating-point,
899 string operands is done automatically as needed.
900 For arithmetic computations, integers are used until some
901 floating-point number is introduced, after which floating-point is used.
902 For example,
904     5 / 4
906 yields the result 1, while
908     5 / 4.0
909     5 / ( [string length "abcd"] + 0.0 )
911 both yield the result 1.25.
913 String values may be used as operands of the comparison operators,
914 although the expression evaluator tries to do comparisons as integer
915 or floating-point when it can.
916 If one of the operands of a comparison is a string and the other
917 has a numeric value, the numeric operand is converted back to
918 a string using the C 'sprintf' format specifier
919 '%d' for integers and '%g' for floating-point values.
920 For example, the expressions
922     "0x03" > "2"
923     "0y" < "0x12"
925 both evaluate to 1.  The first comparison is done using integer
926 comparison, and the second is done using string comparison after
927 the second operand is converted to the string '18'.
929 In general it is safest to enclose an expression in braces when
930 entering it in a command:  otherwise, if the expression contains
931 any white space then the Tcl interpreter will split it
932 among several arguments.  For example, the command
934     expr $a + $b
936 results in three arguments being passed to `expr`:  +$a+,
937 \+, and +$b+.  In addition, if the expression isn't in braces
938 then the Tcl interpreter will perform variable and command substitution
939 immediately (it will happen in the command parser rather than in
940 the expression parser).  In many cases the expression is being
941 passed to a command that will evaluate the expression later (or
942 even many times if, for example, the expression is to be used to
943 decide when to exit a loop).  Usually the desired goal is to re-do
944 the variable or command substitutions each time the expression is
945 evaluated, rather than once and for all at the beginning.  For example,
946 the command
948     for {set i 1} $i<=10 {incr i} {...}        ** WRONG **
950 is probably intended to iterate over all values of +i+ from 1 to 10.
951 After each iteration of the body of the loop, `for` will pass
952 its second argument to the expression evaluator to see whether or not
953 to continue processing.  Unfortunately, in this case the value of +i+
954 in the second argument will be substituted once and for all when the
955 `for` command is parsed.  If +i+ was 0 before the `for`
956 command was invoked then the second argument of `for` will be +0\<=10+
957 which will always evaluate to 1, even though +i+ eventually
958 becomes greater than 10.  In the above case the loop will never
959 terminate.  Instead, the expression should be placed in braces:
961     for {set i 1} {$i<=10} {incr i} {...}      ** RIGHT **
963 This causes the substitution of 'i'
964 to be delayed; it will be re-done each time the expression is
965 evaluated, which is the desired result.
967 LISTS
968 -----
969 The third major way that strings are interpreted in Tcl is as lists.
970 A list is just a string with a list-like structure
971 consisting of fields separated by white space.  For example, the
972 string
974     Al Sue Anne John
976 is a list with four elements or fields.
977 Lists have the same basic structure as command strings, except
978 that a newline character in a list is treated as a field separator
979 just like space or tab.  Conventions for braces and quotes
980 and backslashes are the same for lists as for commands.  For example,
981 the string
983     a b\ c {d e {f g h}}
985 is a list with three elements:  +a+, +b c+, and +d e {f g h}+.
987 Whenever an element is extracted from a list, the same rules about
988 braces and quotes and backslashes are applied as for commands.  Thus in
989 the example above when the third element is extracted from the list,
990 the result is
992     d e {f g h}
994 (when the field was extracted, all that happened was to strip off
995 the outermost layer of braces).  Command substitution and
996 variable substitution are never
997 made on a list (at least, not by the list-processing commands; the
998 list can always be passed to the Tcl interpreter for evaluation).
1000 The Tcl commands `concat`, `foreach`, `lappend`, `lindex`, `linsert`,
1001 `list`, `llength`, `lrange`, `lreplace`, `lsearch`, and `lsort` allow
1002 you to build lists, extract elements from them, search them, and perform
1003 other list-related functions.
1005 Advanced list commands include `lrepeat`, `lreverse`, `lmap`, `lassign`, `lset`.
1007 LIST EXPANSION
1008 --------------
1010 A new addition to Tcl 8.5 is the ability to expand a list into separate
1011 arguments. Support for this feature is also available in Jim.
1013 Consider the following attempt to exec a list:
1015     set cmd {ls -l}
1016     exec $cmd
1018 This will attempt to exec a command named "ls -l", which will clearly not
1019 work. Typically eval and concat are required to solve this problem, however
1020 it can be solved much more easily with +\{*\}+.
1022     exec {*}$cmd
1024 This will expand the following argument into individual elements and then evaluate
1025 the resulting command.
1027 Note that the official Tcl syntax is +\{*\}+, however +\{expand\}+ is retained
1028 for backward compatibility with experimental versions of this feature.
1030 REGULAR EXPRESSIONS
1031 -------------------
1032 Tcl provides two commands that support string matching using regular
1033 expressions, `regexp` and `regsub`, as well as `switch -regexp` and
1034 `lsearch -regexp`.
1036 Regular expressions may be implemented one of two ways. Either using the system's C library
1037 POSIX regular expression support, or using the built-in regular expression engine.
1038 The differences between these are described below.
1040 *NOTE* Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (+ARE+).
1042 POSIX Regular Expressions
1043 ~~~~~~~~~~~~~~~~~~~~~~~~~
1044 If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
1045 this support will be used by default. The type of regular expressions supported are
1046 Extended Regular Expressions (+ERE+) rather than Basic Regular Expressions (+BRE+).
1047 See REG_EXTENDED in the documentation.
1049 Using the system-supported POSIX regular expressions will typically
1050 make for the smallest code size, but some features such as UTF-8
1051 and +{backslash}w+, +{backslash}d+, +{backslash}s+ are not supported, and null characters
1052 in strings are not supported.
1054 See regex(3) and regex(7) for full details.
1056 Jim built-in Regular Expressions
1057 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1058 The Jim built-in regular expression engine may be selected with +./configure --with-jim-regexp+
1059 or it will be selected automatically if UTF-8 support is enabled.
1061 This engine supports UTF-8 as well as some +ARE+ features. The differences with both Tcl 7.x/8.x
1062 and POSIX are highlighted below.
1064 1. UTF-8 strings and patterns are both supported
1065 2. All Tcl character classes are supported (e.g. +[:alnum:]+, +[:digit:]+, +[:space:]+), but...
1066 3. Character classes apply to ASCII characters only
1067 4. Supported shorthand character classes: +{backslash}w+ = +[:alnum:]+, +{backslash}W+ = +^[:alnum:]+, +{backslash}d+ = +[:digit:],+ +{backslash}D+ = +^[:digit:],+ +{backslash}s+ = +[:space:]+, + +{backslash}S+ = +^[:space:]+
1068 5. Supported constraint escapes: +{backslash}m+ = +{backslash}<+ = start of word, +{backslash}M+ = +{backslash}>+ = end of word
1069 6. Backslash escapes may be used within regular expressions, such as +{backslash}n+ = newline, +{backslash}uNNNN+ = unicode
1070 7. Partially supported constraint escapes: +{backslash}A+ = start of string, +{backslash}Z+ = end of string
1071 8. Support for the +?+ non-greedy quantifier. e.g. +*?+
1072 9. Support for non-capturing parentheses +(?:...)+
1073 10. Jim Tcl considers that both patterns and strings end at a null character (+\x00+)
1075 COMMAND RESULTS
1076 ---------------
1077 Each command produces two results:  a code and a string.  The
1078 code indicates whether the command completed successfully or not,
1079 and the string gives additional information.  The valid codes are
1080 defined in jim.h, and are:
1082 +JIM_OK(0)+::
1083     This is the normal return code, and indicates that the command completed
1084     successfully.  The string gives the command's return value.
1086 +JIM_ERR(1)+::
1087     Indicates that an error occurred; the string gives a message describing
1088     the error.
1090 +JIM_RETURN(2)+::
1091     Indicates that the `return` command has been invoked, and that the
1092     current procedure (or top-level command or `source` command)
1093     should return immediately.  The
1094     string gives the return value for the procedure or command.
1096 +JIM_BREAK(3)+::
1097     Indicates that the `break` command has been invoked, so the
1098     innermost loop should abort immediately.  The string should always
1099     be empty.
1101 +JIM_CONTINUE(4)+::
1102     Indicates that the `continue` command has been invoked, so the
1103     innermost loop should go on to the next iteration.  The string
1104     should always be empty.
1106 +JIM_SIGNAL(5)+::
1107     Indicates that a signal was caught while executing a commands.
1108     The string contains the name of the signal caught.
1109     See the `signal` and `catch` commands.
1111 +JIM_EXIT(6)+::
1112     Indicates that the command called the `exit` command.
1113     The string contains the exit code.
1115 Tcl programmers do not normally need to think about return codes,
1116 since +JIM_OK+ is almost always returned.  If anything else is returned
1117 by a command, then the Tcl interpreter immediately stops processing
1118 commands and returns to its caller.  If there are several nested
1119 invocations of the Tcl interpreter in progress, then each nested
1120 command will usually return the error to its caller, until eventually
1121 the error is reported to the top-level application code.  The
1122 application will then display the error message for the user.
1124 In a few cases, some commands will handle certain `error` conditions
1125 themselves and not return them upwards.  For example, the `for`
1126 command checks for the +JIM_BREAK+ code; if it occurs, then `for`
1127 stops executing the body of the loop and returns +JIM_OK+ to its
1128 caller.  The `for` command also handles +JIM_CONTINUE+ codes and the
1129 procedure interpreter handles +JIM_RETURN+ codes.  The `catch`
1130 command allows Tcl programs to catch errors and handle them without
1131 aborting command interpretation any further.
1133 The `info returncodes` command may be used to programmatically map between
1134 return codes and names.
1136 PROCEDURES
1137 ----------
1138 Tcl allows you to extend the command interface by defining
1139 procedures.  A Tcl procedure can be invoked just like any other Tcl
1140 command (it has a name and it receives one or more arguments).
1141 The only difference is that its body isn't a piece of C code linked
1142 into the program; it is a string containing one or more other
1143 Tcl commands.
1145 The `proc` command is used to create a new Tcl command procedure:
1147 +*proc* 'name arglist ?statics? body'+
1149 The new command is named +'name'+, and it replaces any existing command
1150 there may have been by that name. Whenever the new command is
1151 invoked, the contents of +'body'+ will be executed by the Tcl
1152 interpreter.
1154 +'arglist'+ specifies the formal arguments to the procedure.
1155 It consists of a list, possibly empty, of the following
1156 argument specifiers:
1158 +name+::
1159     Required Argument - A simple argument name.
1161 +{name default}+::
1162     Optional Argument - A two-element list consisting of the
1163     argument name, followed by the default value, which will
1164     be used if the corresponding argument is not supplied.
1166 +&name+::
1167     Reference Argument - The caller is expected to pass the name of
1168     an existing variable. An implicit +`upvar` 1 origname name+ is done
1169     to make the variable available in the proc scope.
1171 +*args*+::
1172     Variable Argument - The special name +'args'+, which is
1173     assigned all remaining arguments (including none) as a list. The
1174     variable argument may only be specified once. Note that
1175     the syntax +{args newname}+ may be used to retain the special
1176     behaviour of +'args'+ with a different local name. In this case,
1177     the variable is named +'newname'+ rather than +'args'+.
1179 When the command is invoked, a local variable will be created for each of
1180 the formal arguments to the procedure; its value will be the value
1181 of corresponding argument in the invoking command or the argument's
1182 default value.
1184 Arguments with default values need not be specified in a procedure
1185 invocation.  However, there must be enough actual arguments for all
1186 required arguments, and there must not be any extra actual arguments
1187 (unless the Variable Argument is specified).
1189 Actual arguments are assigned to formal arguments as in left-to-right
1190 order with the following precedence.
1192 1. Required Arguments (including Reference Arguments)
1193 2. Optional Arguments
1194 3. Variable Argument
1196 The following example illustrates precedence. Assume a procedure declaration:
1198     proc p {{a A} args b {c C} d} {...}
1200 This procedure requires at least two arguments, but can accept an unlimited number.
1201 The following table shows how various numbers of arguments are assigned.
1202 Values marked as +-+ are assigned the default value.
1204 [width="40%",frame="topbot",options="header"]
1205 |==============
1206 |Number of arguments|a|args|b|c|d
1207 |2|-|-|1|-|2
1208 |3|1|-|2|-|3
1209 |4|1|-|2|3|4
1210 |5|1|2|3|4|5
1211 |6|1|2,3|4|5|6
1212 |==============
1214 When +'body'+ is being executed, variable names normally refer to local
1215 variables, which are created automatically when referenced and deleted
1216 when the procedure returns.  One local variable is automatically created
1217 for each of the procedure's arguments.  Global variables can be
1218 accessed by invoking the `global` command or via the +::+ prefix.
1220 New in Jim
1221 ~~~~~~~~~~
1222 In addition to procedure arguments, Jim procedures may declare static variables.
1223 These variables scoped to the procedure and initialised at procedure definition.
1224 Either from the static variable definition, or from the enclosing scope.
1226 Consider the following example:
1228     jim> set a 1
1229     jim> proc a {} {a {b 2}} {
1230         set c 1
1231         puts "$a $b $c"
1232         incr a
1233         incr b
1234         incr c
1235     }
1236     jim> a
1237     1 2 1
1238     jim> a
1239     2 3 1
1241 The static variable +'a'+ has no initialiser, so it is initialised from
1242 the enclosing scope with the value 1. (Note that it is an error if there
1243 is no variable with the same name in the enclosing scope). However +'b'+
1244 has an initialiser, so it is initialised to 2.
1246 Unlike a local variable, the value of a static variable is retained across
1247 invocations of the procedure.
1249 See the `proc` command for information on how to define procedures
1250 and what happens when they are invoked. See also NAMESPACES.
1252 VARIABLES - SCALARS AND ARRAYS
1253 ------------------------------
1254 Tcl allows the definition of variables and the use of their values
1255 either through '$'-style variable substitution, the `set`
1256 command, or a few other mechanisms.
1258 Variables need not be declared:  a new variable will automatically
1259 be created each time a new variable name is used.
1261 Tcl supports two types of variables:  scalars and arrays.
1262 A scalar variable has a single value, whereas an array variable
1263 can have any number of elements, each with a name (called
1264 its 'index') and a value.
1266 Array indexes may be arbitrary strings; they need not be numeric.
1267 Parentheses are used refer to array elements in Tcl commands.
1268 For example, the command
1270     set x(first) 44
1272 will modify the element of 'x' whose index is 'first'
1273 so that its new value is '44'.
1275 Two-dimensional arrays can be simulated in Tcl by using indexes
1276 that contain multiple concatenated values.
1277 For example, the commands
1279     set a(2,3) 1
1280     set a(3,6) 2
1282 set the elements of 'a' whose indexes are '2,3' and '3,6'.
1284 In general, array elements may be used anywhere in Tcl that scalar
1285 variables may be used.
1287 If an array is defined with a particular name, then there may
1288 not be a scalar variable with the same name.
1290 Similarly, if there is a scalar variable with a particular
1291 name then it is not possible to make array references to the
1292 variable.
1294 To convert a scalar variable to an array or vice versa, remove
1295 the existing variable with the `unset` command.
1297 The `array` command provides several features for dealing
1298 with arrays, such as querying the names of all the elements of
1299 the array and converting between an array and a list.
1301 Variables may be either global or local.  If a variable
1302 name is used when a procedure isn't being executed, then it
1303 automatically refers to a global variable.  Variable names used
1304 within a procedure normally refer to local variables associated with that
1305 invocation of the procedure.  Local variables are deleted whenever
1306 a procedure exits.  Either `global` command may be used to request
1307 that a name refer to a global variable for the duration of the current
1308 procedure (this is somewhat analogous to 'extern' in C), or the variable
1309 may be explicitly scoped with the +::+ prefix. For example
1311     set a 1
1312     set b 2
1313     proc p {} {
1314         set c 3
1315         global a
1317         puts "$a $::b $c"
1318     }
1319     p
1321 will output:
1323     1 2 3
1325 ARRAYS AS LISTS IN JIM
1326 ----------------------
1327 Unlike Tcl, Jim can automatically convert between a list (with an even
1328 number of elements) and an array value. This is similar to the way Tcl
1329 can convert between a string and a list.
1331 For example:
1333   set a {1 one 2 two}
1334   puts $a(2)
1336 will output:
1338   two
1340 Thus `array set` is equivalent to `set` when the variable does not
1341 exist or is empty.
1343 The reverse is also true where an array will be converted into
1344 a list.
1346   set a(1) one; set a(2) two
1347   puts $a
1349 will output:
1351   1 one 2 two
1353 DICTIONARY VALUES
1354 -----------------
1355 Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
1356 of this command. Dictionaries provide efficient access to key-value
1357 pairs, just like arrays, but dictionaries are pure values. This
1358 means that you can pass them to a procedure just as a list or a
1359 string. Tcl dictionaries are therefore much more like Tcl lists,
1360 except that they represent a mapping from keys to values, rather
1361 than an ordered sequence.
1363 You can nest dictionaries, so that the value for a particular key
1364 consists of another dictionary. That way you can elegantly build
1365 complicated data structures, such as hierarchical databases. You
1366 can also combine dictionaries with other Tcl data structures. For
1367 instance, you can build a list of dictionaries that themselves
1368 contain lists.
1370 Dictionaries are values that contain an efficient, order-preserving
1371 mapping from arbitrary keys to arbitrary values. Each key in the
1372 dictionary maps to a single value. They have a textual format that
1373 is exactly that of any list with an even number of elements, with
1374 each mapping in the dictionary being represented as two items in
1375 the list. When a command takes a dictionary and produces a new
1376 dictionary based on it (either returning it or writing it back into
1377 the variable that the starting dictionary was read from) the new
1378 dictionary will have the same order of keys, modulo any deleted
1379 keys and with new keys added on to the end. When a string is
1380 interpreted as a dictionary and it would otherwise have duplicate
1381 keys, only the last value for a particular key is used; the others
1382 are ignored, meaning that, "apple banana" and "apple carrot apple
1383 banana" are equivalent dictionaries (with different string
1384 representations).
1386 Note that in Jim, arrays are implemented as dictionaries.
1387 Thus automatic conversion between lists and dictionaries applies
1388 as it does for arrays.
1390   jim> dict set a 1 one
1391   1 one
1392   jim> dict set a 2 two
1393   1 one 2 two
1394   jim> puts $a
1395   1 one 2 two
1396   jim> puts $a(2)
1397   two
1398   jim> dict set a 3 T three
1399   1 one 2 two 3 {T three}
1401 See the `dict` command for more details.
1403 NAMESPACES
1404 ----------
1405 Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
1406 including a number of 3rd party components. While there is less need for namespaces
1407 in Jim Tcl (which does not strive to support large applications), it is convenient to
1408 provide a subset of the support for namespaces to easy porting code from Tcl.
1410 Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
1411 purposes. This feature is currently experimental. See README.namespaces for more information
1412 and the documentation of the `namespace` command.
1414 GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION
1415 -----------------------------------------------
1416 Unlike Tcl, Jim has some sophisticated support for functional programming.
1417 These are described briefly below.
1419 More information may be found at http://wiki.tcl.tk/13847
1421 References
1422 ~~~~~~~~~~
1423 A reference can be thought of as holding a value with one level of indirection,
1424 where the value may be garbage collected when unreferenced.
1425 Consider the following example:
1427     jim> set r [ref "One String" test]
1428     <reference.<test___>.00000000000000000000>
1429     jim> getref $r
1430     One String
1432 The operation `ref` creates a references to the value specified by the
1433 first argument. (The second argument is a "type" used for documentation purposes).
1435 The operation `getref` is the dereferencing operation which retrieves the value
1436 stored in the reference.
1438     jim> setref $r "New String"
1439     New String
1440     jim> getref $r
1441     New String
1443 The operation `setref` replaces the value stored by the reference. If the old value
1444 is no longer accessible by any reference, it will eventually be automatically be garbage
1445 collected.
1447 Garbage Collection
1448 ~~~~~~~~~~~~~~~~~~
1449 Normally, all values in Tcl are passed by value. As such values are copied and released
1450 automatically as necessary.
1452 With the introduction of references, it is possible to create values whose lifetime
1453 transcend their scope. To support this, case, the Jim system will periodically identify
1454 and discard objects which are no longer accessible by any reference.
1456 The `collect` command may be used to force garbage collection.  Consider a reference created
1457 with a finalizer:
1459     jim> proc f {ref value} { puts "Finaliser called for $ref,$value" }
1460     jim> set r [ref "One String" test f]
1461     <reference.<test___>.00000000000
1462     jim> collect
1463     0
1464     jim> set r ""
1465     jim> collect
1466     Finaliser called for <reference.<test___>.00000000000,One String
1467     1
1469 Note that once the reference, 'r', was modified so that it no longer
1470 contained a reference to the value, the garbage collector discarded
1471 the value (after calling the finalizer).
1473 The finalizer for a reference may be examined or changed with the `finalize` command
1475     jim> finalize $r
1476     f
1477     jim> finalize $r newf
1478     newf
1480 Lambda Function
1481 ~~~~~~~~~~~~~~~
1482 Jim provides a garbage collected `lambda` function. This is a procedure
1483 which is able to create an anonymous procedure.  Consider:
1485     jim> set f [lambda {a} {{x 0}} { incr x $a }]
1486     jim> $f 1
1487     1
1488     jim> $f 2
1489     3
1490     jim> set f ""
1492 This create an anonymous procedure (with the name stored in 'f'), with a static variable
1493 which is incremented by the supplied value and the result returned.
1495 Once the procedure name is no longer accessible, it will automatically be deleted
1496 when the garbage collector runs.
1498 The procedure may also be delete immediately by renaming it "". e.g.
1500     jim> rename $f ""
1502 UTF-8 AND UNICODE
1503 -----------------
1504 If Jim is built with UTF-8 support enabled (configure --enable-utf),
1505 then most string-related commands become UTF-8 aware.  These include,
1506 but are not limited to, `string match`, `split`, `glob`, `scan` and
1507 `format`.
1509 UTF-8 encoding has many advantages, but one of the complications is that
1510 characters can take a variable number of bytes. Thus the addition of
1511 `string bytelength` which returns the number of bytes in a string,
1512 while `string length` returns the number of characters.
1514 If UTF-8 support is not enabled, all commands treat bytes as characters
1515 and `string bytelength` returns the same value as `string length`.
1517 Note that even if UTF-8 support is not enabled, the +{backslash}uNNNN+ and related syntax
1518 is still available to embed UTF-8 sequences.
1520 Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +'U+1FFFFF'.
1522 String Matching
1523 ~~~~~~~~~~~~~~~
1524 Commands such as `string match`, `lsearch -glob`, `array names` and others use string
1525 pattern matching rules. These commands support UTF-8. For example:
1527   string match a\[\ua0-\ubf\]b "a\u00a3b"
1529 format and scan
1530 ~~~~~~~~~~~~~~~
1531 +format %c+ allows a unicode codepoint to be be encoded. For example, the following will return
1532 a string with two bytes and one character. The same as +{backslash}ub5+
1534   format %c 0xb5
1536 `format` respects widths as character widths, not byte widths. For example, the following will
1537 return a string with three characters, not three bytes.
1539   format %.3s \ub5\ub6\ub7\ub8
1541 Similarly, +scan ... %c+ allows a UTF-8 to be decoded to a unicode codepoint. The following will set
1542 +'a'+ to 181 (0xb5) and +'b'+ to 65 (0x41).
1544   scan \u00b5A %c%c a b
1546 `scan %s` will also accept a character class, including unicode ranges.
1548 String Classes
1549 ~~~~~~~~~~~~~~
1550 `string is` has *not* been extended to classify UTF-8 characters. Therefore, the following
1551 will return 0, even though the string may be considered to be alphabetic.
1553   string is alpha \ub5Test
1555 This does not affect the string classes 'ascii', 'control', 'digit', 'double', 'integer' or 'xdigit'.
1557 Case Mapping and Conversion
1558 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1559 Jim provides a simplified unicode case mapping. This means that case conversion
1560 and comparison will not increase or decrease the number of characters in a string.
1561 (Although it may change the number of bytes).
1563 `string toupper` will convert any lowercase letters to their uppercase equivalent.
1564 Any character which is not a letter or has no uppercase equivalent is left unchanged.
1565 Similarly for `string tolower` and `string totitle`.
1567 Commands which perform case insensitive matches, such as `string compare -nocase`
1568 and `lsearch -nocase` fold both strings to uppercase before comparison.
1570 Invalid UTF-8 Sequences
1571 ~~~~~~~~~~~~~~~~~~~~~~~
1572 Some UTF-8 character sequences are invalid, such as those beginning with '0xff',
1573 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
1574 and those which end prematurely, such as a lone '0xc2'.
1576 In these situations, the offending bytes are treated as single characters. For example,
1577 the following returns 2.
1579   string bytelength \xff\xff
1581 Regular Expressions
1582 ~~~~~~~~~~~~~~~~~~~
1583 If UTF-8 support is enabled, the built-in regular expression engine will be
1584 selected which supports UTF-8 strings and patterns.
1586 See REGULAR EXPRESSIONS
1588 BUILT-IN COMMANDS
1589 -----------------
1590 The Tcl library provides the following built-in commands, which will
1591 be available in any application using Tcl.  In addition to these
1592 built-in commands, there may be additional commands defined by each
1593 application, plus commands defined as Tcl procedures.
1595 In the command syntax descriptions below, words in +*boldface*+ are
1596 literals that you type verbatim to Tcl.
1598 Words in +'italics'+ are meta-symbols; they serve as names for any of
1599 a range of values that you can type.
1601 Optional arguments or groups of arguments are indicated by enclosing them
1602 in +?question-marks?+.
1604 Ellipses (+\...+) indicate that any number of additional
1605 arguments or groups of arguments may appear, in the same format
1606 as the preceding argument(s).
1608 [[CommandIndex]]
1609 Command Index
1610 ~~~~~~~~~~~~~
1611 @INSERTINDEX@
1613 alarm
1614 ~~~~~
1615 +*alarm* 'seconds'+
1617 Delivers the +SIGALRM+ signal to the process after the given
1618 number of seconds. If the platform supports 'ualarm(3)' then
1619 the argument may be a floating point value. Otherwise it must
1620 be an integer.
1622 Note that unless a signal handler for +SIGALRM+ has been installed
1623 (see `signal`), the process will exit on this signal.
1625 alias
1626 ~~~~~
1627 +*alias* 'name args\...'+
1629 Creates a single word alias (command) for one or more words. For example,
1630 the following creates an alias for the command `info exists`.
1632     alias e info exists
1633     if {[e var]} {
1634       ...
1635     }
1637 `alias` returns +'name'+, allowing it to be used with `local`.
1639 See also `proc`, `curry`, `lambda`, `local`, `info alias`, `exists -alias`
1641 append
1642 ~~~~~~
1643 +*append* 'varName value ?value value ...?'+
1645 Append all of the +'value'+ arguments to the current value
1646 of variable +'varName'+.  If +'varName'+ doesn't exist,
1647 it is given a value equal to the concatenation of all the
1648 +'value'+ arguments.
1650 This command provides an efficient way to build up long
1651 variables incrementally.
1652 For example, "`append a $b`" is much more efficient than
1653 "`set a $a$b`" if +$a+ is long.
1655 apply
1656 ~~~~~~
1657 +*apply* 'lambdaExpr ?arg1 arg2 \...?'+
1659 The command `apply` provides for anonymous procedure calls,
1660 similar to `lambda`, but without command name being created, even temporarily.
1662 The function  +'lambdaExpr'+ is a two element list +{args body}+
1663 or a three element list +{args body namespace}+. The first element
1664 args specifies the formal arguments, in the same form as the `proc` and `lambda` commands.
1666 array
1667 ~~~~~
1668 +*array* 'option arrayName ?arg\...?'+
1670 This command performs one of several operations on the
1671 variable given by +'arrayName'+.
1673 Note that in general, if the named array does not exist, the +'array'+ command behaves
1674 as though the array exists but is empty.
1676 The +'option'+ argument determines what action is carried out by the
1677 command.  The legal +'options'+ (which may be abbreviated) are:
1679 +*array exists* 'arrayName'+::
1680     Returns 1 if arrayName is an array variable, 0 if there is
1681     no variable by that name.
1683 +*array get* 'arrayName ?pattern?'+::
1684     Returns a list containing pairs of elements. The first
1685     element in each pair is the name of an element in arrayName
1686     and the second element of each pair is the value of the
1687     array element. The order of the pairs is undefined. If
1688     pattern is not specified, then all of the elements of the
1689     array are included in the result. If pattern is specified,
1690     then only those elements whose names match pattern (using
1691     the matching rules of string match) are included. If arrayName
1692     isn't the name of an array variable, or if the array contains
1693     no elements, then an empty list is returned.
1695 +*array names* 'arrayName ?pattern?'+::
1696     Returns a list containing the names of all of the elements
1697     in the array that match pattern. If pattern is omitted then
1698     the command returns all of the element names in the array.
1699     If pattern is specified, then only those elements whose
1700     names match pattern (using the matching rules of string
1701     match) are included. If there are no (matching) elements
1702     in the array, or if arrayName isn't the name of an array
1703     variable, then an empty string is returned.
1705 +*array set* 'arrayName list'+::
1706     Sets the values of one or more elements in arrayName. list
1707     must have a form like that returned by array get, consisting
1708     of an even number of elements. Each odd-numbered element
1709     in list is treated as an element name within arrayName, and
1710     the following element in list is used as a new value for
1711     that array element. If the variable arrayName does not
1712     already exist and list is empty, arrayName is created with
1713     an empty array value.
1715 +*array size* 'arrayName'+::
1716     Returns the number of elements in the array. If arrayName
1717     isn't the name of an array then 0 is returned.
1719 +*array unset* 'arrayName ?pattern?'+::
1720     Unsets all of the elements in the array that match pattern
1721     (using the matching rules of string match). If arrayName
1722     isn't the name of an array variable or there are no matching
1723     elements in the array, no error will be raised. If pattern
1724     is omitted and arrayName is an array variable, then the
1725     command unsets the entire array. The command always returns
1726     an empty string.
1728 break
1729 ~~~~~
1730 +*break*+
1732 This command may be invoked only inside the body of a loop command
1733 such as `for` or `foreach` or `while`.  It returns a +JIM_BREAK+ code
1734 to signal the innermost containing loop command to return immediately.
1736 case
1737 ~~~~
1738 +*case* 'string' ?in? 'patList body ?patList body ...?'+
1740 +*case* 'string' ?in? {'patList body ?patList body ...?'}+
1742 *Note* that the `switch` command should generally be preferred unless compatibility
1743 with Tcl 6.x is desired.
1745 Match +'string'+ against each of the +'patList'+ arguments
1746 in order.  If one matches, then evaluate the following +'body'+ argument
1747 by passing it recursively to the Tcl interpreter, and return the result
1748 of that evaluation.  Each +'patList'+ argument consists of a single
1749 pattern or list of patterns.  Each pattern may contain any of the wild-cards
1750 described under `string match`.
1752 If a +'patList'+ argument is +default+, the corresponding body will be
1753 evaluated if no +'patList'+ matches +'string'+.  If no +'patList'+ argument
1754 matches +'string'+ and no default is given, then the `case` command returns
1755 an empty string.
1757 Two syntaxes are provided.
1759 The first uses a separate argument for each of the patterns and commands;
1760 this form is convenient if substitutions are desired on some of the
1761 patterns or commands.
1763 The second form places all of the patterns and commands together into
1764 a single argument; the argument must have proper list structure, with
1765 the elements of the list being the patterns and commands.
1767 The second form makes it easy to construct multi-line case commands,
1768 since the braces around the whole list make it unnecessary to include a
1769 backslash at the end of each line.
1771 Since the +'patList'+ arguments are in braces in the second form,
1772 no command or variable substitutions are performed on them;  this makes
1773 the behaviour of the second form different than the first form in some
1774 cases.
1776 Below are some examples of `case` commands:
1778     case abc in {a b} {format 1} default {format 2} a* {format 3}
1780 will return '3',
1782     case a in {
1783         {a b} {format 1}
1784         default {format 2}
1785         a* {format 3}
1786     }
1788 will return '1', and
1790     case xyz {
1791         {a b}
1792             {format 1}
1793         default
1794             {format 2}
1795         a*
1796             {format 3}
1797     }
1799 will return '2'.
1801 catch
1802 ~~~~~
1803 +*catch* ?-?no?'code \...'? ?--? 'command ?resultVarName? ?optionsVarName?'+
1805 The `catch` command may be used to prevent errors from aborting
1806 command interpretation.  `catch` evaluates +'command'+, and returns a
1807 +JIM_OK+ code, regardless of any errors that might occur while
1808 executing +'command'+ (with the possible exception of +JIM_SIGNAL+ -
1809 see below).
1811 The return value from `catch` is a decimal string giving the code
1812 returned by the Tcl interpreter after executing +'command'+.  This
1813 will be '0' (+JIM_OK+) if there were no errors in +'command'+; otherwise
1814 it will have a non-zero value corresponding to one of the exceptional
1815 return codes (see jim.h for the definitions of code values, or the
1816 `info returncodes` command).
1818 If the +'resultVarName'+ argument is given, then it gives the name
1819 of a variable; `catch` will set the value of the variable to the
1820 string returned from +'command'+ (either a result or an error message).
1822 If the +'optionsVarName'+ argument is given, then it gives the name
1823 of a variable; `catch` will set the value of the variable to a
1824 dictionary. For any return code other than +JIM_RETURN+, the value
1825 for the key +-code+ will be set to the return code. For +JIM_RETURN+
1826 it will be set to the code given in `return -code`. Additionally,
1827 for the return code +JIM_ERR+, the value of the key +-errorinfo+
1828 will contain the current stack trace (the same result as `info stacktrace`),
1829 the value of the key +-errorcode+ will contain the
1830 same value as the global variable $::errorCode, and the value of
1831 the key +-level+ will be the current return level (see `return -level`).
1832 This can be useful to rethrow an error:
1834     if {[catch {...} msg opts]} {
1835         ...maybe do something with the error...
1836         incr opts(-level)
1837         return {*}$opts $msg
1838     }
1840 Normally `catch` will +'not'+ catch any of the codes +JIM_EXIT+, +JIM_EVAL+ or +JIM_SIGNAL+.
1841 The set of codes which will be caught may be modified by specifying the one more codes before
1842 +'command'+.
1844 e.g. To catch +JIM_EXIT+ but not +JIM_BREAK+ or +JIM_CONTINUE+
1846     catch -exit -nobreak -nocontinue -- { ... }
1848 The use of +--+ is optional. It signifies that no more return code options follow.
1850 Note that if a signal marked as `signal handle` is caught with `catch -signal`, the return value
1851 (stored in +'resultVarName'+) is name of the signal caught.
1855 +*cd* 'dirName'+
1857 Change the current working directory to +'dirName'+.
1859 Returns an empty string.
1861 This command can potentially be disruptive to an application, so it may
1862 be removed in some applications.
1864 clock
1865 ~~~~~
1866 +*clock seconds*+::
1867     Returns the current time as seconds since the epoch.
1869 +*clock clicks*+::
1870     Returns the current time in "clicks", a system-dependent, high-resolution time.
1872 +*clock microseconds*+::
1873     Returns the current time in microseconds.
1875 +*clock milliseconds*+::
1876     Returns the current time in milliseconds.
1878 +*clock format* 'seconds' ?*-format* 'format?' ?*-gmt* 'boolean?'+::
1879     Format the given time (seconds since the epoch) according to the given
1880     format. See strftime(3) for supported formats.
1881     If no format is supplied, "%c" is used.
1882   ::
1883     If +'boolean'+ is true, processing is performed in UTC.
1884     If +'boolean'+ is false (the default), processing  is performeed in the local time zone.
1886 +*clock scan* 'str' *-format* 'format' ?*-gmt* 'boolean?'+::
1887     Scan the given time string using the given format string.
1888     See strptime(3) for supported formats.
1889     See `clock format` for the handling of '-gmt'.
1891 close
1892 ~~~~~
1893 +*close* 'fileId'+
1895 +'fileId' *close*+
1897 Closes the file given by +'fileId'+.
1898 +'fileId'+ must be the return value from a previous invocation
1899 of the `open` command; after this command, it should not be
1900 used anymore.
1902 collect
1903 ~~~~~~~
1904 +*collect*+
1906 Normally reference garbage collection is automatically performed periodically.
1907 However it may be run immediately with the `collect` command.
1909 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
1911 concat
1912 ~~~~~~
1913 +*concat* 'arg ?arg \...?'+
1915 This command treats each argument as a list and concatenates them
1916 into a single list.  It permits any number of arguments.  For example,
1917 the command
1919     concat a b {c d e} {f {g h}}
1921 will return
1923     a b c d e f {g h}
1925 as its result.
1927 continue
1928 ~~~~~~~~
1929 +*continue*+
1931 This command may be invoked only inside the body of a loop command such
1932 as `for` or `foreach` or `while`.  It returns a  +JIM_CONTINUE+ code to
1933 signal the innermost containing loop command to skip the remainder of
1934 the loop's body but continue with the next iteration of the loop.
1936 curry
1937 ~~~~~
1938 +*alias* 'args\...'+
1940 Similar to `alias` except it creates an anonymous procedure (lambda) instead of
1941 a named procedure.
1943 the following creates a local, unnamed alias for the command `info exists`.
1945     set e [local curry info exists]
1946     if {[$e var]} {
1947       ...
1948     }
1950 `curry` returns the name of the procedure.
1952 See also `proc`, `alias`, `lambda`, `local`.
1954 dict
1955 ~~~~
1956 +*dict* 'option ?arg\...?'+
1958 Performs one of several operations on dictionary values.
1960 The +'option'+ argument determines what action is carried out by the
1961 command.  The legal +'options'+ are:
1963 +*dict create* '?key value \...?'+::
1964     Create and return a new dictionary value that contains each of
1965     the key/value mappings listed as  arguments (keys and values
1966     alternating, with each key being followed by its associated
1967     value.)
1969 +*dict exists* 'dictionary key ?key \...?'+::
1970     Returns a boolean value indicating whether the given key (or path
1971     of keys through a set of nested dictionaries) exists in the given
1972     dictionary value.  This returns a true value exactly when `dict get`
1973     on that path will succeed.
1975 +*dict get* 'dictionary ?key \...?'+::
1976     Given a dictionary value (first argument) and a key (second argument),
1977     this will retrieve the value for that key. Where several keys are
1978     supplied, the behaviour of the command shall be as if the result
1979     of "`dict get $dictVal $key`" was passed as the first argument to
1980     dict get with the remaining arguments as second (and possibly
1981     subsequent) arguments. This facilitates lookups in nested dictionaries.
1982     If no keys are provided, dict would return a list containing pairs
1983     of elements in a manner similar to array get. That is, the first
1984     element of each pair would be the key and the second element would
1985     be the value for that key.  It is an error to attempt to retrieve
1986     a value for a key that is not present in the dictionary.
1988 +*dict keys* 'dictionary ?pattern?'+::
1989     Returns a list of the keys in the dictionary.
1990     If pattern is specified, then only those keys whose
1991     names match +'pattern'+ (using the matching rules of string
1992     match) are included.
1994 +*dict merge* ?'dictionary \...'?+::
1995     Return a dictionary that contains the contents of each of the
1996     +'dictionary'+ arguments. Where two (or more) dictionaries
1997     contain a mapping for the same key, the resulting dictionary
1998     maps that key to the value according to the last dictionary on
1999     the command line containing a mapping for that key.
2001 +*dict set* 'dictionaryName key ?key \...? value'+::
2002     This operation takes the +'name'+ of a variable containing a dictionary
2003     value and places an updated dictionary value in that variable
2004     containing a mapping from the given key to the given value. When
2005     multiple keys are present, this operation creates or updates a chain
2006     of nested dictionaries.
2008 +*dict size* 'dictionary'+::
2009     Return the number of key/value mappings in the given dictionary value.
2011 +*dict unset* 'dictionaryName key ?key \...? value'+::
2012     This operation (the companion to `dict set`) takes the name of a
2013     variable containing a dictionary value and places an updated
2014     dictionary value in that variable that does not contain a mapping
2015     for the given key. Where multiple keys are present, this describes
2016     a path through nested dictionaries to the mapping to remove. At
2017     least one key must be specified, but the last key on the key-path
2018     need not exist. All other components on the path must exist.
2020 +*dict with* 'dictionaryName key ?key \...? script'+::
2021     Execute the Tcl script in +'script'+ with the value for each
2022     key in +'dictionaryName'+ mapped to a variable with the same
2023     name. Where one or more keys are given, these indicate a chain
2024     of nested dictionaries, with the innermost dictionary being the
2025     one opened out for the execution of body. Making +'dictionaryName'+
2026     unreadable will make the updates to the dictionary be discarded,
2027     and this also happens if the contents of +'dictionaryName'+ are
2028     adjusted so that the chain of dictionaries no longer exists.
2029     The result of `dict with` is (unless some kind of error occurs)
2030     the result of the evaluation of body.
2031  ::
2032     The variables are mapped in the scope enclosing the `dict with`;
2033     it is recommended that this command only be used in a local
2034     scope (procedure). Because of this, the variables set by
2035     `dict with` will continue to exist after the command finishes (unless
2036     explicitly unset). Note that changes to the contents of +'dictionaryName'+
2037     only happen when +'script'+ terminates.
2039 +*dict for, values, incr, append, lappend, update, info, replace*+ to be documented...
2043 +*env* '?name? ?default?'+
2045 If +'name'+ is supplied, returns the value of +'name'+ from the initial
2046 environment (see getenv(3)). An error is returned if +'name'+ does not
2047 exist in the environment, unless +'default'+ is supplied - in which case
2048 that value is returned instead.
2050 If no arguments are supplied, returns a list of all environment variables
2051 and their values as +{name value \...}+
2053 See also the global variable +::env+
2057 +*eof* 'fileId'+
2059 +'fileId' *eof*+
2061 Returns 1 if an end-of-file condition has occurred on +'fileId'+,
2062 0 otherwise.
2064 +'fileId'+ must have been the return value from a previous call to `open`,
2065 or it may be +stdin+, +stdout+, or +stderr+ to refer to one of the
2066 standard I/O channels.
2068 error
2069 ~~~~~
2070 +*error* 'message ?stacktrace?'+
2072 Returns a +JIM_ERR+ code, which causes command interpretation to be
2073 unwound.  +'message'+ is a string that is returned to the application
2074 to indicate what went wrong.
2076 If the +'stacktrace'+ argument is provided and is non-empty,
2077 it is used to initialize the stacktrace.
2079 This feature is most useful in conjunction with the `catch` command:
2080 if a caught error cannot be handled successfully, +'stacktrace'+ can be used
2081 to return a stack trace reflecting the original point of occurrence
2082 of the error:
2084     catch {...} errMsg
2085     ...
2086     error $errMsg [info stacktrace]
2088 See also `errorInfo`, `info stacktrace`, `catch` and `return`
2090 errorInfo
2091 ~~~~~~~~~
2092 +*errorInfo* 'error ?stacktrace?'+
2094 Returns a human-readable representation of the given error message and stack trace.
2095 Typical usage is:
2097     if {[catch {...} error]} {
2098         puts stderr [errorInfo $error [info stacktrace]]
2099         exit 1
2100     }
2102 See also `error`.
2104 eval
2105 ~~~~
2106 +*eval* 'arg ?arg\...?'+
2108 `eval` takes one or more arguments, which together comprise a Tcl
2109 command (or collection of Tcl commands separated by newlines in the
2110 usual way).  `eval` concatenates all its arguments in the same
2111 fashion as the `concat` command, passes the concatenated string to the
2112 Tcl interpreter recursively, and returns the result of that
2113 evaluation (or any error generated by it).
2115 exec
2116 ~~~~
2117 +*exec* 'arg ?arg\...?'+
2119 This command treats its arguments as the specification
2120 of one or more UNIX commands to execute as subprocesses.
2121 The commands take the form of a standard shell pipeline;
2122 +|+ arguments separate commands in the
2123 pipeline and cause standard output of the preceding command
2124 to be piped into standard input of the next command (or +|&+ for
2125 both standard output and standard error).
2127 Under normal conditions the result of the `exec` command
2128 consists of the standard output produced by the last command
2129 in the pipeline followed by the standard error output.
2131 If any of the commands writes to its standard error file,
2132 then this will be included in the result after the standard output
2133 of the last command.
2135 Note that unlike Tcl, data written to standard error does not cause
2136 `exec` to return an error.
2138 If any of the commands in the pipeline exit abnormally or
2139 are killed or suspended, then `exec` will return an error.
2140 If no standard error output was produced, or is redirected,
2141 the error message will include the normal result, as above,
2142 followed by error messages describing the abnormal terminations.
2144 If any standard error output was produced, these abnormal termination
2145 messages are suppressed.
2147 If the last character of the result or error message
2148 is a newline then that character is deleted from the result
2149 or error message for consistency with normal
2150 Tcl return values.
2152 An +'arg'+ may have one of the following special forms:
2154 +>filename+::
2155     The standard output of the last command in the pipeline
2156     is redirected to the file.  In this situation `exec`
2157     will normally return an empty string.
2159 +>>filename+::
2160     As above, but append to the file.
2162 +>@fileId+::
2163     The standard output of the last command in the pipeline is
2164     redirected to the given (writable) file descriptor (e.g. stdout,
2165     stderr, or the result of `open`). In this situation `exec`
2166     will normally return an empty string.
2168 +2>filename+::
2169     The standard error of the last command in the pipeline
2170     is redirected to the file.
2172 +2>>filename+::
2173     As above, but append to the file.
2175 +2>@fileId+::
2176     The standard error of the last command in the pipeline is
2177     redirected to the given (writable) file descriptor.
2179 +2>@1+::
2180     The standard error of the last command in the pipeline is
2181     redirected to the same file descriptor as the standard output.
2183 +>&filename+::
2184     Both the standard output and standard error of the last command
2185     in the pipeline is redirected to the file.
2187 +>>&filename+::
2188     As above, but append to the file.
2190 +<filename+::
2191     The standard input of the first command in the pipeline
2192     is taken from the file.
2194 +<<string+::
2195     The standard input of the first command is taken as the
2196     given immediate value.
2198 +<@fileId+::
2199     The standard input of the first command in the pipeline
2200     is taken from the given (readable) file descriptor.
2202 If there is no redirection of standard input, standard error
2203 or standard output, these are connected to the corresponding
2204 input or output of the application.
2206 If the last +'arg'+ is +&+ then the command will be
2207 executed in background.
2208 In this case the standard output from the last command
2209 in the pipeline will
2210 go to the application's standard output unless
2211 redirected in the command, and error output from all
2212 the commands in the pipeline will go to the application's
2213 standard error file. The return value of exec in this case
2214 is a list of process ids (pids) in the pipeline.
2216 Each +'arg'+ becomes one word for a command, except for
2217 +|+, +<+, +<<+, +>+, and +&+ arguments, and the
2218 arguments that follow +<+, +<<+, and +>+.
2220 The first word in each command is taken as the command name;
2221 the directories in the PATH environment variable are searched for
2222 an executable by the given name.
2224 No `glob` expansion or other shell-like substitutions
2225 are performed on the arguments to commands.
2227 If the command fails, the global $::errorCode (and the -errorcode
2228 option in `catch`) will be set to a list, as follows:
2230 +*CHILDKILLED* 'pid sigName msg'+::
2231         This format is used when a child process has been killed
2232         because of a signal. The pid element will be the process's
2233         identifier (in decimal). The sigName element will be the
2234         symbolic name of the signal that caused the process to
2235         terminate; it will be one of the names from the include
2236         file signal.h, such as SIGPIPE. The msg element will be a
2237         short human-readable message describing the signal, such
2238         as "write on pipe with no readers" for SIGPIPE.
2240 +*CHILDSUSP* 'pid sigName msg'+::
2241         This format is used when a child process has been suspended
2242         because of a signal. The pid element will be the process's
2243         identifier, in decimal. The sigName element will be the
2244         symbolic name of the signal that caused the process to
2245         suspend; this will be one of the names from the include
2246         file signal.h, such as SIGTTIN. The msg element will be a
2247         short human-readable message describing the signal, such
2248         as "background tty read" for SIGTTIN.
2250 +*CHILDSTATUS* 'pid code'+::
2251         This format is used when a child process has exited with a
2252         non-zero exit status. The pid element will be the process's
2253         identifier (in decimal) and the code element will be the
2254         exit code returned by the process (also in decimal).
2256 The environment for the executed command is set from $::env (unless
2257 this variable is unset, in which case the original environment is used).
2259 exists
2260 ~~~~~~
2261 +*exists ?-var|-proc|-command|-alias?* 'name'+
2263 Checks the existence of the given variable, procedure, command
2264 or alias respectively and returns 1 if it exists or 0 if not.  This command
2265 provides a more simplified/convenient version of `info exists`,
2266 `info procs` and `info commands`.
2268 If the type is omitted, a type of '-var' is used. The type may be abbreviated.
2270 exit
2271 ~~~~
2272 +*exit* '?returnCode?'+
2274 Terminate the process, returning +'returnCode'+ to the
2275 parent as the exit status.
2277 If +'returnCode'+ isn't specified then it defaults
2278 to 0.
2280 Note that exit can be caught with `catch`.
2282 expr
2283 ~~~~
2284 +*expr* 'arg'+
2286 Calls the expression processor to evaluate +'arg'+, and returns
2287 the result as a string.  See the section EXPRESSIONS above.
2289 Note that Jim supports a shorthand syntax for `expr` as +$(\...)+
2290 The following two are identical.
2292   set x [expr {3 * 2 + 1}]
2293   set x $(3 * 2 + 1)
2295 file
2296 ~~~~
2297 +*file* 'option name ?arg\...?'+
2299 Operate on a file or a file name.  +'name'+ is the name of a file.
2301 +'option'+ indicates what to do with the file name.  Any unique
2302 abbreviation for +'option'+ is acceptable.  The valid options are:
2304 +*file atime* 'name'+::
2305     Return a decimal string giving the time at which file +'name'+
2306     was last accessed.  The time is measured in the standard UNIX
2307     fashion as seconds from a fixed starting time (often January 1, 1970).
2308     If the file doesn't exist or its access time cannot be queried then an
2309     error is generated.
2311 +*file copy ?-force?* 'source target'+::
2312     Copies file +'source'+ to file +'target'+. The source file must exist.
2313     The target file must not exist, unless +-force+ is specified.
2315 +*file delete ?-force? ?--?* 'name\...'+::
2316     Deletes file or directory +'name'+. If the file or directory doesn't exist, nothing happens.
2317     If it can't be deleted, an error is generated. Non-empty directories will not be deleted
2318     unless the +-force+ options is given. In this case no errors will be generated, even
2319     if the file/directory can't be deleted. Use +'--'+ if there is any possibility of
2320     the first name being +'-force'+.
2322 +*file dirname* 'name'+::
2323     Return all of the characters in +'name'+ up to but not including
2324     the last slash character.  If there are no slashes in +'name'+
2325     then return +.+ (a single dot).  If the last slash in +'name'+ is its first
2326     character, then return +/+.
2328 +*file executable* 'name'+::
2329     Return '1' if file +'name'+ is executable by
2330     the current user, '0' otherwise.
2332 +*file exists* 'name'+::
2333     Return '1' if file +'name'+ exists and the current user has
2334     search privileges for the directories leading to it, '0' otherwise.
2336 +*file extension* 'name'+::
2337     Return all of the characters in +'name'+ after and including the
2338     last dot in +'name'+.  If there is no dot in +'name'+ then return
2339     the empty string.
2341 +*file isdirectory* 'name'+::
2342     Return '1' if file +'name'+ is a directory,
2343     '0' otherwise.
2345 +*file isfile* 'name'+::
2346     Return '1' if file +'name'+ is a regular file,
2347     '0' otherwise.
2349 +*file join* 'arg\...'+::
2350     Joins multiple path components. Note that if any components is
2351     an absolute path, the preceding components are ignored.
2352     Thus +"`file` join /tmp /root"+ returns +"/root"+.
2354 +*file link* ?*-hard|-symbolic*? 'newname target'+::
2355     Creates a hard link (default) or symbolic link from +'newname'+ to +'target'+.
2356     Note that the sense of this command is the opposite of `file rename` and `file copy`
2357     and also of `ln`, but this is compatible with Tcl.
2358     An error is returned if +'target'+ doesn't exist or +'newname'+ already exists.
2360 +*file lstat* 'name varName'+::
2361     Same as 'stat' option (see below) except uses the +'lstat'+
2362     kernel call instead of +'stat'+.  This means that if +'name'+
2363     refers to a symbolic link the information returned in +'varName'+
2364     is for the link rather than the file it refers to.  On systems that
2365     don't support symbolic links this option behaves exactly the same
2366     as the 'stat' option.
2368 +*file mkdir* 'dir1 ?dir2\...?'+::
2369     Creates each directory specified. For each pathname +'dir'+ specified,
2370     this command will create all non-existing parent directories
2371     as well as +'dir'+ itself. If an existing directory is specified,
2372     then no action is taken and no error is returned. Trying to
2373     overwrite an existing file with a directory will result in an
2374     error.  Arguments are processed in the order specified, halting
2375     at the first error, if any.
2377 +*file mtime* 'name ?time?'+::
2378     Return a decimal string giving the time at which file +'name'+
2379     was last modified.  The time is measured in the standard UNIX
2380     fashion as seconds from a fixed starting time (often January 1, 1970).
2381     If the file doesn't exist or its modified time cannot be queried then an
2382     error is generated. If +'time'+ is given, sets the modification time
2383     of the file to the given value.
2385 +*file mtimeus* 'name ?time_us?'+::
2386     As for `file mtime` except the time value is in microseconds
2387         since the epoch (see also `clock microseconds`).
2388         Note that some platforms and some filesystems don't support high
2389         resolution timestamps for files.
2391 +*file normalize* 'name'+::
2392     Return the normalized path of +'name'+. See 'realpath(3)'.
2394 +*file owned* 'name'+::
2395     Return '1' if file +'name'+ is owned by the current user,
2396     '0' otherwise.
2398 +*file readable* 'name'+::
2399     Return '1' if file +'name'+ is readable by
2400     the current user, '0' otherwise.
2402 +*file readlink* 'name'+::
2403     Returns the value of the symbolic link given by +'name'+ (i.e. the
2404     name of the file it points to).  If
2405     +'name'+ isn't a symbolic link or its value cannot be read, then
2406     an error is returned.  On systems that don't support symbolic links
2407     this option is undefined.
2409 +*file rename* ?*-force*? 'oldname' 'newname'+::
2410     Renames the file from the old name to the new name.
2411     If +'newname'+ already exists, an error is returned unless +'-force'+ is
2412     specified.
2414 +*file rootname* 'name'+::
2415     Return all of the characters in +'name'+ up to but not including
2416     the last '.' character in the name.  If +'name'+ doesn't contain
2417     a dot, then return +'name'+.
2419 +*file size* 'name'+::
2420     Return a decimal string giving the size of file +'name'+ in bytes.
2421     If the file doesn't exist or its size cannot be queried then an
2422     error is generated.
2424 +*file stat* 'name ?varName?'+::
2425     Invoke the 'stat' kernel call on +'name'+, and return the result
2426     as a dictionary with the following keys: 'atime',
2427     'ctime', 'dev', 'gid', 'ino', 'mode', 'mtime',
2428     'nlink', 'size', 'type', 'uid', 'mtimeus' (if supported - see `file mtimeus`)
2429     Each element except 'type' is a decimal string with the value of
2430     the corresponding field from the 'stat' return structure; see the
2431     manual entry for 'stat' for details on the meanings of the values.
2432     The 'type' element gives the type of the file in the same form
2433     returned by the command `file type`.
2434     If +'varName'+ is specified, it is taken to be the name of an array
2435     variable and the values are also stored into the array.
2437 +*file tail* 'name'+::
2438     Return all of the characters in +'name'+ after the last slash.
2439     If +'name'+ contains no slashes then return +'name'+.
2441 +*file tempfile* '?template?'+::
2442     Creates and returns the name of a unique temporary file. If +'template'+ is omitted, a
2443     default template will be used to place the file in /tmp. See 'mkstemp(3)' for
2444     the format of the template and security concerns.
2446 +*file type* 'name'+::
2447     Returns a string giving the type of file +'name'+, which will be
2448     one of +file+, +directory+, +characterSpecial+,
2449     +blockSpecial+, +fifo+, +link+, or +socket+.
2451 +*file writable* 'name'+::
2452     Return '1' if file +'name'+ is writable by
2453     the current user, '0' otherwise.
2455 The `file` commands that return 0/1 results are often used in
2456 conditional or looping commands, for example:
2458     if {![file exists foo]} {
2459         error {bad file name}
2460     } else {
2461         ...
2462     }
2464 finalize
2465 ~~~~~~~~
2466 +*finalize* 'reference ?command?'+
2468 If +'command'+ is omitted, returns the finalizer command for the given reference.
2470 Otherwise, sets a new finalizer command for the given reference. +'command'+ may be
2471 the empty string to remove the current finalizer.
2473 The reference must be a valid reference create with the `ref`
2474 command.
2476 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
2478 flush
2479 ~~~~~
2480 +*flush* 'fileId'+
2482 +'fileId' *flush*+
2484 Flushes any output that has been buffered for +'fileId'+.  +'fileId'+ must
2485 have been the return value from a previous call to `open`, or it may be
2486 +stdout+ or +stderr+ to access one of the standard I/O streams; it must
2487 refer to a file that was opened for writing.  This command returns an
2488 empty string.
2492 +*for* 'start test next body'+
2494 `for` is a looping command, similar in structure to the C `for` statement.
2495 The +'start'+, +'next'+, and +'body'+ arguments must be Tcl command strings,
2496 and +'test'+ is an expression string.
2498 The `for` command first invokes the Tcl interpreter to execute +'start'+.
2499 Then it repeatedly evaluates +'test'+ as an expression; if the result is
2500 non-zero it invokes the Tcl interpreter on +'body'+, then invokes the Tcl
2501 interpreter on +'next'+, then repeats the loop.  The command terminates
2502 when +'test'+ evaluates to 0.
2504 If a `continue` command is invoked within +'body'+ then any remaining
2505 commands in the current execution of +'body'+ are skipped; processing
2506 continues by invoking the Tcl interpreter on +'next'+, then evaluating
2507 +'test'+, and so on.
2509 If a `break` command is invoked within +'body'+ or +'next'+, then the `for`
2510 command will return immediately.
2512 The operation of `break` and `continue` are similar to the corresponding
2513 statements in C.
2515 `for` returns an empty string.
2517 foreach
2518 ~~~~~~~
2519 +*foreach* 'varName list body'+
2521 +*foreach* 'varList list ?varList2 list2 \...? body'+
2523 In this command, +'varName'+ is the name of a variable, +'list'+
2524 is a list of values to assign to +'varName'+, and +'body'+ is a
2525 collection of Tcl commands.
2527 For each field in +'list'+ (in order from left to right), `foreach` assigns
2528 the contents of the field to +'varName'+ (as if the `lindex` command
2529 had been used to extract the field), then calls the Tcl interpreter to
2530 execute +'body'+.
2532 If instead of being a simple name, +'varList'+ is used, multiple assignments
2533 are made each time through the loop, one for each element of +'varList'+.
2535 For example, if there are two elements in +'varList'+ and six elements in
2536 the list, the loop will be executed three times.
2538 If the length of the list doesn't evenly divide by the number of elements
2539 in +'varList'+, the value of the remaining variables in the last iteration
2540 of the loop are undefined.
2542 The `break` and `continue` statements may be invoked inside +'body'+,
2543 with the same effect as in the `for` command.
2545 `foreach` returns an empty string.
2547 format
2548 ~~~~~~
2549 +*format* 'formatString ?arg \...?'+
2551 This command generates a formatted string in the same way as the
2552 C 'sprintf' procedure (it uses 'sprintf' in its
2553 implementation).  +'formatString'+ indicates how to format
2554 the result, using +%+ fields as in 'sprintf', and the additional
2555 arguments, if any, provide values to be substituted into the result.
2557 All of the 'sprintf' options are valid; see the 'sprintf'
2558 man page for details.  Each +'arg'+ must match the expected type
2559 from the +%+ field in +'formatString'+; the `format` command
2560 converts each argument to the correct type (floating, integer, etc.)
2561 before passing it to 'sprintf' for formatting.
2563 The only unusual conversion is for +%c+; in this case the argument
2564 must be a decimal string, which will then be converted to the corresponding
2565 ASCII (or UTF-8) character value.
2567 In addition, Jim Tcl provides basic support for conversion to binary with +%b+.
2569 `format` does backslash substitution on its +'formatString'+
2570 argument, so backslash sequences in +'formatString'+ will be handled
2571 correctly even if the argument is in braces.
2573 The return value from `format` is the formatted string.
2575 getref
2576 ~~~~~~
2577 +*getref* 'reference'+
2579 Returns the string associated with +'reference'+. The reference must
2580 be a valid reference create with the `ref` command.
2582 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
2584 gets
2585 ~~~~
2586 +*gets* 'fileId ?varName?'+
2588 +'fileId' *gets* '?varName?'+
2590 Reads the next line from the file given by +'fileId'+ and discards
2591 the terminating newline character.
2593 If +'varName'+ is specified, then the line is placed in the variable
2594 by that name and the return value is a count of the number of characters
2595 read (not including the newline).
2597 If the end of the file is reached before reading
2598 any characters then -1 is returned and +'varName'+ is set to an
2599 empty string.
2601 If +'varName'+ is not specified then the return value will be
2602 the line (minus the newline character) or an empty string if
2603 the end of the file is reached before reading any characters.
2605 An empty string will also be returned if a line contains no characters
2606 except the newline, so `eof` may have to be used to determine
2607 what really happened.
2609 If the last character in the file is not a newline character, then
2610 `gets` behaves as if there were an additional newline character
2611 at the end of the file.
2613 +'fileId'+ must be +stdin+ or the return value from a previous
2614 call to `open`; it must refer to a file that was opened
2615 for reading.
2617 glob
2618 ~~~~
2619 +*glob* ?*-nocomplain*? ?*-directory* 'dir'? ?*-tails*? ?*--*? 'pattern ?pattern \...?'+
2621 This command performs filename globbing, using csh rules.  The returned
2622 value from `glob` is the list of expanded filenames.
2624 If +-nocomplain+ is specified as the first argument then an empty
2625 list may be returned;  otherwise an error is returned if the expanded
2626 list is empty.  The +-nocomplain+ argument must be provided
2627 exactly: an abbreviation will not be accepted.
2629 If +-directory+ is given, the +'dir'+ is understood to contain a
2630 directory name to search in. This allows globbing inside directories
2631 whose names may contain glob-sensitive characters. The returned names
2632 include the directory name unless +'-tails'+ is specified.
2634 If +'-tails'+ is specified, along with +-directory+, the returned names
2635 are relative to the given directory.
2637 global
2638 ~~~~~~
2640 +*global* 'varName ?varName \...?'+
2642 This command is ignored unless a Tcl procedure is being interpreted.
2643 If so, then it declares each given +'varName'+ to be a global variable
2644 rather than a local one.  For the duration of the current procedure
2645 (and only while executing in the current procedure), any reference to
2646 +'varName'+ will be bound to a global variable instead
2647 of a local one.
2649 An alternative to using `global` is to use the +::+ prefix
2650 to explicitly name a variable in the global scope.
2654 +*if* 'expr1' ?*then*? 'body1' *elseif* 'expr2' ?*then*? 'body2' *elseif* \... ?*else*? ?'bodyN'?+
2656 The `if` command evaluates +'expr1'+ as an expression (in the same way
2657 that `expr` evaluates its argument).  The value of the expression must
2658 be numeric; if it is non-zero then +'body1'+ is executed by passing it to
2659 the Tcl interpreter.
2661 Otherwise +'expr2'+ is evaluated as an expression and if it is non-zero
2662 then +'body2'+ is executed, and so on.
2664 If none of the expressions evaluates to non-zero then +'bodyN'+ is executed.
2666 The +then+ and +else+ arguments are optional "noise words" to make the
2667 command easier to read.
2669 There may be any number of +elseif+ clauses, including zero.  +'bodyN'+
2670 may also be omitted as long as +else+ is omitted too.
2672 The return value from the command is the result of the body script that
2673 was executed, or an empty string if none of the expressions was non-zero
2674 and there was no +'bodyN'+.
2676 incr
2677 ~~~~
2678 +*incr* 'varName ?increment?'+
2680 Increment the value stored in the variable whose name is +'varName'+.
2681 The value of the variable must be integral.
2683 If +'increment'+ is supplied then its value (which must be an
2684 integer) is added to the value of variable +'varName'+;  otherwise
2685 1 is added to +'varName'+.
2687 The new value is stored as a decimal string in variable +'varName'+
2688 and also returned as result.
2690 If the variable does not exist, the variable is implicitly created
2691 and set to +0+ first.
2693 info
2694 ~~~~
2696 +*info* 'option ?arg\...?'+::
2698 Provide information about various internals to the Tcl interpreter.
2699 The legal +'option'+'s (which may be abbreviated) are:
2701 +*info args* 'procname'+::
2702     Returns a list containing the names of the arguments to procedure
2703     +'procname'+, in order.  +'procname'+ must be the name of a
2704     Tcl command procedure.
2706 +*info alias* 'command'+::
2707     +'command'+ must be an alias created with `alias`. In which case the target
2708     command and arguments, as passed to `alias` are returned. See `exists -alias`
2710 +*info body* 'procname'+::
2711     Returns the body of procedure +'procname'+.  +'procname'+ must be
2712     the name of a Tcl command procedure.
2714 +*info channels*+::
2715     Returns a list of all open file handles from `open` or `socket`
2717 +*info commands* ?'pattern'?+::
2718     If +'pattern'+ isn't specified, returns a list of names of all the
2719     Tcl commands, including both the built-in commands written in C and
2720     the command procedures defined using the `proc` command.
2721     If +'pattern'+ is specified, only those names matching +'pattern'+
2722     are returned.  Matching is determined using the same rules as for
2723     `string match`.
2725 +*info complete* 'command' ?'missing'?+::
2726     Returns 1 if +'command'+ is a complete Tcl command in the sense of
2727     having no unclosed quotes, braces, brackets or array element names,
2728     If the command doesn't appear to be complete then 0 is returned.
2729     This command is typically used in line-oriented input environments
2730     to allow users to type in commands that span multiple lines;  if the
2731     command isn't complete, the script can delay evaluating it until additional
2732     lines have been typed to complete the command. If +'varName'+ is specified, the
2733     missing character is stored in the variable with that name.
2735 +*info exists* 'varName'+::
2736     Returns '1' if the variable named +'varName'+ exists in the
2737     current context (either as a global or local variable), returns '0'
2738     otherwise.
2740 +*info frame* ?'number'?+::
2741     If +'number'+ is not specified, this command returns a number
2742     which is the same result as `info level` - the current stack frame level.
2743     If +'number'+ is specified, then the result is a list consisting of the procedure,
2744     filename and line number for the procedure call at level +'number'+ on the stack.
2745     If +'number'+ is positive then it selects a particular stack level (1 refers
2746     to the top-most active procedure, 2 to the procedure it called, and
2747     so on); otherwise it gives a level relative to the current level
2748     (0 refers to the current procedure, -1 to its caller, and so on).
2749     The level has an identical meaning to `info level`.
2751 +*info globals* ?'pattern'?+::
2752     If +'pattern'+ isn't specified, returns a list of all the names
2753     of currently-defined global variables.
2754     If +'pattern'+ is specified, only those names matching +'pattern'+
2755     are returned.  Matching is determined using the same rules as for
2756     `string match`.
2758 +*info hostname*+::
2759     An alias for `os.gethostname` for compatibility with Tcl 6.x
2761 +*info level* ?'number'?+::
2762     If +'number'+ is not specified, this command returns a number
2763     giving the stack level of the invoking procedure, or 0 if the
2764     command is invoked at top-level.  If +'number'+ is specified,
2765     then the result is a list consisting of the name and arguments for the
2766     procedure call at level +'number'+ on the stack.  If +'number'+
2767     is positive then it selects a particular stack level (1 refers
2768     to the top-most active procedure, 2 to the procedure it called, and
2769     so on); otherwise it gives a level relative to the current level
2770     (0 refers to the current procedure, -1 to its caller, and so on).
2771     See the `uplevel` command for more information on what stack
2772     levels mean.
2774 +*info locals* ?'pattern'?+::
2775     If +'pattern'+ isn't specified, returns a list of all the names
2776     of currently-defined local variables, including arguments to the
2777     current procedure, if any.  Variables defined with the `global`
2778     and `upvar` commands will not be returned.  If +'pattern'+ is
2779     specified, only those names matching +'pattern'+ are returned.
2780     Matching is determined using the same rules as for `string match`.
2782 +*info nameofexecutable*+::
2783     Returns the name of the binary file from which the application
2784     was invoked. A full path will be returned, unless the path
2785     can't be determined, in which case the empty string will be returned.
2787 +*info procs* ?'pattern'?+::
2788     If +'pattern'+ isn't specified, returns a list of all the
2789     names of Tcl command procedures.
2790     If +'pattern'+ is specified, only those names matching +'pattern'+
2791     are returned.  Matching is determined using the same rules as for
2792     `string match`.
2794 +*info references*+::
2795     Returns a list of all references which have not yet been garbage
2796     collected.
2798 +*info returncodes* ?'code'?+::
2799     Returns a list representing the mapping of standard return codes
2800     to names. e.g. +{0 ok 1 error 2 return \...}+. If a code is given,
2801     instead returns the name for the given code.
2803 +*info script*+::
2804     If a Tcl script file is currently being evaluated (i.e. there is a
2805     call to 'Jim_EvalFile' active or there is an active invocation
2806     of the `source` command), then this command returns the name
2807     of the innermost file being processed.  Otherwise the command returns an
2808     empty string.
2810 +*info source* 'script ?filename line?'+::
2811     With a single argument, returns the original source location of the given script as a list of
2812     +{filename linenumber}+. If the source location can't be determined, the
2813     list +{{} 0}+ is returned. If +'filename'+ and +'line'+ are given, returns a copy
2814     of +'script'+ with the associate source information. This can be useful to produce
2815     useful messages from `eval`, etc. if the original source information may be lost.
2817 +*info stacktrace*+::
2818     After an error is caught with `catch`, returns the stack trace as a list
2819     of +{procedure filename line \...}+.
2821 +*info statics* 'procname'+::
2822     Returns a dictionary of the static variables of procedure
2823     +'procname'+.  +'procname'+ must be the name of a Tcl command
2824     procedure. An empty dictionary is returned if the procedure has
2825     no static variables.
2827 +*info version*+::
2828     Returns the version number for this version of Jim in the form +*x.yy*+.
2830 +*info vars* ?'pattern'?+::
2831     If +'pattern'+ isn't specified,
2832     returns a list of all the names of currently-visible variables, including
2833     both locals and currently-visible globals.
2834     If +'pattern'+ is specified, only those names matching +'pattern'+
2835     are returned.  Matching is determined using the same rules as for
2836     `string match`.
2838 join
2839 ~~~~
2840 +*join* 'list ?joinString?'+
2842 The +'list'+ argument must be a valid Tcl list.  This command returns the
2843 string formed by joining all of the elements of +'list'+ together with
2844 +'joinString'+ separating each adjacent pair of elements.
2846 The +'joinString'+ argument defaults to a space character.
2848 kill
2849 ~~~~
2850 +*kill* ?'SIG'|*-0*? 'pid'+
2852 Sends the given signal to the process identified by +'pid'+.
2854 The signal may be specified by name or number in one of the following forms:
2856 * +TERM+
2857 * +SIGTERM+
2858 * +-TERM+
2859 * +15+
2860 * +-15+
2862 The signal name may be in either upper or lower case.
2864 The special signal name +-0+ simply checks that a signal +'could'+ be sent.
2866 If no signal is specified, SIGTERM is used.
2868 An error is raised if the signal could not be delivered.
2870 lambda
2871 ~~~~~~
2872 +*lambda* 'args ?statics? body'+
2874 The `lambda` command is identical to `proc`, except rather than
2875 creating a named procedure, it creates an anonymous procedure and returns
2876 the name of the procedure.
2878 See `proc` and GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
2880 lappend
2881 ~~~~~~~
2882 +*lappend* 'varName value ?value value \...?'+
2884 Treat the variable given by +'varName'+ as a list and append each of
2885 the +'value'+ arguments to that list as a separate element, with spaces
2886 between elements.
2888 If +'varName'+ doesn't exist, it is created as a list with elements given
2889 by the +'value'+ arguments. `lappend` is similar to `append` except that
2890 each +'value'+ is appended as a list element rather than raw text.
2892 This command provides a relatively efficient way to build up large lists.
2893 For example,
2895     lappend a $b
2897 is much more efficient than
2899     set a [concat $a [list $b]]
2901 when +$a+ is long.
2903 lassign
2904 ~~~~~~~
2905 +*lassign* 'list varName ?varName \...?'+
2907 This command treats the value +'list'+ as a list and assigns successive elements from that list to
2908 the variables given by the +'varName'+ arguments in order. If there are more variable names than
2909 list elements, the remaining variables are set to the empty string. If there are more list elements
2910 than variables, a list of unassigned elements is returned.
2912     jim> lassign {1 2 3} a b; puts a=$a,b=$b
2913     3
2914     a=1,b=2
2916 local
2917 ~~~~~
2918 +*local* 'cmd ?arg\...?'+
2920 First, `local` evaluates +'cmd'+ with the given arguments. The return value must
2921 be the name of an existing command, which is marked as having local scope.
2922 This means that when the current procedure exits, the specified
2923 command is deleted. This can be useful with `lambda`, local procedures or
2924 to automatically close a filehandle.
2926 In addition, if a command already exists with the same name,
2927 the existing command will be kept rather than deleted, and may be called
2928 via `upcall`. The previous command will be restored when the current
2929 procedure exits. See `upcall` for more details.
2931 In this example, a local procedure is created. Note that the procedure
2932 continues to have global scope while it is active.
2934     proc outer {} {
2935       # proc ... returns "inner" which is marked local
2936       local proc inner {} {
2937         # will be deleted when 'outer' exits
2938       }
2940       inner
2941       ...
2942     }
2944 In this example, the lambda is deleted at the end of the procedure rather
2945 than waiting until garbage collection.
2947     proc outer {} {
2948       set x [lambda inner {args} {
2949         # will be deleted when 'outer' exits
2950       }]
2951       # Use 'function' here which simply returns $x
2952       local function $x
2954       $x ...
2955       ...
2956     }
2958 loop
2959 ~~~~
2960 +*loop* 'var first limit ?incr? body'+
2962 Similar to `for` except simpler and possibly more efficient.
2963 With a positive increment, equivalent to:
2965   for {set var $first} {$var < $limit} {incr var $incr} $body
2967 If +'incr'+ is not specified, 1 is used.
2968 Note that setting the loop variable inside the loop does not
2969 affect the loop count.
2971 lindex
2972 ~~~~~~
2973 +*lindex* 'list ?index ...?'+
2975 Treats +'list'+ as a Tcl list and returns element +'index'+ from it
2976 (0 refers to the first element of the list).
2977 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
2979 In extracting the element, +'lindex'+ observes the same rules concerning
2980 braces and quotes and backslashes as the Tcl command interpreter; however,
2981 variable substitution and command substitution do not occur.
2983 If no index values are given, simply returns +'list'+
2985 If +'index'+ is negative or greater than or equal to the number of elements
2986 in +'list'+, then an empty string is returned.
2988 If additional index arguments are supplied, then each argument is
2989 used in turn to select an element from the previous indexing
2990 operation, allowing the script to select elements from sublists.
2992 linsert
2993 ~~~~~~~
2994 +*linsert* 'list index element ?element element \...?'+
2996 This command produces a new list from +'list'+ by inserting all
2997 of the +'element'+ arguments just before the element +'index'+
2998 of +'list'+. Each +'element'+ argument will become
2999 a separate element of the new list. If +'index'+ is less than
3000 or equal to zero, then the new elements are inserted at the
3001 beginning of the list. If +'index'+ is greater than or equal
3002 to the number of elements in the list, then the new elements are
3003 appended to the list.
3005 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
3007 list
3008 ~~~~
3010 +*list* 'arg ?arg \...?'+
3012 This command returns a list comprised of all the arguments, +'arg'+. Braces
3013 and backslashes get added as necessary, so that the `lindex` command
3014 may be used on the result to re-extract the original arguments, and also
3015 so that `eval` may be used to execute the resulting list, with
3016 +'arg1'+ comprising the command's name and the other args comprising
3017 its arguments. `list` produces slightly different results than
3018 `concat`:  `concat` removes one level of grouping before forming
3019 the list, while `list` works directly from the original arguments.
3020 For example, the command
3022     list a b {c d e} {f {g h}}
3024 will return
3026     a b {c d e} {f {g h}}
3028 while `concat` with the same arguments will return
3030     a b c d e f {g h}
3032 llength
3033 ~~~~~~~
3034 +*llength* 'list'+
3036 Treats +'list'+ as a list and returns a decimal string giving
3037 the number of elements in it.
3039 lset
3040 ~~~~
3041 +*lset* 'varName ?index ..? newValue'+
3043 Sets an element in a list.
3045 The `lset` command accepts a parameter, +'varName'+, which it interprets
3046 as the name of a variable containing a Tcl list. It also accepts
3047 zero or more indices into the list. Finally, it accepts a new value
3048 for an element of varName. If no indices are presented, the command
3049 takes the form:
3051     lset varName newValue
3053 In this case, newValue replaces the old value of the variable
3054 varName.
3056 When presented with a single index, the `lset` command
3057 treats the content of the varName variable as a Tcl list. It addresses
3058 the index'th element in it (0 refers to the first element of the
3059 list). When interpreting the list, `lset` observes the same rules
3060 concerning braces and quotes and backslashes as the Tcl command
3061 interpreter; however, variable substitution and command substitution
3062 do not occur. The command constructs a new list in which the
3063 designated element is replaced with newValue. This new list is
3064 stored in the variable varName, and is also the return value from
3065 the `lset` command.
3067 If index is negative or greater than or equal to the number of
3068 elements in $varName, then an error occurs.
3070 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
3072 If additional index arguments are supplied, then each argument is
3073 used in turn to address an element within a sublist designated by
3074 the previous indexing operation, allowing the script to alter
3075 elements in sublists. The command,
3077     lset a 1 2 newValue
3079 replaces element 2 of sublist 1 with +'newValue'+.
3081 The integer appearing in each index argument must be greater than
3082 or equal to zero. The integer appearing in each index argument must
3083 be strictly less than the length of the corresponding list. In other
3084 words, the `lset` command cannot change the size of a list. If an
3085 index is outside the permitted range, an error is reported.
3087 lmap
3088 ~~~~
3090 +*lmap* 'varName list body'+
3092 +*lmap* 'varList list ?varList2 list2 \...? body'+
3094 `lmap` is a "collecting" `foreach` which returns a list of its results.
3096 For example:
3098     jim> lmap i {1 2 3 4 5} {expr $i*$i}
3099     1 4 9 16 25
3100     jim> lmap a {1 2 3} b {A B C} {list $a $b}
3101     {1 A} {2 B} {3 C}
3103 If the body invokes `continue`, no value is added for this iteration.
3104 If the body invokes `break`, the loop ends and no more values are added.
3106 load
3107 ~~~~
3108 +*load* 'filename'+
3110 Loads the dynamic extension, +'filename'+. Generally the filename should have
3111 the extension +.so+. The initialisation function for the module must be based
3112 on the name of the file. For example loading +hwaccess.so+ will invoke
3113 the initialisation function, +Jim_hwaccessInit+. Normally the `load` command
3114 should not be used directly. Instead it is invoked automatically by `package require`.
3116 lrange
3117 ~~~~~~
3118 +*lrange* 'list first last'+
3120 +'list'+ must be a valid Tcl list. This command will return a new
3121 list consisting of elements +'first'+ through +'last'+, inclusive.
3123 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
3125 If +'last'+ is greater than or equal to the number of elements
3126 in the list, then it is treated as if it were +end+.
3128 If +'first'+ is greater than +'last'+ then an empty string
3129 is returned.
3131 Note: +"`lrange` 'list first first'"+ does not always produce the
3132 same result as +"`lindex` 'list first'"+ (although it often does
3133 for simple fields that aren't enclosed in braces); it does, however,
3134 produce exactly the same results as +"`list` [`lindex` 'list first']"+
3136 lreplace
3137 ~~~~~~~~
3139 +*lreplace* 'list first last ?element element \...?'+
3141 Returns a new list formed by replacing one or more elements of
3142 +'list'+ with the +'element'+ arguments.
3144 +'first'+ gives the index in +'list'+ of the first element
3145 to be replaced.
3147 If +'first'+ is less than zero then it refers to the first
3148 element of +'list'+;  the element indicated by +'first'+
3149 must exist in the list.
3151 +'last'+ gives the index in +'list'+ of the last element
3152 to be replaced;  it must be greater than or equal to +'first'+.
3154 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
3156 The +'element'+ arguments specify zero or more new arguments to
3157 be added to the list in place of those that were deleted.
3159 Each +'element'+ argument will become a separate element of
3160 the list.
3162 If no +'element'+ arguments are specified, then the elements
3163 between +'first'+ and +'last'+ are simply deleted.
3165 lrepeat
3166 ~~~~~~~~
3167 +*lrepeat* 'number element1 ?element2 \...?'+
3169 Build a list by repeating elements +'number'+ times (which must be
3170 a positive integer).
3172     jim> lrepeat 3 a b
3173     a b a b a b
3175 lreverse
3176 ~~~~~~~~
3177 +*lreverse* 'list'+
3179 Returns the list in reverse order.
3181     jim> lreverse {1 2 3}
3182     3 2 1
3184 lsearch
3185 ~~~~~~~
3186 +*lsearch* '?options? list pattern'+
3188 This command searches the elements +'list'+ to see if one of them matches +'pattern'+. If so, the
3189 command returns the index of the first matching element (unless the options +-all+, +-inline+ or +-bool+ are
3190 specified.) If not, the command returns -1. The option arguments indicates how the elements of
3191 the list are to be matched against pattern and must have one of the values below:
3193 *Note* that this command is different from Tcl in that default match type is +-exact+ rather than +-glob+.
3195 +*-exact*+::
3196     +'pattern'+ is a literal string that is compared for exact equality against each list element.
3197     This is the default.
3199 +*-glob*+::
3200     +'pattern'+ is a glob-style pattern which is matched against each list element using the same
3201     rules as the string match command.
3203 +*-regexp*+::
3204     +'pattern'+ is treated as a regular expression and matched against each list element using
3205     the rules described by `regexp`.
3207 +*-command* 'cmdname'+::
3208     +'cmdname'+ is a command which is used to match the pattern against each element of the
3209     list. It is invoked as +'cmdname' ?*-nocase*? 'pattern listvalue'+ and should return 1
3210     for a match, or 0 for no match.
3212 +*-all*+::
3213     Changes the result to be the list of all matching indices (or all matching values if
3214     +-inline+ is specified as well). If indices are returned, the indices will be in numeric
3215     order. If values are returned, the order of the values will be the order of those values
3216     within the input list.
3218 +*-inline*+::
3219     The matching value is returned instead of its index (or an empty string if no value
3220     matches). If +-all+ is also specified, then the result of the command is the list of all
3221     values that matched. The +-inline+ and +-bool+ options are mutually exclusive.
3223 +*-bool*+::
3224     Changes the result to '1' if a match was found, or '0' otherwise. If +-all+ is also specified,
3225     the result will be a list of '0' and '1' for each element of the list depending upon whether
3226     the corresponding element matches. The +-inline+ and +-bool+ options are mutually exclusive.
3228 +*-not*+::
3229     This negates the sense of the match, returning the index (or value
3230     if +-inline+ is specified) of the first non-matching value in the
3231     list. If +-bool+ is also specified, the '0' will be returned if a
3232     match is found, or '1' otherwise. If +-all+ is also specified,
3233     non-matches will be returned rather than matches.
3235 +*-nocase*+::
3236     Causes comparisons to be handled in a case-insensitive manner.
3238 lsort
3239 ~~~~~
3240 +*lsort* ?*-index* 'listindex'? ?*-nocase|-integer|-real|-command* 'cmdname'? ?*-unique*? ?*-decreasing*|*-increasing*? 'list'+
3242 Sort the elements of +'list'+, returning a new list in sorted order.
3243 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.
3245 If +-nocase+ is specified, comparisons are case-insensitive.
3247 If +-integer+ is specified, numeric sorting is used.
3249 If +-real+ is specified, floating point number sorting is used.
3251 If +-command 'cmdname'+ is specified, +'cmdname'+ is treated as a command
3252 name. For each comparison, +'cmdname $value1 $value2+' is called which
3253 should compare the values and return an integer less than, equal
3254 to, or greater than zero if the +'$value1'+ is to be considered less
3255 than, equal to, or greater than +'$value2'+, respectively.
3257 If +-decreasing+ is specified, the resulting list is in the opposite
3258 order to what it would be otherwise. +-increasing+ is the default.
3260 If +-unique+ is specified, then only the last set of duplicate elements found in the list will be retained.
3261 Note that duplicates are determined relative to the comparison used in the sort. Thus if +-index 0+ is used,
3262 +{1 a}+ and +{1 b}+ would be considered duplicates and only the second element, +{1 b}+, would be retained.
3264 If +-index 'listindex'+ is specified, each element of the list is treated as a list and
3265 the given index is extracted from the list for comparison. The list index may
3266 be any valid list index, such as +1+, +end+ or +end-2+.
3268 defer
3269 ~~~~~
3270 +*defer* 'script'+
3272 This command is a simple helper command to add a script to the '+$jim::defer+' variable
3273 that will run when the current proc or interpreter exits. For example:
3275     jim> proc a {} { defer {puts "Leaving a"}; puts "Exit" }
3276     jim> a
3277     Exit
3278     Leaving a
3280 If the '+$jim::defer+' variable exists, it is treated as a list of scripts to run
3281 when the proc or interpreter exits.
3283 open
3284 ~~~~
3285 +*open* 'fileName ?access?'+
3287 +*open* '|command-pipeline ?access?'+
3289 Opens a file and returns an identifier
3290 that may be used in future invocations
3291 of commands like `read`, `puts`, and `close`.
3292 +'fileName'+ gives the name of the file to open.
3294 The +'access'+ argument indicates the way in which the file is to be accessed.
3295 It may have any of the following values:
3297 +r+::
3298     Open the file for reading only; the file must already exist.
3300 +r++::
3301     Open the file for both reading and writing; the file must
3302     already exist.
3304 +w+::
3305     Open the file for writing only. Truncate it if it exists. If it doesn't
3306     exist, create a new file.
3308 +w++::
3309     Open the file for reading and writing. Truncate it if it exists.
3310     If it doesn't exist, create a new file.
3312 +a+::
3313     Open the file for writing only. The file must already exist, and the file
3314     is positioned so that new data is appended to the file.
3316 +a++::
3317     Open the file for reading and writing. If the file doesn't
3318     exist, create a new empty file. Set the initial access position
3319     to the end of the file.
3321 +'access'+ defaults to 'r'.
3323 If a file is opened for both reading and writing, then `seek`
3324 must be invoked between a read and a write, or vice versa.
3326 If the first character of +'fileName'+ is "|" then the remaining
3327 characters of +'fileName'+ are treated as a list of arguments that
3328 describe a command pipeline to invoke, in the same style as the
3329 arguments for exec. In this case, the channel identifier returned
3330 by open may be used to write to the command's input pipe or read
3331 from its output pipe, depending on the value of +'access'+. If write-only
3332 access is used (e.g. +'access'+ is 'w'), then standard output for the
3333 pipeline is directed to the current standard output unless overridden
3334 by the command. If read-only access is used (e.g. +'access'+ is r),
3335 standard input for the pipeline is taken from the current standard
3336 input unless overridden by the command.
3338 The `pid` command may be used to return the process ids of the commands
3339 forming the command pipeline.
3341 See also `socket`, `pid`, `exec`
3343 package
3344 ~~~~~~~
3345 +*package provide* 'name ?version?'+
3347 Indicates that the current script provides the package named +'name'+.
3348 If no version is specified, '1.0' is used.
3350 Any script which provides a package may include this statement
3351 as the first statement, although it is not required.
3353 +*package require* 'name ?version?'*+
3355 Searches for the package with the given +'name'+ by examining each path
3356 in '$::auto_path' and trying to load '$path/$name.so' as a dynamic extension,
3357 or '$path/$name.tcl' as a script package.
3359 The first such file which is found is considered to provide the package.
3360 (The version number is ignored).
3362 If '$name.so' exists, it is loaded with the `load` command,
3363 otherwise if '$name.tcl' exists it is loaded with the `source` command.
3365 If `load` or `source` fails, `package require` will fail immediately.
3366 No further attempt will be made to locate the file.
3370 +*pid*+
3372 +*pid* 'fileId'+
3374 The first form returns the process identifier of the current process.
3376 The second form accepts a handle returned by `open` and returns a list
3377 of the process ids forming the pipeline in the same form as `exec ... &`.
3378 If 'fileId' represents a regular file handle rather than a command pipeline,
3379 the empty string is returned instead.
3381 See also `open`, `exec`
3383 proc
3384 ~~~~
3385 +*proc* 'name args ?statics? body'+
3387 The `proc` command creates a new Tcl command procedure, +'name'+.
3388 When the new command is invoked, the contents of +'body'+ will be executed.
3389 Tcl interpreter. +'args'+ specifies the formal arguments to the procedure.
3390 If specified, +'statics'+, declares static variables which are bound to the
3391 procedure.
3393 See PROCEDURES for detailed information about Tcl procedures.
3395 The `proc` command returns +'name'+ (which is useful with `local`).
3397 When a procedure is invoked, the procedure's return value is the
3398 value specified in a `return` command.  If the procedure doesn't
3399 execute an explicit `return`, then its return value is the value
3400 of the last command executed in the procedure's body.
3402 If an error occurs while executing the procedure body, then the
3403 procedure-as-a-whole will return that same error.
3405 puts
3406 ~~~~
3407 +*puts* ?*-nonewline*? '?fileId? string'+
3409 +'fileId' *puts* ?*-nonewline*? 'string'+
3411 Writes the characters given by +'string'+ to the file given
3412 by +'fileId'+. +'fileId'+ must have been the return
3413 value from a previous call to `open`, or it may be
3414 +stdout+ or +stderr+ to refer to one of the standard I/O
3415 channels; it must refer to a file that was opened for
3416 writing.
3418 In the first form, if no +'fileId'+ is specified then it defaults to +stdout+.
3419 `puts` normally outputs a newline character after +'string'+,
3420 but this feature may be suppressed by specifying the +-nonewline+
3421 switch.
3423 Output to files is buffered internally by Tcl; the `flush`
3424 command may be used to force buffered characters to be output.
3426 pipe
3427 ~~~~
3428 Creates a pair of `aio` channels and returns the handles as a list: +{read write}+
3430     lassign [pipe] r w
3432     # Must close $w after exec
3433     exec ps >@$w &
3434     $w close
3436     $r readable ...
3440 +*pwd*+
3442 Returns the path name of the current working directory.
3444 rand
3445 ~~~~
3446 +*rand* '?min? ?max?'+
3448 Returns a random integer between +'min'+ (defaults to 0) and +'max'+
3449 (defaults to the maximum integer).
3451 If only one argument is given, it is interpreted as +'max'+.
3453 range
3454 ~~~~
3455 +*range* '?start? end ?step?'+
3457 Returns a list of integers starting at +'start'+ (defaults to 0)
3458 and ranging up to but not including +'end'+ in steps of +'step'+ defaults to 1).
3460     jim> range 5
3461     0 1 2 3 4
3462     jim> range 2 5
3463     2 3 4
3464     jim> range 2 10 4
3465     2 6
3466     jim> range 7 4 -2
3467     7 5
3469 read
3470 ~~~~
3471 +*read* ?*-nonewline*? 'fileId'+
3473 +'fileId' *read* ?*-nonewline*?+
3475 +*read* 'fileId numBytes'+
3477 +'fileId' *read* 'numBytes'+
3480 In the first form, all of the remaining bytes are read from the file
3481 given by +'fileId'+; they are returned as the result of the command.
3482 If the +-nonewline+ switch is specified then the last
3483 character of the file is discarded if it is a newline.
3485 In the second form, the extra argument specifies how many bytes to read;
3486 exactly this many bytes will be read and returned, unless there are fewer than
3487 +'numBytes'+ bytes left in the file; in this case, all the remaining
3488 bytes are returned.
3490 +'fileId'+ must be +stdin+ or the return value from a previous call
3491 to `open`; it must refer to a file that was opened for reading.
3493 regexp
3494 ~~~~~~
3495 +*regexp ?-nocase? ?-line? ?-indices? ?-start* 'offset'? *?-all? ?-inline? ?--?* 'exp string ?matchVar? ?subMatchVar subMatchVar \...?'+
3497 Determines whether the regular expression +'exp'+ matches part or
3498 all of +'string'+ and returns 1 if it does, 0 if it doesn't.
3500 See REGULAR EXPRESSIONS above for complete information on the
3501 syntax of +'exp'+ and how it is matched against +'string'+.
3503 If additional arguments are specified after +'string'+ then they
3504 are treated as the names of variables to use to return
3505 information about which part(s) of +'string'+ matched +'exp'+.
3506 +'matchVar'+ will be set to the range of +'string'+ that
3507 matched all of +'exp'+. The first +'subMatchVar'+ will contain
3508 the characters in +'string'+ that matched the leftmost parenthesized
3509 subexpression within +'exp'+, the next +'subMatchVar'+ will
3510 contain the characters that matched the next parenthesized
3511 subexpression to the right in +'exp'+, and so on.
3513 Normally, +'matchVar'+ and the each +'subMatchVar'+ are set to hold the
3514 matching characters from `string`, however see +-indices+ and
3515 +-inline+ below.
3517 If there are more values for +'subMatchVar'+ than parenthesized subexpressions
3518 within +'exp'+, or if a particular subexpression in +'exp'+ doesn't
3519 match the string (e.g. because it was in a portion of the expression
3520 that wasn't matched), then the corresponding +'subMatchVar'+ will be
3521 set to +"-1 -1"+ if +-indices+ has been specified or to an empty
3522 string otherwise.
3524 The following switches modify the behaviour of +'regexp'+
3526 +*-nocase*+::
3527     Causes upper-case and lower-case characters to be treated as
3528     identical during the matching process.
3530 +*-line*+::
3531     Use newline-sensitive matching. By default, newline
3532     is a completely ordinary character with no special meaning in
3533     either REs or strings. With this flag, +[^+ bracket expressions
3534     and +.+ never match newline, an +^+ anchor matches the null
3535     string after any newline in the string in addition to its normal
3536     function, and the +$+ anchor matches the null string before any
3537     newline in the string in addition to its normal function.
3539 +*-indices*+::
3540     Changes what is stored in the subMatchVars. Instead of
3541     storing the matching characters from string, each variable
3542     will contain a list of two decimal strings giving the indices
3543     in string of the first and last characters in the matching
3544     range of characters.
3546 +*-start* 'offset'+::
3547     Specifies a character index offset into the string at which to start
3548     matching the regular expression. If +-indices+ is
3549     specified, the indices will be indexed starting from the
3550     absolute beginning of the input string. +'offset'+ will be
3551     constrained to the bounds of the input string.
3553 +*-all*+::
3554     Causes the regular expression to be matched as many times as possible
3555     in the string, returning the total number of matches found. If this
3556     is specified with match variables, they will contain information
3557     for the last match only.
3559 +*-inline*+::
3560     Causes the command to return, as a list, the data that would otherwise
3561     be placed in match variables. When using +-inline+, match variables
3562     may not be specified. If used with +-all+, the list will be concatenated
3563     at each iteration, such that a flat list is always returned. For
3564     each match iteration, the command will append the overall match
3565     data, plus one element for each subexpression in the regular
3566     expression.
3568 +*--*+::
3569     Marks the end of switches. The argument following this one will be
3570     treated as +'exp'+ even if it starts with a +-+.
3572 regsub
3573 ~~~~~~
3574 +*regsub ?-nocase? ?-all? ?-line? ?-start* 'offset'? ?*--*? 'exp string subSpec ?varName?'+
3576 This command matches the regular expression +'exp'+ against
3577 +'string'+ using the rules described in REGULAR EXPRESSIONS
3578 above.
3580 If +'varName'+ is specified, the commands stores +'string'+ to +'varName'+
3581 with the substitutions detailed below, and returns the number of
3582 substitutions made (normally 1 unless +-all+ is specified).
3583 This is 0 if there were no matches.
3585 If +'varName'+ is not specified, the substituted string will be returned
3586 instead.
3588 When copying +'string'+, the portion of +'string'+ that
3589 matched +'exp'+ is replaced with +'subSpec'+.
3590 If +'subSpec'+ contains a +&+ or +{backslash}0+, then it is replaced
3591 in the substitution with the portion of +'string'+ that
3592 matched +'exp'+.
3594 If +'subSpec'+ contains a +{backslash}n+, where +'n'+ is a digit
3595 between 1 and 9, then it is replaced in the substitution with
3596 the portion of +'string'+ that matched the +'n'+\'-th
3597 parenthesized subexpression of +'exp'+.
3598 Additional backslashes may be used in +'subSpec'+ to prevent special
3599 interpretation of +&+ or +{backslash}0+ or +{backslash}n+ or
3600 backslash.
3602 The use of backslashes in +'subSpec'+ tends to interact badly
3603 with the Tcl parser's use of backslashes, so it's generally
3604 safest to enclose +'subSpec'+ in braces if it includes
3605 backslashes.
3607 The following switches modify the behaviour of +'regsub'+
3609 +*-nocase*+::
3610     Upper-case characters in +'string'+ are converted to lower-case
3611     before matching against +'exp'+;  however, substitutions
3612     specified by +'subSpec'+ use the original unconverted form
3613     of +'string'+.
3615 +*-all*+::
3616     All ranges in +'string'+ that match +'exp'+ are found and substitution
3617     is performed for each of these ranges, rather than only the
3618     first. The +&+ and +{backslash}n+ sequences are handled for
3619     each substitution using the information from the corresponding
3620     match.
3622 +*-line*+::
3623     Use newline-sensitive matching. By default, newline
3624     is a completely ordinary character with no special meaning in
3625     either REs or strings.  With this flag, +[^+ bracket expressions
3626     and +.+ never match newline, an +^+ anchor matches the null
3627     string after any newline in the string in addition to its normal
3628     function, and the +$+ anchor matches the null string before any
3629     newline in the string in addition to its normal function.
3631 +*-start* 'offset'+::
3632     Specifies a character index offset into the string at which to
3633     start matching the regular expression. +'offset'+ will be
3634     constrained to the bounds of the input string.
3636 +*--*+::
3637     Marks the end of switches. The argument following this one will be
3638     treated as +'exp'+ even if it starts with a +-+.
3642 +*ref* 'string tag ?finalizer?'+
3644 Create a new reference containing +'string'+ of type +'tag'+.
3645 If +'finalizer'+ is specified, it is a command which will be invoked
3646 when the a garbage collection cycle runs and this reference is
3647 no longer accessible.
3649 The finalizer is invoked as:
3651   finalizer reference string
3653 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
3655 rename
3656 ~~~~~~
3657 +*rename* 'oldName newName'+
3659 Rename the command that used to be called +'oldName'+ so that it
3660 is now called +'newName'+.  If +'newName'+ is an empty string
3661 (e.g. {}) then +'oldName'+ is deleted.  The `rename` command
3662 returns an empty string as result.
3664 return
3665 ~~~~~~
3666 +*return* ?*-code* 'code'? ?*-errorinfo* 'stacktrace'? ?*-errorcode* 'errorcode'? ?*-level* 'n'? ?'value'?+
3668 Return immediately from the current procedure (or top-level command
3669 or `source` command), with +'value'+ as the return value.  If +'value'+
3670 is not specified, an empty string will be returned as result.
3672 If +-code+ is specified (as either a number or ok, error, break,
3673 continue, signal, return or exit), this code will be used instead
3674 of +JIM_OK+. This is generally useful when implementing flow of control
3675 commands.
3677 If +-level+ is specified and greater than 1, it has the effect of delaying
3678 the new return code from +-code+. This is useful when rethrowing an error
3679 from `catch`. See the implementation of try/catch in tclcompat.tcl for
3680 an example of how this is done.
3682 Note: The following options are only used when +-code+ is JIM_ERR.
3684 If +-errorinfo+ is specified (as returned from `info stacktrace`)
3685 it is used to initialize the stacktrace.
3687 If +-errorcode+ is specified, it is used to set the global variable $::errorCode.
3689 scan
3690 ~~~~
3691 +*scan* 'string format varName1 ?varName2 \...?'+
3693 This command parses fields from an input string in the same fashion
3694 as the C 'sscanf' procedure.  +'string'+ gives the input to be parsed
3695 and +'format'+ indicates how to parse it, using '%' fields as in
3696 'sscanf'.  All of the 'sscanf' options are valid; see the 'sscanf'
3697 man page for details.  Each +'varName'+ gives the name of a variable;
3698 when a field is scanned from +'string'+, the result is converted back
3699 into a string and assigned to the corresponding +'varName'+.  The
3700 only unusual conversion is for '%c'.  For '%c' conversions a single
3701 character value is converted to a decimal string, which is then
3702 assigned to the corresponding +'varName'+; no field width may be
3703 specified for this conversion.
3705 seek
3706 ~~~~
3707 +*seek* 'fileId offset ?origin?'+
3709 +'fileId' *seek* 'offset ?origin?'+
3711 Change the current access position for +'fileId'+.
3712 The +'offset'+ and +'origin'+ arguments specify the position at
3713 which the next read or write will occur for +'fileId'+.
3714 +'offset'+ must be a number (which may be negative) and +'origin'+
3715 must be one of the following:
3717 +*start*+::
3718     The new access position will be +'offset'+ bytes from the start
3719     of the file.
3721 +*current*+::
3722     The new access position will be +'offset'+ bytes from the current
3723     access position; a negative +'offset'+ moves the access position
3724     backwards in the file.
3726 +*end*+::
3727     The new access position will be +'offset'+ bytes from the end of
3728     the file.  A negative +'offset'+ places the access position before
3729     the end-of-file, and a positive +'offset'+ places the access position
3730     after the end-of-file.
3732 The +'origin'+ argument defaults to +start+.
3734 +'fileId'+ must have been the return value from a previous call to
3735 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
3736 of the standard I/O channels.
3738 This command returns an empty string.
3742 +*set* 'varName ?value?'+
3744 Returns the value of variable +'varName'+.
3746 If +'value'+ is specified, then set the value of +'varName'+ to +'value'+,
3747 creating a new variable if one doesn't already exist, and return
3748 its value.
3750 If +'varName'+ contains an open parenthesis and ends with a
3751 close parenthesis, then it refers to an array element:  the characters
3752 before the open parenthesis are the name of the array, and the characters
3753 between the parentheses are the index within the array.
3754 Otherwise +'varName'+ refers to a scalar variable.
3756 If no procedure is active, then +'varName'+ refers to a global
3757 variable.
3759 If a procedure is active, then +'varName'+ refers to a parameter
3760 or local variable of the procedure, unless the +'global'+ command
3761 has been invoked to declare +'varName'+ to be global.
3763 The +::+ prefix may also be used to explicitly reference a variable
3764 in the global scope.
3766 setref
3767 ~~~~~~
3768 +*setref* 'reference string'+
3770 Store a new string in +'reference'+, replacing the existing string.
3771 The reference must be a valid reference create with the `ref`
3772 command.
3774 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
3776 signal
3777 ~~~~~~
3778 Command for signal handling.
3780 See `kill` for the different forms which may be used to specify signals.
3782 Commands which return a list of signal names do so using the canonical form:
3783 "+SIGINT SIGTERM+".
3785 +*signal handle* ?'signals \...'?+::
3786     If no signals are given, returns a list of all signals which are currently
3787     being handled.
3788     If signals are specified, these are added to the list of signals currently
3789     being handled.
3791 +*signal ignore* ?'signals \...'?+::
3792     If no signals are given, returns a lists all signals which are currently
3793     being ignored.
3794     If signals are specified, these are added to the list of signals
3795     currently being ignored. These signals are still delivered, but
3796     are not considered by `catch -signal` or `try -signal`. Use
3797     `signal check` to determine which signals have occurred but
3798     been ignored.
3800 +*signal default* ?'signals \...'?+::
3801     If no signals are given, returns a lists all signals which are currently have
3802     the default behaviour.
3803     If signals are specified, these are added to the list of signals which have
3804     the default behaviour.
3806 +*signal check ?-clear?* ?'signals \...'?+::
3807     Returns a list of signals which have been delivered to the process
3808     but are 'ignored'. If signals are specified, only that set of signals will
3809     be checked, otherwise all signals will be checked.
3810     If +-clear+ is specified, any signals returned are removed and will not be
3811     returned by subsequent calls to `signal check` unless delivered again.
3813 +*signal throw* ?'signal'?+::
3814     Raises the given signal, which defaults to +SIGINT+ if not specified.
3815     The behaviour is identical to:
3817         kill signal [pid]
3819 Note that `signal handle` and `signal ignore` represent two forms of signal
3820 handling. `signal handle` is used in conjunction with `catch -signal` or `try -signal`
3821 to immediately abort execution when the signal is delivered. Alternatively, `signal ignore`
3822 is used in conjunction with `signal check` to handle signal synchronously. Consider the
3823 two examples below.
3825 Prevent a processing from taking too long
3827     signal handle SIGALRM
3828     alarm 20
3829     try -signal {
3830         .. possibly long running process ..
3831         alarm 0
3832     } on signal {sig} {
3833         puts stderr "Process took too long"
3834     }
3836 Handle SIGHUP to reconfigure:
3838     signal ignore SIGHUP
3839     while {1} {
3840         ... handle configuration/reconfiguration ...
3841         while {[signal check -clear SIGHUP] eq ""} {
3842             ... do processing ..
3843         }
3844         # Received SIGHUP, so reconfigure
3845     }
3847 Note: signal handling is currently not supported in child interpreters.
3848 In these interpreters, the signal command does not exist.
3850 sleep
3851 ~~~~~
3852 +*sleep* 'seconds'+
3854 Pauses for the given number of seconds, which may be a floating
3855 point value less than one to sleep for less than a second, or an
3856 integer to sleep for one or more seconds.
3858 source
3859 ~~~~~~
3860 +*source* 'fileName'+
3862 Read file +'fileName'+ and pass the contents to the Tcl interpreter
3863 as a sequence of commands to execute in the normal fashion.  The return
3864 value of `source` is the return value of the last command executed
3865 from the file.  If an error occurs in executing the contents of the
3866 file, then the `source` command will return that error.
3868 If a `return` command is invoked from within the file, the remainder of
3869 the file will be skipped and the `source` command will return
3870 normally with the result from the `return` command.
3872 split
3873 ~~~~~
3874 +*split* 'string ?splitChars?'+
3876 Returns a list created by splitting +'string'+ at each character
3877 that is in the +'splitChars'+ argument.
3879 Each element of the result list will consist of the
3880 characters from +'string'+ between instances of the
3881 characters in +'splitChars'+.
3883 Empty list elements will be generated if +'string'+ contains
3884 adjacent characters in +'splitChars'+, or if the first or last
3885 character of +'string'+ is in +'splitChars'+.
3887 If +'splitChars'+ is an empty string then each character of
3888 +'string'+ becomes a separate element of the result list.
3890 +'splitChars'+ defaults to the standard white-space characters.
3891 For example,
3893     split "comp.unix.misc" .
3895 returns +'"comp unix misc"'+ and
3897     split "Hello world" {}
3899 returns +'"H e l l o { } w o r l d"'+.
3901 stackdump
3902 ~~~~~~~~~
3904 +*stackdump* 'stacktrace'+
3906 Creates a human readable representation of a stack trace.
3908 stacktrace
3909 ~~~~~~~~~~
3911 +*stacktrace*+
3913 Returns a live stack trace as a list of +proc file line proc file line \...+.
3914 Iteratively uses `info frame` to create the stack trace. This stack trace is in the
3915 same form as produced by `catch` and `info stacktrace`
3917 See also `stackdump`.
3919 string
3920 ~~~~~~
3922 +*string* 'option arg ?arg \...?'+
3924 Perform one of several string operations, depending on +'option'+.
3925 The legal options (which may be abbreviated) are:
3927 +*string bytelength* 'string'+::
3928     Returns the length of the string in bytes. This will return
3929     the same value as `string length` if UTF-8 support is not enabled,
3930     or if the string is composed entirely of ASCII characters.
3931     See UTF-8 AND UNICODE.
3933 +*string byterange* 'string first last'+::
3934     Like `string range` except works on bytes rather than characters.
3935     These commands are identical if UTF-8 support is not enabled.
3937 +*string cat* '?string1 string2 \...?'+::
3938     Concatenates the given strings into a single string.
3940 +*string compare ?-nocase?* ?*-length* 'len? string1 string2'+::
3941     Perform a character-by-character comparison of strings +'string1'+ and
3942     +'string2'+ in the same way as the C 'strcmp' procedure.  Return
3943     -1, 0, or 1, depending on whether +'string1'+ is lexicographically
3944     less than, equal to, or greater than +'string2'+. If +-length+
3945     is specified, then only the first +'len'+ characters are used
3946     in the comparison.  If +'len'+ is negative, it is ignored.
3947     Performs a case-insensitive comparison if +-nocase+ is specified.
3949 +*string equal ?-nocase?* '?*-length* len?' 'string1 string2'+::
3950     Returns 1 if the strings are equal, or 0 otherwise. If +-length+
3951     is specified, then only the first +'len'+ characters are used
3952     in the comparison.  If +'len'+ is negative, it is ignored.
3953     Performs a case-insensitive comparison if +-nocase+ is specified.
3955 +*string first* 'string1 string2 ?firstIndex?'+::
3956     Search +'string2'+ for a sequence of characters that exactly match
3957     the characters in +'string1'+.  If found, return the index of the
3958     first character in the first such match within +'string2'+.  If not
3959     found, return -1. If +'firstIndex'+ is specified, matching will start
3960     from +'firstIndex'+ of +'string1'+.
3961  ::
3962     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'firstIndex'+.
3964 +*string index* 'string charIndex'+::
3965     Returns the +'charIndex'+'th character of the +'string'+
3966     argument.  A +'charIndex'+ of 0 corresponds to the first
3967     character of the string.
3968     If +'charIndex'+ is less than 0 or greater than
3969     or equal to the length of the string then an empty string is
3970     returned.
3971  ::
3972     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'charIndex'+.
3974 +*string is* 'class' ?*-strict*? 'string'+::
3975     Returns 1 if +'string'+ is a valid member of the specified character
3976     class, otherwise returns 0. If +-strict+ is specified, then an
3977     empty string returns 0, otherwise an empty string will return 1
3978     on any class. The following character classes are recognized
3979     (the class name can be abbreviated):
3980   ::
3981   +alnum+;;  Any alphabet or digit character.
3982   +alpha+;;  Any alphabet character.
3983   +ascii+;;  Any character with a value less than 128 (those that are in the 7-bit ascii range).
3984   +boolean+;;  Any of the valid string formats for a boolean value in Tcl (0, false, no, off, 1, true, yes, on)
3985   +control+;; Any control character.
3986   +digit+;;  Any digit character.
3987   +double+;; Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
3988              In case of under/overflow in the value, 0 is returned.
3989   +graph+;;  Any printing character, except space.
3990   +integer+;; Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
3991   +lower+;;  Any lower case alphabet character.
3992   +print+;;  Any printing character, including space.
3993   +punct+;;  Any punctuation character.
3994   +space+;;  Any space character.
3995   +upper+;;  Any upper case alphabet character.
3996   +xdigit+;; Any hexadecimal digit character ([0-9A-Fa-f]).
3997  ::
3998     Note that string classification does +'not'+ respect UTF-8. See UTF-8 AND UNICODE
3999  ::
4000     Note that only +'lowercase'+ boolean values are recognized (Tcl accepts any case).
4002 +*string last* 'string1 string2 ?lastIndex?'+::
4003     Search +'string2'+ for a sequence of characters that exactly match
4004     the characters in +'string1'+.  If found, return the index of the
4005     first character in the last such match within +'string2'+.  If there
4006     is no match, then return -1. If +'lastIndex'+ is specified, only characters
4007     up to +'lastIndex'+ of +'string2'+ will be considered in the match.
4008  ::
4009     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'lastIndex'+.
4011 +*string length* 'string'+::
4012     Returns a decimal string giving the number of characters in +'string'+.
4013     If UTF-8 support is enabled, this may be different than the number of bytes.
4014     See UTF-8 AND UNICODE
4016 +*string map ?-nocase?* 'mapping string'+::
4017     Replaces substrings in +'string'+ based on the key-value pairs in
4018     +'mapping'+, which is a list of +key value key value \...+ as in the form
4019     returned by `array get`. Each instance of a key in the string will be
4020     replaced with its corresponding value.  If +-nocase+ is specified, then
4021     matching is done without regard to case differences. Both key and value may
4022     be multiple characters.  Replacement is done in an ordered manner, so the
4023     key appearing first in the list will be checked first, and so on. +'string'+ is
4024     only iterated over once, so earlier key replacements will have no affect for
4025     later key matches. For example,
4027       string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc
4029  ::
4030     will return the string +01321221+.
4031  ::
4032     Note that if an earlier key is a prefix of a later one, it will completely mask the later
4033     one.  So if the previous example is reordered like this,
4035       string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc
4037  ::
4038     it will return the string +02c322c222c+.
4040 +*string match ?-nocase?* 'pattern string'+::
4041     See if +'pattern'+ matches +'string'+; return 1 if it does, 0
4042     if it doesn't.  Matching is done in a fashion similar to that
4043     used by the C-shell.  For the two strings to match, their contents
4044     must be identical except that the following special sequences
4045     may appear in +'pattern'+:
4047     +*+;;
4048         Matches any sequence of characters in +'string'+,
4049         including a null string.
4051     +?+;;
4052         Matches any single character in +'string'+.
4054     +['chars']+;;
4055         Matches any character in the set given by +'chars'+.
4056         If a sequence of the form +'x-y'+ appears in +'chars'+,
4057         then any character between +'x'+ and +'y'+, inclusive,
4058         will match.
4060     +{backslash}x+;;
4061         Matches the single character +'x'+.  This provides a way of
4062         avoiding the special interpretation of the characters +{backslash}*?[]+
4063         in +'pattern'+.
4064  ::
4065     Performs a case-insensitive comparison if +-nocase+ is specified.
4067 +*string range* 'string first last'+::
4068     Returns a range of consecutive characters from +'string'+, starting
4069     with the character whose index is +'first'+ and ending with the
4070     character whose index is +'last'+.  An index of 0 refers to the
4071     first character of the string.
4072  ::
4073     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
4074  ::
4075     If +'first'+ is less than zero then it is treated as if it were zero, and
4076     if +'last'+ is greater than or equal to the length of the string then
4077     it is treated as if it were +end+.  If +'first'+ is greater than
4078     +'last'+ then an empty string is returned.
4080 +*string repeat* 'string count'+::
4081     Returns a new string consisting of +'string'+ repeated +'count'+ times.
4083 +*string replace* 'string first last ?newstring?'+::
4084     Removes a range of consecutive characters from +'string'+, starting
4085     with the character whose index is +'first'+ and ending with the
4086     character whose index is +'last'+.  If +'newstring'+ is specified,
4087     then it is placed in the removed character range. If +'first'+ is
4088     less than zero then it is treated as if it were zero, and if +'last'+
4089     is greater than or equal to the length of the string then it is
4090     treated as if it were +end+. If +'first'+ is greater than +'last'+
4091     or the length of the initial string, or +'last'+ is less than 0,
4092     then the initial string is returned untouched.
4094 +*string reverse* 'string'+::
4095     Returns a string that is the same length as +'string'+ but
4096     with its characters in the reverse order.
4098 +*string tolower* 'string'+::
4099     Returns a value equal to +'string'+ except that all upper case
4100     letters have been converted to lower case.
4102 +*string totitle* 'string'+::
4103     Returns a value equal to +'string'+ except that the first character
4104     is converted to title case (or upper case if there is no UTF-8 titlecase variant)
4105     and all remaining characters have been converted to lower case.
4107 +*string toupper* 'string'+::
4108     Returns a value equal to +'string'+ except that all lower case
4109     letters have been converted to upper case.
4111 +*string trim* 'string ?chars?'+::
4112     Returns a value equal to +'string'+ except that any leading
4113     or trailing characters from the set given by +'chars'+ are
4114     removed.
4115     If +'chars'+ is not specified then white space is removed
4116     (spaces, tabs, newlines, and carriage returns).
4118 +*string trimleft* 'string ?chars?'+::
4119     Returns a value equal to +'string'+ except that any
4120     leading characters from the set given by +'chars'+ are
4121     removed.
4122     If +'chars'+ is not specified then white space is removed
4123     (spaces, tabs, newlines, and carriage returns).
4125 +*string trimright* 'string ?chars?'+::
4126     Returns a value equal to +'string'+ except that any
4127     trailing characters from the set given by +'chars'+ are
4128     removed.
4129     If +'chars'+ is not specified then white space is removed
4130     (spaces, tabs, newlines, and carriage returns).
4131     Null characters are always removed.
4133 subst
4134 ~~~~~
4135 +*subst ?-nobackslashes? ?-nocommands? ?-novariables?* 'string'+
4137 This command performs variable substitutions, command substitutions,
4138 and backslash substitutions on its string argument and returns the
4139 fully-substituted result. The substitutions are performed in exactly
4140 the same way as for Tcl commands. As a result, the string argument
4141 is actually substituted twice, once by the Tcl parser in the usual
4142 fashion for Tcl commands, and again by the subst command.
4144 If any of the +-nobackslashes+, +-nocommands+, or +-novariables+ are
4145 specified, then the corresponding substitutions are not performed.
4146 For example, if +-nocommands+ is specified, no command substitution
4147 is performed: open and close brackets are treated as ordinary
4148 characters with no special interpretation.
4150 *Note*: when it performs its substitutions, subst does not give any
4151 special treatment to double quotes or curly braces. For example,
4152 the following script returns +xyz \{44\}+, not +xyz \{$a\}+.
4154     set a 44
4155     subst {xyz {$a}}
4158 switch
4159 ~~~~~~
4160 +*switch* '?options? string pattern body ?pattern body \...?'+
4162 +*switch* '?options? string {pattern body ?pattern body \...?}'+
4164 The `switch` command matches its string argument against each of
4165 the pattern arguments in order. As soon as it finds a pattern that
4166 matches string it evaluates the following body and returns the
4167 result of that evaluation. If the last pattern argument is default
4168 then it matches anything. If no pattern argument matches string and
4169 no default is given, then the `switch` command returns an empty string.
4170 If the initial arguments to switch start with - then they are treated
4171 as options. The following options are currently supported:
4173     +-exact+::
4174         Use exact matching when comparing string to a
4175         pattern. This is the default.
4177     +-glob+::
4178         When matching string to the patterns, use glob-style
4179         matching (i.e. the same as implemented by the string
4180         match command).
4182     +-regexp+::
4183         When matching string to the patterns, use regular
4184         expression matching (i.e. the same as implemented
4185         by the regexp command).
4187     +-command 'commandname'+::
4188         When matching string to the patterns, use the given command, which
4189         must be a single word. The command is invoked as
4190         'commandname pattern string', or 'commandname -nocase pattern string'
4191         and must return 1 if matched, or 0 if not.
4193     +--+::
4194         Marks the end of options. The argument following
4195         this one will be treated as string even if it starts
4196         with a +-+.
4198 Two syntaxes are provided for the pattern and body arguments. The
4199 first uses a separate argument for each of the patterns and commands;
4200 this form is convenient if substitutions are desired on some of the
4201 patterns or commands. The second form places all of the patterns
4202 and commands together into a single argument; the argument must
4203 have proper list structure, with the elements of the list being the
4204 patterns and commands. The second form makes it easy to construct
4205 multi-line `switch` commands, since the braces around the whole list
4206 make it unnecessary to include a backslash at the end of each line.
4207 Since the pattern arguments are in braces in the second form, no
4208 command or variable substitutions are performed on them; this makes
4209 the behaviour of the second form different than the first form in
4210 some cases.
4212 If a body is specified as +-+ it means that the body for the next
4213 pattern should also be used as the body for this pattern (if the
4214 next pattern also has a body of +-+ then the body after that is
4215 used, and so on). This feature makes it possible to share a single
4216 body among several patterns.
4218 Below are some examples of `switch` commands:
4220     switch abc a - b {format 1} abc {format 2} default {format 3}
4222 will return 2,
4224     switch -regexp aaab {
4225            ^a.*b$ -
4226            b {format 1}
4227            a* {format 2}
4228            default {format 3}
4229     }
4231 will return 1, and
4233     switch xyz {
4234            a -
4235            b {format 1}
4236            a* {format 2}
4237            default {format 3}
4238     }
4240 will return 3.
4242 tailcall
4243 ~~~~~~~~
4244 +*tailcall* 'cmd ?arg\...?'+
4246 The `tailcall` command provides an optimised way of invoking a command whilst replacing
4247 the current call frame. This is similar to 'exec' in Bourne Shell.
4249 The following are identical except the first immediately replaces the current call frame.
4251   tailcall a b c
4253   return [uplevel 1 [list a b c]]
4255 `tailcall` is useful as a dispatch mechanism:
4257   proc a {cmd args} {
4258     tailcall sub_$cmd {*}$args
4259   }
4260   proc sub_cmd1 ...
4261   proc sub_cmd2 ...
4263 tell
4264 ~~~~
4265 +*tell* 'fileId'+
4267 +'fileId' *tell*+
4269 Returns a decimal string giving the current access position in
4270 +'fileId'+.
4272 +'fileId'+ must have been the return value from a previous call to
4273 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
4274 of the standard I/O channels.
4276 throw
4277 ~~~~~
4278 +*throw* 'code ?msg?'+
4280 This command throws an exception (return) code along with an optional message.
4281 This command is mostly for convenient usage with `try`.
4283 The command +throw break+ is equivalent to +break+.
4284 The command +throw 20 message+ can be caught with an +on 20 \...+ clause to `try`.
4286 time
4287 ~~~~
4288 +*time* 'command ?count?'+
4290 This command will call the Tcl interpreter +'count'+
4291 times to execute +'command'+ (or once if +'count'+ isn't
4292 specified).  It will then return a string of the form
4294     503 microseconds per iteration
4296 which indicates the average amount of time required per iteration,
4297 in microseconds.
4299 Time is measured in elapsed time, not CPU time.
4303 +*try* '?catchopts? tryscript' ?*on* 'returncodes {?resultvar? ?optsvar?} handlerscript \...'? ?*finally* 'finalscript'?+
4305 The `try` command is provided as a convenience for exception handling.
4307 This interpeter first evaluates +'tryscript'+ under the effect of the catch
4308 options +'catchopts'+ (e.g. +-signal -noexit --+, see `catch`).
4310 It then evaluates the script for the first matching 'on' handler
4311 (there many be zero or more) based on the return code from the `try`
4312 section. For example a normal +JIM_ERR+ error will be matched by
4313 an 'on error' handler.
4315 Finally, any +'finalscript'+ is evaluated.
4317 The result of this command is the result of +'tryscript'+, except in the
4318 case where an exception occurs in a matching 'on' handler script or the 'finally' script,
4319 in which case the result is this new exception.
4321 The specified +'returncodes'+ is a list of return codes either as names ('ok', 'error', 'break', etc.)
4322 or as integers.
4324 If +'resultvar'+ and +'optsvar'+ are specified, they are set as for `catch` before evaluating
4325 the matching handler.
4327 For example:
4329     set f [open input]
4330     try -signal {
4331         process $f
4332     } on {continue break} {} {
4333         error "Unexpected break/continue"
4334     } on error {msg opts} {
4335         puts "Dealing with error"
4336         return {*}$opts $msg
4337     } on signal sig {
4338         puts "Got signal: $sig"
4339     } finally {
4340         $f close
4341     }
4343 If break, continue or error are raised, they are dealt with by the matching
4344 handler.
4346 In any case, the file will be closed via the 'finally' clause.
4348 See also `throw`, `catch`, `return`, `error`.
4350 unknown
4351 ~~~~~~~
4352 +*unknown* 'cmdName ?arg arg ...?'+
4354 This command doesn't actually exist as part of Tcl, but Tcl will
4355 invoke it if it does exist.
4357 If the Tcl interpreter encounters a command name for which there
4358 is not a defined command, then Tcl checks for the existence of
4359 a command named `unknown`.
4361 If there is no such command, then the interpreter returns an
4362 error.
4364 If the `unknown` command exists, then it is invoked with
4365 arguments consisting of the fully-substituted name and arguments
4366 for the original non-existent command.
4368 The `unknown` command typically does things like searching
4369 through library directories for a command procedure with the name
4370 +'cmdName'+, or expanding abbreviated command names to full-length,
4371 or automatically executing unknown commands as UNIX sub-processes.
4373 In some cases (such as expanding abbreviations) `unknown` will
4374 change the original command slightly and then (re-)execute it.
4375 The result of the `unknown` command is used as the result for
4376 the original non-existent command.
4378 unset
4379 ~~~~~
4380 +*unset ?-nocomplain? ?--?* '?name name ...?'+
4382 Remove variables.
4383 Each +'name'+ is a variable name, specified in any of the
4384 ways acceptable to the `set` command.
4386 If a +'name'+ refers to an element of an array, then that
4387 element is removed without affecting the rest of the array.
4389 If a +'name'+ consists of an array name with no parenthesized
4390 index, then the entire array is deleted.
4392 The `unset` command returns an empty string as result.
4394 An error occurs if any of the variables doesn't exist, unless '-nocomplain'
4395 is specified. The '--' argument may be specified to stop option processing
4396 in case the variable name may be '-nocomplain'.
4398 upcall
4399 ~~~~~~~
4400 +*upcall* 'command ?args ...?'+
4402 May be used from within a proc defined as `local` `proc` in order to call
4403 the previous, hidden version of the same command.
4405 If there is no previous definition of the command, an error is returned.
4407 uplevel
4408 ~~~~~~~
4409 +*uplevel* '?level? command ?command ...?'+
4411 All of the +'command'+ arguments are concatenated as if they had
4412 been passed to `concat`; the result is then evaluated in the
4413 variable context indicated by +'level'+.  `uplevel` returns
4414 the result of that evaluation.  If +'level'+ is an integer, then
4415 it gives a distance (up the procedure calling stack) to move before
4416 executing the command.  If +'level'+ consists of +\#+ followed by
4417 a number then the number gives an absolute level number.  If +'level'+
4418 is omitted then it defaults to +1+.  +'level'+ cannot be
4419 defaulted if the first +'command'+ argument starts with a digit or +#+.
4421 For example, suppose that procedure 'a' was invoked
4422 from top-level, and that it called 'b', and that 'b' called 'c'.
4423 Suppose that 'c' invokes the `uplevel` command.  If +'level'+
4424 is +1+ or +#2+  or omitted, then the command will be executed
4425 in the variable context of 'b'.  If +'level'+ is +2+ or +#1+
4426 then the command will be executed in the variable context of 'a'.
4428 If +'level'+ is '3' or +#0+ then the command will be executed
4429 at top-level (only global variables will be visible).
4430 The `uplevel` command causes the invoking procedure to disappear
4431 from the procedure calling stack while the command is being executed.
4432 In the above example, suppose 'c' invokes the command
4434     uplevel 1 {set x 43; d}
4436 where 'd' is another Tcl procedure.  The `set` command will
4437 modify the variable 'x' in 'b's context, and 'd' will execute
4438 at level 3, as if called from 'b'.  If it in turn executes
4439 the command
4441     uplevel {set x 42}
4443 then the `set` command will modify the same variable 'x' in 'b's
4444 context:  the procedure 'c' does not appear to be on the call stack
4445 when 'd' is executing.  The command `info level` may
4446 be used to obtain the level of the current procedure.
4448 `uplevel` makes it possible to implement new control
4449 constructs as Tcl procedures (for example, `uplevel` could
4450 be used to implement the `while` construct as a Tcl procedure).
4452 upvar
4453 ~~~~~
4454 +*upvar* '?level? otherVar myVar ?otherVar myVar ...?'+
4456 This command arranges for one or more local variables in the current
4457 procedure to refer to variables in an enclosing procedure call or
4458 to global variables.
4460 +'level'+ may have any of the forms permitted for the `uplevel`
4461 command, and may be omitted if the first letter of the first +'otherVar'+
4462 isn't +#+ or a digit (it defaults to '1').
4464 For each +'otherVar'+ argument, `upvar` makes the variable
4465 by that name in the procedure frame given by +'level'+ (or at
4466 global level, if +'level'+ is +#0+) accessible
4467 in the current procedure by the name given in the corresponding
4468 +'myVar'+ argument.
4470 The variable named by +'otherVar'+ need not exist at the time of the
4471 call;  it will be created the first time +'myVar'+ is referenced, just like
4472 an ordinary variable.
4474 `upvar` may only be invoked from within procedures.
4476 `upvar` returns an empty string.
4478 The `upvar` command simplifies the implementation of call-by-name
4479 procedure calling and also makes it easier to build new control constructs
4480 as Tcl procedures.
4481 For example, consider the following procedure:
4483     proc add2 name {
4484         upvar $name x
4485         set x [expr $x+2]
4486     }
4488 'add2' is invoked with an argument giving the name of a variable,
4489 and it adds two to the value of that variable.
4490 Although 'add2' could have been implemented using `uplevel`
4491 instead of `upvar`, `upvar` makes it simpler for 'add2'
4492 to access the variable in the caller's procedure frame.
4494 wait
4495 ~~~~
4496 +*wait*+
4498 +*wait -nohang* 'pid'+
4500 With no arguments, cleans up any processes started by `exec ... &` that have completed
4501 (reaps zombie processes).
4503 With one or two arguments, waits for a process by id, either returned by `exec ... &`
4504 or by `os.fork` (if supported).
4506 Waits for the process to complete, unless +-nohang+ is specified, in which case returns
4507 immediately if the process is still running.
4509 Returns a list of 3 elements.
4511 +{NONE x x}+ if the process does not exist or has already been waited for, or
4512 if -nohang is specified, and the process is still alive.
4514 +{CHILDSTATUS <pid> <exit-status>}+ if the process exited normally.
4516 +{CHILDKILLED <pid> <signal>}+ if the process terminated on a signal.
4518 +{CHILDSUSP <pid> none}+ if the process terminated for some other reason.
4520 Note that on platforms supporting waitpid(2), +pid+ can also be given special values such
4521 as 0 or -1. See waitpid(2) for more detail.
4523 while
4524 ~~~~~
4525 +*while* 'test body'+
4527 The +'while'+ command evaluates +'test'+ as an expression
4528 (in the same way that `expr` evaluates its argument).
4529 The value of the expression must be numeric; if it is non-zero
4530 then +'body'+ is executed by passing it to the Tcl interpreter.
4532 Once +'body'+ has been executed then +'test'+ is evaluated
4533 again, and the process repeats until eventually +'test'+
4534 evaluates to a zero numeric value.  `continue`
4535 commands may be executed inside +'body'+ to terminate the current
4536 iteration of the loop, and `break`
4537 commands may be executed inside +'body'+ to cause immediate
4538 termination of the `while` command.
4540 The `while` command always returns an empty string.
4542 OPTIONAL-EXTENSIONS
4543 -------------------
4545 The following extensions may or may not be available depending upon
4546 what options were selected when Jim Tcl was built.
4549 [[cmd_1]]
4550 posix: os.fork, os.gethostname, os.getids, os.uptime
4551 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4552 +*os.fork*+::
4553     Invokes 'fork(2)' and returns the result.
4555 +*os.gethostname*+::
4556     Invokes 'gethostname(3)' and returns the result.
4558 +*os.getids*+::
4559     Returns the various user/group ids for the current process.
4561     jim> os.getids
4562     uid 1000 euid 1000 gid 100 egid 100
4564 +*os.uptime*+::
4565     Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.
4567 ANSI I/O (aio) and EVENTLOOP API
4568 --------------------------------
4569 Jim provides an alternative object-based API for I/O.
4571 See `open` and `socket` for commands which return an I/O handle.
4575 +$handle *accept* ?addrvar?+::
4576     Server socket only: Accept a connection and return stream.
4577     If +'addrvar'+ is specified, the address of the connected client is stored
4578     in the named variable in the form 'addr:port' for IP sockets or 'path' for Unix domain sockets.
4579     See `socket` for details.
4581 +$handle *buffering none|line|full*+::
4582     Sets the buffering mode of the stream.
4584 +$handle *close* ?r(ead)|w(rite)|-nodelete?+::
4585     Closes the stream.
4586     The +'read'+ and +'write'+ arguments perform a "half-close" on a socket. See the +shutdown(2)+ man page.
4587     The +'-nodelete'+ option is applicable only for Unix domain sockets. It closes the socket
4588     but does not delete the bound path (e.g. after `os.fork`).
4591 +$handle *copyto* 'tofd ?size?'+::
4592     Copy bytes to the file descriptor +'tofd'+. If +'size'+ is specified, at most
4593     that many bytes will be copied. Otherwise copying continues until the end
4594     of the input file. Returns the number of bytes actually copied.
4596 +$handle *eof*+::
4597     Returns 1 if stream is at eof
4599 +$handle *filename*+::
4600     Returns the original filename associated with the handle.
4601     Handles returned by `socket` give the socket type instead of a filename.
4603 +$handle *flush*+::
4604     Flush the stream
4606 +$handle *gets* '?var?'+::
4607     Read one line and return it or store it in the var
4609 +$handle *isatty*+::
4610     Returns 1 if the stream is a tty device.
4612 +$handle *lock*+::
4613     Apply a POSIX lock to the open file associated with the handle using
4614     fcntl(2).
4615     The handle must be open for write access.
4616     Returns 1 if the lock was successfully obtained, 0 otherwise.
4617     An error occurs if the handle is not suitable for locking (e.g.
4618     if it is not open for write)
4620 +$handle *ndelay ?0|1?*+::
4621     Set O_NDELAY (if arg). Returns current/new setting.
4622     Note that in general ANSI I/O interacts badly with non-blocking I/O.
4623     Use with care.
4625 +$handle *peername*+::
4626     Returns the remote address or path of the connected socket. See 'getpeername(2)'.
4628 +$handle *puts ?-nonewline?* 'str'+::
4629     Write the string, with newline unless -nonewline
4631 +$handle *read ?-nonewline?* '?len?'+::
4632     Read and return bytes from the stream. To eof if no len.
4634 +$handle *recvfrom* 'maxlen ?addrvar?'+::
4635     Receives a message from the handle via recvfrom(2) and returns it.
4636     At most +'maxlen'+ bytes are read. If +'addrvar'+ is specified, the sending address
4637     of the message is stored in the named variable in the form 'addr:port' for IP sockets
4638     or 'path' for Unix domain sockets. See `socket` for details.
4640 +$handle *seek* 'offset' *?start|current|end?*+::
4641     Seeks in the stream (default 'current')
4643 +$handle *sendto* 'str ?address'+::
4644     Sends the string, +'str'+, to the given address (host:port or path) via the socket using sendto(2).
4645     This is intended for udp/dgram sockets and may give an error or behave in unintended
4646     ways for other handle types.
4647     Returns the number of bytes written.
4649 +$handle *sockname*+::
4650     Returns the bound address or path of the socket. See 'getsockname(2)'.
4652 +$handle *sockopt* '?name value?'+::
4653     With no arguments, returns a dictionary of socket options currently set for the handle
4654     (will be empty for a non-socket). With +'name'+ and +'value'+, sets the socket option
4655     to the given value. Currently supports the following boolean socket options:
4656     +broadcast, debug, keepalive, nosigpipe, oobinline, tcp_nodelay+, and the following
4657     integer socket options: +sndbuf, rcvbuf+
4659 +$handle *sync*+::
4660     Flush the stream, then fsync(2) to commit any changes to storage.
4661     Only available on platforms that support fsync(2).
4663 +$handle *tell*+::
4664     Returns the current seek position
4666 +$handle *tty* ?settings?+::
4667     If no arguments are given, returns a dictionary containing the tty settings for the stream.
4668     If arguments are given, they must either be a dictionary, or +setting value \...+
4669     Abbrevations are supported for both settings and values, so the following is acceptable:
4670     +$f tty parity e input c out raw+.
4671     Only available on platforms that support termios(3). Supported settings are:
4673     +*baud* 'rate'+;;
4674         Baud rate. e.g. 115200
4676     +*data 5|6|7|8*+;;
4677         Number of data bits
4679     +*stop 1|2*+;;
4680         Number of stop bits
4682     +*parity even|odd|none*+;;
4683         Parity setting
4685     +*handshake xonxoff|rtscts|none*+;;
4686         Handshaking type
4688     +*input raw|cooked*+;;
4689         Input character processing. In raw mode, the usual key sequences such as ^C do
4690         not generate signals.
4692     +*output raw|cooked*+;;
4693         Output character processing. Typically CR -> CRNL is disabled in raw mode.
4695     +*vmin* 'numchars'+;;
4696         Minimum number of characters to read.
4698     +*vtime* 'time'+;;
4699         Timeout for noncanonical read (units of 0.1 seconds)
4701 +$handle *ssl* *?-server cert priv?*+::
4702     Upgrades the stream to a SSL/TLS session and returns the handle.
4704 +$handle *unlock*+::
4705     Release a POSIX lock previously acquired by `aio lock`.
4707 +$handle *verify*+::
4708     Verifies the certificate of a SSL/TLS stream peer
4710 +*load_ssl_certs* 'dir'+::
4711     Loads SSL/TLS CA certificates for use during verification
4713 fconfigure
4714 ~~~~~~~~~~
4715 +*fconfigure* 'handle' *?-blocking 0|1? ?-buffering noneline|full? ?-translation* 'mode'?+::
4716     For compatibility with Tcl, a limited form of the `fconfigure`
4717     command is supported.
4718     * `fconfigure ... -blocking` maps to `aio ndelay`
4719     * `fconfigure ... -buffering` maps to `aio buffering`
4720     * `fconfigure ... -translation` is accepted but ignored
4722 [[cmd_2]]
4723 eventloop: after, vwait, update
4724 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4726 The following commands allow a script to be invoked when the given condition occurs.
4727 If no script is given, returns the current script. If the given script is the empty, the
4728 handler is removed.
4730 +$handle *readable* '?readable-script?'+::
4731     Sets or returns the script for when the socket is readable.
4733 +$handle *writable* '?writable-script?'+::
4734     Sets or returns the script for when the socket is writable.
4736 +$handle *onexception* '?exception-script?'+::
4737     Sets or returns the script for when oob data received.
4739 For compatibility with 'Tcl', these may be prefixed with `fileevent`.  e.g.
4741  ::
4742     +fileevent $handle *readable* '\...'+
4744 Time-based execution is also available via the eventloop API.
4746 +*after* 'ms'+::
4747     Sleeps for the given number of milliseconds. No events are
4748     processed during this time.
4750 +*after* 'ms'|*idle* 'script ?script \...?'+::
4751     The scripts are concatenated and executed after the given
4752     number of milliseconds have elapsed.  If 'idle' is specified,
4753     the script will run the next time the event loop is processed
4754     with `vwait` or `update`. The script is only run once and
4755     then removed.  Returns an event id.
4757 +*after cancel* 'id|command'+::
4758     Cancels an `after` event with the given event id or matching
4759     command (script).  Returns the number of milliseconds
4760     remaining until the event would have fired.  Returns the
4761     empty string if no matching event is found.
4763 +*after info* '?id?'+::
4764     If +'id'+ is not given, returns a list of current `after`
4765     events.  If +'id'+ is given, returns a list containing the
4766     associated script and either 'timer' or 'idle' to indicated
4767     the type of the event. An error occurs if +'id'+ does not
4768     match an event.
4770 +*vwait* 'variable'+::
4771     A call to `vwait` enters the eventloop. `vwait` processes
4772     events until the named (global) variable changes or all
4773     event handlers are removed. The variable need not exist
4774     beforehand.  If there are no event handlers defined, `vwait`
4775     returns immediately.
4777 +*update ?idletasks?*+::
4778     A call to `update` enters the eventloop to process expired events, but
4779     no new events. If 'idletasks' is specified, only expired time events are handled,
4780     not file events.
4781     Returns once handlers have been run for all expired events.
4783 Scripts are executed at the global scope. If an error occurs during a handler script,
4784 an attempt is made to call (the user-defined command) `bgerror` with the details of the error.
4785 If the `bgerror` command does not exist, the error message details are printed to stderr instead.
4787 If a file event handler script generates an error, the handler is automatically removed
4788 to prevent infinite errors. (A time event handler is always removed after execution).
4790 +*bgerror* 'msg'+::
4791     Called when an event handler script generates an error. Note that the normal command resolution
4792     rules are used for bgerror. First the name is resolved in the current namespace, then in the
4793     global scope.
4795 socket
4796 ~~~~~~
4797 Various socket types may be created.
4799 +*socket unix* 'path'+::
4800     A unix domain socket client connected to 'path'
4802 +*socket unix.server* 'path'+::
4803     A unix domain socket server listening on 'path'
4805 +*socket unix.dgram* '?path?'+::
4806     A unix domain socket datagram client, optionally connected to 'path'
4808 +*socket unix.dgram.server* 'path'+::
4809     A unix domain socket datagram server server listening on 'path'
4811 +*socket ?-ipv6? stream* 'addr:port'+::
4812     A TCP socket client. (See the forms for +'addr'+ below)
4814 +*socket ?-ipv6? stream.server* '?addr:?port'+::
4815     A TCP socket server (+'addr'+ defaults to +0.0.0.0+ for IPv4 or +[::]+ for IPv6).
4817 +*socket ?-ipv6? dgram* ?'addr:port'?+::
4818     A UDP socket client. If the address is not specified,
4819     the client socket will be unbound and 'sendto' must be used
4820     to indicated the destination.
4822 +*socket ?-ipv6? dgram.server* 'addr:port'+::
4823     A UDP socket server.
4825 +*socket pipe*+::
4826     A synonym for `pipe`
4828 +*socket pair*+::
4829     A socketpair (see socketpair(2)). Like `pipe`, this command returns
4830     a list of two channels: {s1 s2}. These channels are both readable and writable.
4832 This command creates a socket connected (client) or bound (server) to the given
4833 address.
4835 The returned value is channel and may generally be used with the various file I/O
4836 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.
4838     . set f [socket stream www.google.com:80]
4839     aio.sockstream1
4840     . $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
4841     . $f gets
4842     HTTP/1.0 302 Found
4843     . $f close
4845 Server sockets, however support only 'accept', which is most useful in conjunction with
4846 the EVENTLOOP API.
4848     set f [socket stream.server 80]
4849     $f readable {
4850         set client [$f accept]
4851         $client gets $buf
4852         ...
4853         $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
4854         $client close
4855     }
4856     vwait done
4858 The address, +'addr'+, can be given in one of the following forms:
4860 1. For IPv4 socket types, an IPv4 address such as 192.168.1.1
4861 2. For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
4862 3. A hostname
4864 Note that on many systems, listening on an IPv6 address such as [::] will
4865 also accept requests via IPv4.
4867 Where a hostname is specified, the +'first'+ returned address is used
4868 which matches the socket type is used.
4870 An unconnected dgram socket (either 'dgram' or 'unix.dgram') must use
4871 `sendto` to specify the destination address.
4873 The path for Unix domain sockets is automatically removed when the socket
4874 is closed. Use `close -nodelete` in the rare case where this behaviour
4875 should be avoided (e.g. after `os.fork`).
4877 syslog
4878 ~~~~~~
4879 +*syslog* '?options? ?priority? message'+
4881 This  command sends message to system syslog facility with given
4882 priority. Valid priorities are:
4884     emerg, alert, crit, err, error, warning, notice, info, debug
4886 If a message is specified, but no priority is specified, then a
4887 priority of info is used.
4889 By default, facility user is used and the value of global tcl variable
4890 argv0 is used as ident string. However, any of the following options
4891 may be specified before priority to control these parameters:
4893 +*-facility* 'value'+::
4894     Use specified facility instead of user. The following
4895     values for facility are recognized:
4897     authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
4898     uucp, local0-local7
4900 +*-ident* 'string'+::
4901     Use given string instead of argv0 variable for ident string.
4903 +*-options* 'integer'+::
4904     Set syslog options such as +LOG_CONS+, +LOG_NDELAY+. You should
4905     use numeric values of those from your system syslog.h file,
4906     because I haven't got time to implement yet another hash
4907     table.
4909 pack: pack, unpack
4910 ~~~~~~~~~~~~~~~~~~
4911 The optional 'pack' extension provides commands to encode and decode binary strings.
4913 +*pack* 'varName value' *-intle|-intbe|-floatle|-floatbe|-str* 'bitwidth ?bitoffset?'+::
4914     Packs the binary representation of +'value'+ into the variable
4915     +'varName'+. The value is packed according to the given type
4916     (integer/floating point/string, big-endian/little-endian), width and bit offset.
4917     The variable is created if necessary (like `append`).
4918     The variable is expanded if necessary.
4920 +*unpack* 'binvalue' *-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str* 'bitpos bitwidth'+::
4921     Unpacks bits from +'binvalue'+ at bit position +'bitpos'+ and with +'bitwidth'+.
4922     Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
4923     and signed/unsigned) and returns it. For integer types, +'bitwidth'+
4924     may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
4925     +'bitwidth'+ may be 32 bits (for single precision numbers) or 64 bits (for double precision).
4926     For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
4927     access outside the length of the value will return 0 for integer types, 0.0 for floating point types
4928     or the empty string for the string type.
4930 zlib
4931 ~~~~
4932 The optional 'zlib' extension provides a Tcl-compatible subset of the `zlib` command.
4934 +*crc32* 'data' '?startValue?'+::
4935     Returns the CRC32 checksum of a buffer. Optionally, an initial value may be specified; this is most useful
4936     for calculating the checksum of chunked data read from a stream (for instance, a pipe).
4938 +*deflate* 'string' '?level?'+::
4939     Compresses a buffer and outputs a raw, Deflate-compressed stream. Optionally, a compression level (1-9) may
4940     be specified to choose the desired speed vs. compression rate ratio.
4942 +*inflate* 'data' '?bufferSize?'+::
4943     Decompresses a raw, Deflate-compressed stream. When the uncompressed data size is known and specified, memory
4944     allocation is more efficient. Otherwise, decomperssion is chunked and therefore slower.
4946 +*gzip* 'string' '?-level level?'+::
4947     Compresses a buffer and adds a gzip header.
4949 +*gunzip* 'data' '?-buffersize size?'+::
4950     Decompresses a gzip-compressed buffer. Decompression is chunked, with a default, small buffer size of 64K
4951     which guarantees lower memory footprint at the cost of speed. It is recommended to use a bigger size, on
4952     systems without a severe memory constraint.
4954 binary
4955 ~~~~~~
4956 The optional, pure-Tcl 'binary' extension provides the Tcl-compatible `binary scan` and `binary format`
4957 commands based on the low-level `pack` and `unpack` commands.
4959 See the Tcl documentation at: http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm
4961 Note that 'binary format' with f/r/R specifiers (single-precision float) uses the value of Infinity
4962  in case of overflow.
4964 oo: class, super
4965 ~~~~~~~~~~~~~~~~
4966 The optional, pure-Tcl 'oo' extension provides object-oriented (OO) support for Jim Tcl.
4968 See the online documentation (http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/) for more details.
4970 +*class* 'classname ?baseclasses? classvars'+::
4971     Create a new class, +'classname'+, with the given dictionary
4972     (+'classvars'+) as class variables. These are the initial variables
4973     which all newly created objects of this class are initialised with.
4974     If a list of baseclasses is given, methods and instance variables
4975     are inherited.
4977 +*super* 'method ?args \...?'+::
4978     From within a method, invokes the given method on the base class.
4979     Note that this will only call the last baseclass given.
4981 tree
4982 ~~~~
4983 The optional, pure-Tcl 'tree' extension implements an OO, general purpose tree structure
4984 similar to that provided by tcllib ::struct::tree (http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/struct_tree.html)
4986 A tree is a collection of nodes, where each node (except the root node) has a single parent
4987 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.
4989 +*tree*+::
4990     Creates and returns a new tree object with a single node named "root".
4991     All operations on the tree are invoked through this object.
4993 +$tree *destroy*+::
4994     Destroy the tree and all it's nodes. (Note that the tree will also
4995     be automatically garbage collected once it goes out of scope).
4997 +$tree *set* 'nodename key value'+::
4998     Set the value for the given attribute key.
5000 +$tree *lappend* 'nodename key value \...'+::
5001     Append to the (list) value(s) for the given attribute key, or set if not yet set.
5003 +$tree *keyexists* 'nodename key'+::
5004     Returns 1 if the given attribute key exists.
5006 +$tree *get* 'nodename key'+::
5007     Returns the value associated with the given attribute key.
5009 +$tree *getall* 'nodename'+::
5010     Returns the entire attribute dictionary associated with the given key.
5012 +$tree *depth* 'nodename'+::
5013     Returns the depth of the given node. The depth of "root" is 0.
5015 +$tree *parent* 'nodename'+::
5016     Returns the node name of the parent node, or "" for the root node.
5018 +$tree *numchildren* 'nodename'+::
5019     Returns the number of child nodes.
5021 +$tree *children* 'nodename'+::
5022     Returns a list of the child nodes.
5024 +$tree *next* 'nodename'+::
5025     Returns the next sibling node, or "" if none.
5027 +$tree *insert* 'nodename ?index?'+::
5028     Add a new child node to the given node. The index is a list index
5029     such as +3+ or +end-2+. The default index is +end+.
5030     Returns the name of the newly added node.
5032 +$tree *walk* 'nodename' *dfs|bfs* {'actionvar nodevar'} 'script'+::
5033     Walks the tree starting from the given node, either breadth first (+bfs+)
5034     depth first (+dfs+).
5035     The value +"enter"+ or +"exit"+ is stored in variable +'actionvar'+.
5036     The name of each node is stored in +'nodevar'+.
5037     The script is evaluated twice for each node, on entry and exit.
5039 +$tree *dump*+::
5040     Dumps the tree contents to stdout
5042 tcl::prefix
5043 ~~~~~~~~~~~
5044 The optional tclprefix extension provides the Tcl8.6-compatible `tcl::prefix` command
5045 (http://www.tcl.tk/man/tcl8.6/TclCmd/prefix.htm) for matching strings against a table
5046 of possible values (typically commands or options).
5048 +*tcl::prefix all* 'table string'+::
5049     Returns a list of all elements in +'table'+ that begin with the prefix +'string'+.
5051 +*tcl::prefix longest* 'table string'+::
5052     Returns the longest common prefix of all elements in +'table'+ that begin with the prefix +'string'+.
5054 +*tcl::prefix match* '?options? table string'+::
5055     If +'string'+ equals one element in +'table'+ or is a prefix to
5056     exactly one element, the matched element is returned. If not, the
5057     result depends on the +-error+ option.
5059     * +*-exact*+ Accept only exact matches.
5060     * +*-message* 'string'+ Use +'string'+ in the error message at a mismatch. Default is "option".
5061     * +*-error* 'options'+ The options are used when no match is found. If +'options'+ is
5062       empty, no error is generated and an empty string is returned.
5063       Otherwise the options are used as return options when
5064       generating the error message. The default corresponds to
5065       setting +-level 0+.
5067 tcl::autocomplete
5068 ~~~~~~~~~~~~~~~~~
5069 Scriptable command line completion is supported in the interactive shell, 'jimsh', through
5070 the `tcl::autocomplete` callback. A simple implementation is provided, however this may
5071 be replaced with a custom command instead if desired.
5073 In the interactive shell, press <TAB> to activate command line completion.
5075 +*tcl::autocomplete* 'commandline'+::
5076     This command is called with the current command line when the user presses <TAB>.
5077     The command should return a list of all possible command lines that match the current command line.
5078     For example if +*pr*+ is the current command line, the list +*{prefix proc}*+ may be returned.
5080 history
5081 ~~~~~~~
5082 The optional history extension provides script access to the command line editing
5083 and history support available in 'jimsh'. See 'examples/jtclsh.tcl' for an example.
5084 Note: if line editing support is not available, `history getline` acts like `gets` and
5085 the remaining subcommands do nothing.
5087 +*history load* 'filename'+::
5088     Load history from a (text) file. If the file does not exist or is not readable,
5089     it is ignored.
5091 +*history getline* 'prompt ?varname?'+::
5092     Displays the given prompt and allows a line to be entered. Similarly to `gets`,
5093     if +'varname'+ is given, it receives the line and the length of the line is returned,
5094     or -1 on EOF. If +'varname'+ is not given, the line is returned directly.
5096 +*history completion* 'command'+::
5097     Sets an autocompletion command (see `tcl::autocomplete`) that is active during `history getline`.
5098     If the command is empty, autocompletion is disabled.
5100 +*history add* 'line'+::
5101     Adds the given line to the history buffer.
5103 +*history save* 'filename'+::
5104     Saves the current history buffer to the given file.
5106 +*history show*+::
5107     Displays the current history buffer to standard output.
5109 namespace
5110 ~~~~~~~~~
5111 Provides namespace-related functions. See also: http://www.tcl.tk/man/tcl8.6/TclCmd/namespace.htm
5113 +*namespace code* 'script'+::
5114     Captures the current namespace context for later execution of
5115     the script +'script'+. It returns a new script in which script has
5116     been wrapped in a +*namespace inscope*+ command.
5118 +*namespace current*+::
5119     Returns the fully-qualified name for the current namespace.
5121 +*namespace delete* '?namespace ...?'+::
5122     Deletes all commands and variables with the given namespace prefixes.
5124 +*namespace eval* 'namespace arg ?arg...?'+::
5125     Activates a namespace called +'namespace'+ and evaluates some code in that context.
5127 +*namespace origin* 'command'+::
5128     Returns the fully-qualified name of the original command to which the imported command +'command'+ refers.
5130 +*namespace parent* ?namespace?+::
5131     Returns the fully-qualified name of the parent namespace for namespace +'namespace'+, if given, otherwise
5132     for the current namespace.
5134 +*namespace qualifiers* 'string'+::
5135     Returns any leading namespace qualifiers for +'string'+
5137 +*namespace tail* 'string'+::
5138     Returns the simple name at the end of a qualified string.
5140 +*namespace upvar* 'namespace ?arg...?'+::
5141     This command arranges for zero or more local variables in the current procedure to refer to variables in +'namespace'+
5143 +*namespace which* '?-command|-variable? name'+::
5144     Looks up +'name'+ as either a command (the default) or variable and returns its fully-qualified name.
5146 interp
5147 ~~~~~~
5148 The optional 'interp' command allows sub-interpreters to be created where commands may be run
5149 independently (but synchronously) of the main interpreter.
5151 +*interp*+::
5152     Creates and returns a new interpreter object (command).
5153     The created interpeter contains any built-in commands along with static extensions,
5154     but does not include any dynamically loaded commands (package require, load).
5155     These must be reloaded in the child interpreter if required.
5157 +*$interp delete*+::
5158     Deletes the interpeter object.
5160 +*$interp eval* 'script' ...+::
5161     Evaluates a script in the context for the child interpreter, in the same way as 'eval'.
5163 +*$interp alias* 'alias childcmd parentcmd ?arg ...?'+::
5164     Similar to 'alias', but creates a command, +'childcmd'+, in the child interpreter that is an
5165     alias for +'parentcmd'+ in the parent interpreter, with the given, fixed arguments.
5166     The alias may be deleted in the child with 'rename'.
5168 [[BuiltinVariables]]
5169 BUILT-IN VARIABLES
5170 ------------------
5172 The following global variables are created automatically
5173 by the Tcl library.
5175 +*env*+::
5176     This variable is set by Jim as an array
5177     whose elements are the environment variables for the process.
5178     Reading an element will return the value of the corresponding
5179     environment variable.
5180     This array is initialised at startup from the `env` command.
5181     It may be modified and will affect the environment passed to
5182     commands invoked with `exec`.
5184 +*platform_tcl*+::
5185     This variable is set by Jim as an array containing information
5186     about the platform on which Jim was built. Currently this includes
5187     'os' and 'platform'.
5189 +*auto_path*+::
5190     This variable contains a list of paths to search for packages.
5191     It defaults to a location based on where jim is installed
5192     (e.g. +/usr/local/lib/jim+), but may be changed by +jimsh+
5193     or the embedding application. Note that +jimsh+ will consider
5194     the environment variable +$JIMLIB+ to be a list of colon-separated
5195     list of paths to add to +*auto_path*+.
5197 +*errorCode*+::
5198     This variable holds the value of the -errorcode return
5199     option set by the most recent error that occurred in this
5200     interpreter. This list value represents additional information
5201     about the error in a form that is easy to process with
5202     programs. The first element of the list identifies a general
5203     class of errors, and determines the format of the rest of
5204     the list. The following formats for -errorcode return options
5205     are used by the Tcl core; individual applications may define
5206     additional formats. Currently only `exec` sets this variable.
5207     Otherwise it will be +NONE+.
5209 The following global variables are set by jimsh.
5211 +*tcl_interactive*+::
5212     This variable is set to 1 if jimsh is started in interactive mode
5213     or 0 otherwise.
5215 +*tcl_platform*+::
5216     This variable is set by Jim as an array containing information
5217     about the platform upon which Jim was built. The following is an
5218     example of the contents of this array.
5220     tcl_platform(byteOrder)     = littleEndian
5221     tcl_platform(engine)        = Jim
5222     tcl_platform(os)            = Darwin
5223     tcl_platform(platform)      = unix
5224     tcl_platform(pointerSize)   = 8
5225     tcl_platform(threaded)      = 0
5226     tcl_platform(wordSize)      = 8
5227     tcl_platform(pathSeparator) = :
5229 +*argv0*+::
5230     If jimsh is invoked to run a script, this variable contains the name
5231     of the script.
5233 +*argv*+::
5234     If jimsh is invoked to run a script, this variable contains a list
5235     of any arguments supplied to the script.
5237 +*argc*+::
5238     If jimsh is invoked to run a script, this variable contains the number
5239     of arguments supplied to the script.
5241 +*jim::argv0*+::
5242     The value of argv[0] when jimsh was invoked.
5244 The following variables have special meaning to Jim Tcl:
5246 +*jim::defer*+::
5247     If this variable is set, it is considered to be a list of scripts to evaluate
5248     when the current proc exits (local variables), or the interpreter exits (global variable).
5249     See `defer`.
5251 +*history::multiline*+::
5252     If this variable is set to "1", interactive line editing operates in multiline mode.
5253     That is, long lines will wrap across multiple lines rather than scrolling within a
5254     single line.
5256 CHANGES IN PREVIOUS RELEASES
5257 ----------------------------
5259 === In v0.70 ===
5261 1. +platform_tcl()+ settings are now automatically determined
5262 2. Add aio `$handle filename`
5263 3. Add `info channels`
5264 4. The 'bio' extension is gone. Now `aio` supports 'copyto'.
5265 5. Add `exists` command
5266 6. Add the pure-Tcl 'oo' extension
5267 7. The `exec` command now only uses vfork(), not fork()
5268 8. Unit test framework is less verbose and more Tcl-compatible
5269 9. Optional UTF-8 support
5270 10. Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
5271 11. Command line editing in interactive mode, e.g. 'jimsh'
5273 === In v0.63 ===
5275 1. `source` now checks that a script is complete (.i.e. not missing a brace)
5276 2. 'info complete' now uses the real parser and so is 100% accurate
5277 3. Better access to live stack frames with 'info frame', `stacktrace` and `stackdump`
5278 4. `tailcall` no longer loses stack trace information
5279 5. Add `alias` and `curry`
5280 6. `lambda`, `alias` and `curry` are implemented via `tailcall` for efficiency
5281 7. `local` allows procedures to be deleted automatically at the end of the current procedure
5282 8. udp sockets are now supported for both clients and servers.
5283 9. vfork-based exec is now working correctly
5284 10. Add 'file tempfile'
5285 11. Add 'socket pipe'
5286 12. Enhance 'try ... on ... finally' to be more Tcl 8.6 compatible
5287 13. It is now possible to `return` from within `try`
5288 14. IPv6 support is now included
5289 15. Add 'string is'
5290 16. Event handlers works better if an error occurs. eof handler has been removed.
5291 17. `exec` now sets $::errorCode, and catch sets opts(-errorcode) for exit status
5292 18. Command pipelines via open "|..." are now supported
5293 19. `pid` can now return pids of a command pipeline
5294 20. Add 'info references'
5295 21. Add support for 'after +'ms'+', 'after idle', 'after info', `update`
5296 22. `exec` now sets environment based on $::env
5297 23. Add 'dict keys'
5298 24. Add support for 'lsort -index'
5300 === In v0.62 ===
5302 1. Add support to `exec` for '>&', '>>&', '|&', '2>@1'
5303 2. Fix `exec` error messages when special token (e.g. '>') is the last token
5304 3. Fix `subst` handling of backslash escapes.
5305 4. Allow abbreviated options for `subst`
5306 5. Add support for `return`, `break`, `continue` in subst
5307 6. Many `expr` bug fixes
5308 7. Add support for functions in `expr` (e.g. int(), abs()), and also 'in', 'ni' list operations
5309 8. The variable name argument to `regsub` is now optional
5310 9. Add support for 'unset -nocomplain'
5311 10. Add support for list commands: `lassign`, `lrepeat`
5312 11. Fully-functional `lsearch` is now implemented
5313 12. Add 'info nameofexecutable' and 'info returncodes'
5314 13. Allow `catch` to determine what return codes are caught
5315 14. Allow `incr` to increment an unset variable by first setting to 0
5316 15. Allow 'args' and optional arguments to the left or required arguments in `proc`
5317 16. Add 'file copy'
5318 17. Add 'try ... finally' command
5321 LICENCE
5322 -------
5324  Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
5325  Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
5326  Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
5327  Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
5328  Copyright 2008 Andrew Lunn <andrew@lunn.ch>
5329  Copyright 2008 Duane Ellis <openocd@duaneellis.com>
5330  Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
5331  Copyright 2009 Steve Bennett <steveb@workware.net.au>
5333 [literal]
5334  Redistribution and use in source and binary forms, with or without
5335  modification, are permitted provided that the following conditions
5336  are met:
5337  1. Redistributions of source code must retain the above copyright
5338     notice, this list of conditions and the following disclaimer.
5339  2. Redistributions in binary form must reproduce the above
5340     copyright notice, this list of conditions and the following
5341     disclaimer in the documentation and/or other materials
5342     provided with the distribution.
5344  THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
5345  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
5346  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
5347  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
5348  JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
5349  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5350  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5351  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5352  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
5353  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5354  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5355  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5357  The views and conclusions contained in the software and documentation
5358  are those of the authors and should not be interpreted as representing
5359  official policies, either expressed or implied, of the Jim Tcl Project.