Improve comments for JimResetHashTable()
[jimtcl.git] / jim_tcl.txt
blob754210f6bd9587f98bdd8b93dcaa0e2b5cdb61a6
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
59 3. Add support for `aio lock -wait`
60 4. Add `signal block` to prevent delivery of signals
61 5. Add support for `file split`
63 Changes between 0.77 and 0.78
64 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65 1. Add serial/tty support with `aio tty`
66 2. Add support for 'jimsh -'
67 3. Add hidden '-commands' option to many commands
68 4. Add scriptable autocompletion support in interactive mode with `tcl::autocomplete`
69 5. Add `aio sockopt`
70 6. Add scriptable autocompletion support with `history completion`
71 7. Add support for `tree delete`
72 8. Add support for `defer` and '$jim::defer'
73 9. Renamed `os.wait` to `wait`, now more Tcl-compatible and compatible with `exec ... &`
74 10. `pipe` is now a synonym for `socket pipe`
75 11. Closing a pipe open with `open |...` now returns Tcl-like status
76 12. It is now possible to used `exec` redirection with a pipe opened with `open |...`
77 13. Interactive line editing now supports multiline mode if $::history::multiline is set
79 Changes between 0.76 and 0.77
80 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81 1. Add support for `aio sync`
82 2. Add SSL and TLS support in aio
83 3. Added `zlib`
84 4. Added support for boolean constants in `expr`
85 5. `string is` now supports 'boolean' class
86 6. Add support for `aio lock` and `aio unlock`
87 7. Add new `interp` command
89 Changes between 0.75 and 0.76
90 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91 1. `glob` now supports the +-tails+ option
92 2. Add support for `string cat`
93 3. Allow `info source` to add source info
95 Changes between 0.74 and 0.75
96 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97 1. `binary`, `pack` and `unpack` now support floating point
98 2. `file copy` +-force+ handles source and target as the same file
99 3. `format` now supports +%b+ for binary conversion
100 4. `lsort` now supports +-unique+ and +-real+
101 5. Add support for half-close with `aio close` +?r|w?+
102 6. Add `socket pair` for a bidirectional pipe
103 7. Add '--random-hash' to randomise hash tables for greater security
104 8. `dict` now supports 'for', 'values', 'incr', 'append', 'lappend', 'update', 'info' and 'replace'
105 9. `file stat` no longer requires the variable name
106 10. Add support for `file link`
108 Changes between 0.73 and 0.74
109 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110 1. Numbers with leading zeros are treated as decimal, not octal
111 2. Add `aio isatty`
112 3. Add LFS (64 bit) support for `aio seek`, `aio tell`, `aio copyto`, `file copy`
113 4. `string compare` and `string equal` now support '-length'
114 5. `glob` now supports '-directory'
116 Changes between 0.72 and 0.73
117 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118 1. Built-in regexp now support non-capturing parentheses: (?:...)
119 2. Add `string replace`
120 3. Add `string totitle`
121 4. Add `info statics`
122 5. Add +build-jim-ext+ for easy separate building of loadable modules (extensions)
123 6. `local` now works with any command, not just procs
124 7. Add `info alias` to access the target of an alias
125 8. UTF-8 encoding past the basic multilingual plane (BMP) is supported
126 9. Add `tcl::prefix`
127 10. Add `history`
128 11. Most extensions are now enabled by default
129 12. Add support for namespaces and the `namespace` command
130 13. Add `apply`
132 Changes between 0.71 and 0.72
133 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
134 1. procs now allow 'args' and optional parameters in any position
135 2. Add Tcl-compatible expr functions, `rand()`, `srand()` and `pow()`
136 3. Add support for the '-force' option to `file delete`
137 4. Better diagnostics when `source` fails to load a script with a missing quote or bracket
138 5. New +tcl_platform(pathSeparator)+
139 6. Add support settings the modification time with `file mtime`
140 7. `exec` is now fully supported on win32 (mingw32)
141 8. `file join`, `pwd`, `glob` etc. now work for mingw32
142 9. Line editing is now supported for the win32 console (mingw32)
143 10. Add `aio listen` command
145 Changes between 0.70 and 0.71
146 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147 1. Allow 'args' to be renamed in procs
148 2. Add +$(...)+ shorthand syntax for expressions
149 3. Add automatic reference variables in procs with +&var+ syntax
150 4. Support +jimsh --version+
151 5. Additional variables in +tcl_platform()+
152 6. `local` procs now push existing commands and `upcall` can call them
153 7. Add `loop` command (TclX compatible)
154 8. Add `aio buffering` command
155 9. `info complete` can now return the missing character
156 10. `binary format` and `binary scan` are now (optionally) supported
157 11. Add `string byterange`
158 12. Built-in regexp now support non-greedy repetition (*?, +?, ??)
160 TCL INTRODUCTION
161 -----------------
162 Tcl stands for 'tool command language' and is pronounced
163 'http://www.oxforddictionaries.com/definition/american_english/tickle[tickle]'.
164 It is actually two things: a language and a library.
166 First, Tcl is a simple textual language, intended primarily for
167 issuing commands to interactive programs such as text editors,
168 debuggers, illustrators, and shells.  It has a simple syntax and is also
169 programmable, so Tcl users can write command procedures to provide more
170 powerful commands than those in the built-in set.
172 Second, Tcl is a library package that can be embedded in application
173 programs.  The Tcl library consists of a parser for the Tcl language,
174 routines to implement the Tcl built-in commands, and procedures that
175 allow each application to extend Tcl with additional commands specific
176 to that application.  The application program generates Tcl commands and
177 passes them to the Tcl parser for execution.  Commands may be generated
178 by reading characters from an input source, or by associating command
179 strings with elements of the application's user interface, such as menu
180 entries, buttons, or keystrokes.
182 When the Tcl library receives commands it parses them into component
183 fields and executes built-in commands directly.  For commands implemented
184 by the application, Tcl calls back to the application to execute the
185 commands.  In many cases commands will invoke recursive invocations of the
186 Tcl interpreter by passing in additional strings to execute (procedures,
187 looping commands, and conditional commands all work in this way).
189 An application program gains three advantages by using Tcl for its command
190 language.  First, Tcl provides a standard syntax:  once users know Tcl,
191 they will be able to issue commands easily to any Tcl-based application.
192 Second, Tcl provides programmability.  All a Tcl application needs
193 to do is to implement a few application-specific low-level commands.
194 Tcl provides many utility commands plus a general programming interface
195 for building up complex command procedures.  By using Tcl, applications
196 need not re-implement these features.
198 Third, Tcl can be used as a common language for communicating between
199 applications.  Inter-application communication is not built into the
200 Tcl core described here, but various add-on libraries, such as the Tk
201 toolkit, allow applications to issue commands to each other.  This makes
202 it possible for applications to work together in much more powerful ways
203 than was previously possible.
205 Fourth, Jim Tcl includes a command processor, +jimsh+, which can be
206 used to run standalone Tcl scripts, or to run Tcl commands interactively.
208 This manual page focuses primarily on the Tcl language.  It describes
209 the language syntax and the built-in commands that will be available
210 in any application based on Tcl.  The individual library procedures are
211 described in more detail in separate manual pages, one per procedure.
213 JIMSH COMMAND INTERPRETER
214 -------------------------
215 A simple, but powerful command processor, +jimsh+, is part of Jim Tcl.
216 It may be invoked in interactive mode as:
218   jimsh
220 or to process the Tcl script in a file with:
222   jimsh filename
224 or to process the Tcl script from standard input:
226   jimsh -
228 It may also be invoked to execute an immediate script with:
230   jimsh -e "script"
232 Interactive Mode
233 ~~~~~~~~~~~~~~~~
234 Interactive mode reads Tcl commands from standard input, evaluates
235 those commands and prints the results.
237   $ jimsh
238   Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
239   . info version
240   0.73
241   . lsort [info commands p*]
242   package parray pid popen proc puts pwd
243   . foreach i {a b c} {
244   {> puts $i
245   {> }
246   a
247   b
248   c
249   . bad
250   invalid command name "bad"
251   [error] . exit
252   $
254 If +jimsh+ is configured with line editing (it is by default) and a VT-100-compatible
255 terminal is detected, Emacs-style line editing commands are available, including:
256 arrow keys, +\^W+ to erase a word, +\^U+ to erase the line, +^R+ for reverse incremental search
257 in history. Additionally, the +h+ command may be used to display the command history.
259 Command line history is automatically saved and loaded from +~/.jim_history+
261 In interactive mode, +jimsh+ automatically runs the script +~/.jimrc+ at startup
262 if it exists.
264 INTERPRETERS
265 ------------
266 The central data structure in Tcl is an interpreter (C type 'Jim_Interp').
267 An interpreter consists of a set of command bindings, a set of variable
268 values, and a few other miscellaneous pieces of state.  Each Tcl command
269 is interpreted in the context of a particular interpreter.
271 Some Tcl-based applications will maintain multiple interpreters
272 simultaneously, each associated with a different widget or portion of
273 the application.  Interpreters are relatively lightweight structures.
274 They can be created and deleted quickly, so application programmers should
275 feel free to use multiple interpreters if that simplifies the application.
277 DATA TYPES
278 ----------
279 Tcl supports only one type of data:  strings.  All commands, all arguments
280 to commands, all command results, and all variable values are strings.
282 Where commands require numeric arguments or return numeric results,
283 the arguments and results are passed as strings.  Many commands expect
284 their string arguments to have certain formats, but this interpretation
285 is up to the individual commands.  For example, arguments often contain
286 Tcl command strings, which may get executed as part of the commands.
287 The easiest way to understand the Tcl interpreter is to remember that
288 everything is just an operation on a string.  In many cases Tcl constructs
289 will look similar to more structured constructs from other languages.
290 However, the Tcl constructs are not structured at all; they are just
291 strings of characters, and this gives them a different behaviour than
292 the structures they may look like.
294 Although the exact interpretation of a Tcl string depends on who is doing
295 the interpretation, there are three common forms that strings take:
296 commands, expressions, and lists.  The major sections below discuss
297 these three forms in more detail.
299 BASIC COMMAND SYNTAX
300 --------------------
301 The Tcl language has syntactic similarities to both the Unix shells
302 and Lisp.  However, the interpretation of commands is different
303 in Tcl than in either of those other two systems.
304 A Tcl command string consists of one or more commands separated
305 by newline characters or semi-colons.
306 Each command consists of a collection of fields separated by
307 white space (spaces or tabs).
308 The first field must be the name of a command, and the
309 additional fields, if any, are arguments that will be passed to
310 that command.  For example, the command:
312 ----
313     set a 22
314 ----
316 has three fields:  the first, `set`, is the name of a Tcl command, and
317 the last two, 'a' and '22', will be passed as arguments to
318 the `set` command.  The command name may refer either to a built-in
319 Tcl command, an application-specific command bound in with the library
320 procedure 'Jim_CreateCommand', or a command procedure defined with the
321 `proc` built-in command.
323 Arguments are passed literally as text strings.  Individual commands may
324 interpret those strings in any fashion they wish.  The `set` command,
325 for example, will treat its first argument as the name of a variable
326 and its second argument as a string value to assign to that variable.
327 For other commands arguments may be interpreted as integers, lists,
328 file names, or Tcl commands.
330 Command names should normally be typed completely (e.g. no abbreviations).
331 However, if the Tcl interpreter cannot locate a command it invokes a
332 special command named `unknown` which attempts to find or create the
333 command.
335 For example, at many sites `unknown` will search through library
336 directories for the desired command and create it as a Tcl procedure if
337 it is found.  The `unknown` command often provides automatic completion
338 of abbreviated commands, but usually only for commands that were typed
339 interactively.
341 It's probably a bad idea to use abbreviations in command scripts and
342 other forms that will be re-used over time:  changes to the command set
343 may cause abbreviations to become ambiguous, resulting in scripts that
344 no longer work.
346 COMMENTS
347 --------
348 If the first non-blank character in a command is +\#+, then everything
349 from the +#+ up through the next newline character is treated as
350 a comment and ignored.  When comments are embedded inside nested
351 commands (e.g. fields enclosed in braces) they must have properly-matched
352 braces (this is necessary because when Tcl parses the top-level command
353 it doesn't yet know that the nested field will be used as a command so
354 it cannot process the nested comment character as a comment).
356 GROUPING ARGUMENTS WITH DOUBLE-QUOTES
357 -------------------------------------
358 Normally each argument field ends at the next white space, but
359 double-quotes may be used to create arguments with embedded space.
361 If an argument field begins with a double-quote, then the argument isn't
362 terminated by white space (including newlines) or a semi-colon (see below
363 for information on semi-colons); instead it ends at the next double-quote
364 character.  The double-quotes are not included in the resulting argument.
365 For example, the command
367 ----
368     set a "This is a single argument"
369 ----
371 will pass two arguments to `set`:  'a' and 'This is a single argument'.
373 Within double-quotes, command substitutions, variable substitutions,
374 and backslash substitutions still occur, as described below.  If the
375 first character of a command field is not a quote, then quotes receive
376 no special interpretation in the parsing of that field.
378 GROUPING ARGUMENTS WITH BRACES
379 ------------------------------
380 Curly braces may also be used for grouping arguments.  They are similar
381 to quotes except for two differences.  First, they nest; this makes them
382 easier to use for complicated arguments like nested Tcl command strings.
383 Second, the substitutions described below for commands, variables, and
384 backslashes do *not* occur in arguments enclosed in braces, so braces
385 can be used to prevent substitutions where they are undesirable.
387 If an argument field begins with a left brace, then the argument ends
388 at the matching right brace.  Tcl will strip off the outermost layer
389 of braces and pass the information between the braces to the command
390 without any further modification.  For example, in the command
392 ----
393     set a {xyz a {b c d}}
394 ----
396 the `set` command will receive two arguments: 'a'
397 and 'xyz a {b c d}'.
399 When braces or quotes are in effect, the matching brace or quote need
400 not be on the same line as the starting quote or brace; in this case
401 the newline will be included in the argument field along with any other
402 characters up to the matching brace or quote.  For example, the `eval`
403 command takes one argument, which is a command string; `eval` invokes
404 the Tcl interpreter to execute the command string.  The command
406 ----
407     eval {
408       set a 22
409       set b 33
410     }
411 ----
413 will assign the value '22' to 'a' and '33' to 'b'.
415 If the first character of a command field is not a left
416 brace, then neither left nor right
417 braces in the field will be treated specially (except as part of
418 variable substitution; see below).
420 COMMAND SUBSTITUTION WITH BRACKETS
421 ----------------------------------
422 If an open bracket occurs in a field of a command, then command
423 substitution occurs (except for fields enclosed in braces).  All of the
424 text up to the matching close bracket is treated as a Tcl command and
425 executed immediately.  Then the result of that command is substituted
426 for the bracketed text.  For example, consider the command
428 ----
429     set a [set b]
430 ----
432 When the `set` command has only a single argument, it is the name of a
433 variable and `set` returns the contents of that variable.  In this case,
434 if variable 'b' has the value 'foo', then the command above is equivalent
435 to the command
437 ----
438     set a foo
439 ----
441 Brackets can be used in more complex ways.  For example, if the variable
442 'b' has the value 'foo' and the variable 'c' has the value 'gorp',
443 then the command
445 ----
446     set a xyz[set b].[set c]
447 ----
449 is equivalent to the command
451 ----
452     set a xyzfoo.gorp
453 ----
455 A bracketed command may contain multiple commands separated by newlines
456 or semi-colons in the usual fashion.  In this case the value of the last
457 command is used for substitution.  For example, the command
459 ----
460     set a x[set b 22
461     expr $b+2]x
462 ----
464 is equivalent to the command
466 ----
467     set a x24x
468 ----
470 If a field is enclosed in braces then the brackets and the characters
471 between them are not interpreted specially; they are passed through to
472 the argument verbatim.
474 VARIABLE SUBSTITUTION WITH $
475 ----------------------------
476 The dollar sign (+$+) may be used as a special shorthand form for
477 substituting variable values.  If +$+ appears in an argument that isn't
478 enclosed in braces then variable substitution will occur.  The characters
479 after the +$+, up to the first character that isn't a number, letter,
480 or underscore, are taken as a variable name and the string value of that
481 variable is substituted for the name.
483 For example, if variable 'foo' has the value 'test', then the command
485 ----
486     set a $foo.c
487 ----
489 is equivalent to the command
491 ----
492     set a test.c
493 ----
495 There are two special forms for variable substitution.  If the next
496 character after the name of the variable is an open parenthesis, then
497 the variable is assumed to be an array name, and all of the characters
498 between the open parenthesis and the next close parenthesis are taken as
499 an index into the array.  Command substitutions and variable substitutions
500 are performed on the information between the parentheses before it is
501 used as an index.
503 For example, if the variable 'x' is an array with one element named
504 'first' and value '87' and another element named '14' and value 'more',
505 then the command
507 ----
508     set a xyz$x(first)zyx
509 ----
511 is equivalent to the command
513 ----
514     set a xyz87zyx
515 ----
517 If the variable 'index' has the value '14', then the command
519 ----
520     set a xyz$x($index)zyx
521 ----
523 is equivalent to the command
525 ----
526     set a xyzmorezyx
527 ----
529 For more information on arrays, see <<_variables_scalars_and_arrays,VARIABLES - SCALARS AND ARRAYS>> below.
531 The second special form for variables occurs when the dollar sign is
532 followed by an open curly brace.  In this case the variable name consists
533 of all the characters up to the next curly brace.
535 Array references are not possible in this form:  the name between braces
536 is assumed to refer to a scalar variable.  For example, if variable
537 'foo' has the value 'test', then the command
539 ----
540     set a abc${foo}bar
541 ----
543 is equivalent to the command
545 ----
546     set a abctestbar
547 ----
550 Variable substitution does not occur in arguments that are enclosed in
551 braces:  the dollar sign and variable name are passed through to the
552 argument verbatim.
554 The dollar sign abbreviation is simply a shorthand form.  +$a+ is
555 completely equivalent to +[set a]+; it is provided as a convenience
556 to reduce typing.
558 SEPARATING COMMANDS WITH SEMI-COLONS
559 ------------------------------------
560 Normally, each command occupies one line (the command is terminated by a
561 newline character).  However, semi-colon (+;+) is treated as a command
562 separator character; multiple commands may be placed on one line by
563 separating them with a semi-colon.  Semi-colons are not treated as
564 command separators if they appear within curly braces or double-quotes.
566 BACKSLASH SUBSTITUTION
567 ----------------------
568 Backslashes may be used to insert non-printing characters into command
569 fields and also to insert special characters like braces and brackets
570 into fields without them being interpreted specially as described above.
572 The backslash sequences understood by the Tcl interpreter are
573 listed below.  In each case, the backslash
574 sequence is replaced by the given character:
575 [[BackslashSequences]]
576 +{backslash}b+::
577     Backspace (0x8)
579 +{backslash}f+::
580     Form feed (0xc)
582 +{backslash}n+::
583     Newline (0xa)
585 +{backslash}r+::
586     Carriage-return (0xd).
588 +{backslash}t+::
589     Tab (0x9).
591 +{backslash}v+::
592     Vertical tab (0xb).
594 +{backslash}{+::
595     Left brace ({).
597 +{backslash}}+::
598     Right brace (}).
600 +{backslash}[+::
601     Open bracket ([).
603 +{backslash}]+::
604     Close bracket (]).
606 +{backslash}$+::
607     Dollar sign ($).
609 +{backslash}<space>+::
610     Space ( ): doesn't terminate argument.
612 +{backslash};+::
613     Semi-colon: doesn't terminate command.
615 +{backslash}"+::
616     Double-quote.
618 +{backslash}<newline>+::
619     Nothing:  this joins two lines together
620     into a single line.  This backslash feature is unique in that
621     it will be applied even when the sequence occurs within braces.
623 +{backslash}{backslash}+::
624     Backslash ('{backslash}').
626 +{backslash}ddd+::
627     The digits +'ddd'+ (one, two, or three of them) give the octal value of
628     the character.  Note that Jim supports null characters in strings.
630 +{backslash}unnnn+::
631 +{backslash}u\{nnn\}+::
632 +{backslash}Unnnnnnnn+::
633     The UTF-8 encoding of the unicode codepoint represented by the hex digits, +'nnnn'+, is inserted.
634     The 'u' form allows for one to four hex digits.
635     The 'U' form allows for one to eight hex digits.
636     The 'u\{nnn\}' form allows for one to eight hex digits, but makes it easier to insert
637     characters UTF-8 characters which are followed by a hex digit.
639 For example, in the command
641 ----
642     set a \{x\[\ yz\141
643 ----
645 the second argument to `set` will be +{x[ yza+.
647 If a backslash is followed by something other than one of the options
648 described above, then the backslash is transmitted to the argument
649 field without any special processing, and the Tcl scanner continues
650 normal processing with the next character.  For example, in the
651 command
653 ----
654     set \*a \\\{foo
655 ----
657 The first argument to `set` will be +{backslash}*a+ and the second
658 argument will be +{backslash}{foo+.
660 If an argument is enclosed in braces, then backslash sequences inside
661 the argument are parsed but no substitution occurs (except for
662 backslash-newline):  the backslash
663 sequence is passed through to the argument as is, without making
664 any special interpretation of the characters in the backslash sequence.
665 In particular, backslashed braces are not counted in locating the
666 matching right brace that terminates the argument.
667 For example, in the
668 command
670 ----
671     set a {\{abc}
672 ----
674 the second argument to `set` will be +{backslash}{abc+.
676 This backslash mechanism is not sufficient to generate absolutely
677 any argument structure; it only covers the
678 most common cases.  To produce particularly complicated arguments
679 it is probably easiest to use the `format` command along with
680 command substitution.
682 STRING AND LIST INDEX SPECIFICATIONS
683 ------------------------------------
685 Many string and list commands take one or more 'index' parameters which
686 specify a position in the string relative to the start or end of the string/list.
688 The index may be one of the following forms:
690 +integer+::
691     A simple integer, where '0' refers to the first element of the string
692     or list.
694 +integer+integer+ or::
695 +integer-integer+::
696     The sum or difference of the two integers. e.g. +2+3+ refers to the 5th element.
697     This is useful when used with (e.g.) +$i+1+ rather than the more verbose
698     +[expr {$i+1\}]+
700 +end+::
701     The last element of the string or list.
703 +end-integer+::
704     The 'nth-from-last' element of the string or list.
706 COMMAND SUMMARY
707 ---------------
708 1. A command is just a string.
709 2. Within a string commands are separated by newlines or semi-colons
710    (unless the newline or semi-colon is within braces or brackets
711    or is backslashed).
712 3. A command consists of fields.  The first field is the name of the command.
713    The other fields are strings that are passed to that command as arguments.
714 4. Fields are normally separated by white space.
715 5. Double-quotes allow white space and semi-colons to appear within
716    a single argument.
717    Command substitution, variable substitution, and backslash substitution
718    still occur inside quotes.
719 6. Braces defer interpretation of special characters.
720    If a field begins with a left brace, then it consists of everything
721    between the left brace and the matching right brace. The
722    braces themselves are not included in the argument.
723    No further processing is done on the information between the braces
724    except that backslash-newline sequences are eliminated.
725 7. If a field doesn't begin with a brace then backslash,
726    variable, and command substitution are done on the field.  Only a
727    single level of processing is done:  the results of one substitution
728    are not scanned again for further substitutions or any other
729    special treatment.  Substitution can
730    occur on any field of a command, including the command name
731    as well as the arguments.
732 8. If the first non-blank character of a command is a +\#+, everything
733    from the +#+ up through the next newline is treated as a comment
734    and ignored.
736 EXPRESSIONS
737 -----------
738 The second major interpretation applied to strings in Tcl is
739 as expressions.  Several commands, such as `expr`, `for`,
740 and `if`, treat one or more of their arguments as expressions
741 and call the Tcl expression processors ('Jim_ExprLong',
742 'Jim_ExprBoolean', etc.) to evaluate them.
744 The operators permitted in Tcl expressions are a subset of
745 the operators permitted in C expressions, and they have the
746 same meaning and precedence as the corresponding C operators.
747 Expressions almost always yield numeric results
748 (integer or floating-point values).
749 For example, the expression
751 ----
752     8.2 + 6
753 ----
755 evaluates to 14.2.
757 Tcl expressions differ from C expressions in the way that
758 operands are specified, and in that Tcl expressions support
759 non-numeric operands and string comparisons.
761 A Tcl expression consists of a combination of operands, operators,
762 and parentheses.
764 White space may be used between the operands and operators and
765 parentheses; it is ignored by the expression processor.
766 Where possible, operands are interpreted as integer values.
768 Integer values may be specified in decimal (the normal case) or in
769 hexadecimal (if the first two characters of the operand are '0x').
770 Note that Jim Tcl does *not* treat numbers with leading zeros as octal.
772 If an operand does not have one of the integer formats given
773 above, then it is treated as a floating-point number if that is
774 possible.  Floating-point numbers may be specified in any of the
775 ways accepted by an ANSI-compliant C compiler (except that the
776 'f', 'F', 'l', and 'L' suffixes will not be permitted in
777 most installations).  For example, all of the
778 following are valid floating-point numbers:  2.1, 3., 6e4, 7.91e+16.
780 If no numeric interpretation is possible, then an operand is left
781 as a string (and only a limited set of operators may be applied to
782 it).
784 String constants representing boolean constants
785 (+'0'+, +'1'+, +'false'+, +'off'+, +'no'+, +'true'+, +'on'+, +'yes'+)
786 are also recognized and can be used in logical operations.
788 1. Operands may be specified in any of the following ways:
790 2. As a numeric value, either integer or floating-point.
792 3. As one of valid boolean constants
794 4. As a Tcl variable, using standard '$' notation.
795 The variable's value will be used as the operand.
797 5. As a string enclosed in double-quotes.
798 The expression parser will perform backslash, variable, and
799 command substitutions on the information between the quotes,
800 and use the resulting value as the operand
802 6. As a string enclosed in braces.
803 The characters between the open brace and matching close brace
804 will be used as the operand without any substitutions.
806 7. As a Tcl command enclosed in brackets.
807 The command will be executed and its result will be used as
808 the operand.
810 Where substitutions occur above (e.g. inside quoted strings), they
811 are performed by the expression processor.
812 However, an additional layer of substitution may already have
813 been performed by the command parser before the expression
814 processor was called.
816 As discussed below, it is usually best to enclose expressions
817 in braces to prevent the command parser from performing substitutions
818 on the contents.
820 For some examples of simple expressions, suppose the variable 'a' has
821 the value 3 and the variable 'b' has the value 6.  Then the expression
822 on the left side of each of the lines below will evaluate to the value
823 on the right side of the line:
825 ----
826     $a + 3.1                6.1
827     2 + "$a.$b"             5.6
828     4*[llength "6 2"]       8
829     {word one} < "word $a"  0
830 ----
832 The valid operators are listed below, grouped in decreasing order
833 of precedence:
834 [[OperatorPrecedence]]
835 +int() double() round() abs(), rand(), srand()+::
836     Unary functions (except rand() which takes no arguments)
837     * +'int()'+ converts the numeric argument to an integer by truncating down.
838     * +'double()'+ converts the numeric argument to floating point.
839     * +'round()'+ converts the numeric argument to the closest integer value.
840     * +'abs()'+ takes the absolute value of the numeric argument.
841     * +'rand()'+ returns a pseudo-random floating-point value in the range (0,1).
842     * +'srand()'+ takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
844 +sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()+::
845     Unary math functions.
846     If Jim is compiled with math support, these functions are available.
848 +- + ~ !+::
849     Unary minus, unary plus, bit-wise NOT, logical NOT.  None of these operands
850     may be applied to string operands, and bit-wise NOT may be
851     applied only to integers.
853 +** pow(x,y)+::
854     Power. e.g. 'x^y^'. If Jim is compiled with math support, supports doubles and
855     integers. Otherwise supports integers only. (Note that the math-function form
856     has the same highest precedence)
858 +* / %+::
859     Multiply, divide, remainder.  None of these operands may be
860     applied to string operands, and remainder may be applied only
861     to integers.
863 ++ -+::
864     Add and subtract.  Valid for any numeric operands.
866 +<<  >> <<< >>>+::
867     Left and right shift, left and right rotate.  Valid for integer operands only.
869 +<  >  \<=  >=+::
870     Boolean less, greater, less than or equal, and greater than or equal.
871     Each operator produces 1 if the condition is true, 0 otherwise.
872     These operators may be applied to strings as well as numeric operands,
873     in which case string comparison is used.
875 +==  !=+::
876     Boolean equal and not equal.  Each operator produces a zero/one result.
877     Valid for all operand types. *Note* that values will be converted to integers
878     if possible, then floating point types, and finally strings will be compared.
879     It is recommended that 'eq' and 'ne' should be used for string comparison.
881 +eq ne+::
882     String equal and not equal.  Uses the string value directly without
883     attempting to convert to a number first.
885 +in ni+::
886     String in list and not in list. For 'in', result is 1 if the left operand (as a string)
887     is contained in the right operand (as a list), or 0 otherwise. The result for
888     +{$a ni $list}+ is equivalent to +{!($a in $list)}+.
890 +&+::
891     Bit-wise AND.  Valid for integer operands only.
893 +|+::
894     Bit-wise OR.  Valid for integer operands only.
896 +^+::
897     Bit-wise exclusive OR.  Valid for integer operands only.
899 +&&+::
900     Logical AND.  Produces a 1 result if both operands are non-zero, 0 otherwise.
901     Valid for numeric operands only (integers or floating-point).
903 +||+::
904     Logical OR.  Produces a 0 result if both operands are zero, 1 otherwise.
905     Valid for numeric operands only (integers or floating-point).
907 +x ? y : z+::
908     If-then-else, as in C.  If +'x'+
909     evaluates to non-zero, then the result is the value of +'y'+.
910     Otherwise the result is the value of +'z'+.
911     The +'x'+ operand must have a numeric value, while +'y'+ and +'z'+ can
912     be of any type.
914 See the C manual for more details on the results
915 produced by each operator.
916 All of the binary operators group left-to-right within the same
917 precedence level.  For example, the expression
919 ----
920     4*2 < 7
921 ----
923 evaluates to 0.
925 The +&&+, +||+, and +?:+ operators have 'lazy evaluation', just as
926 in C, which means that operands are not evaluated if they are not
927 needed to determine the outcome.  For example, in
929 ----
930     $v ? [a] : [b]
931 ----
933 only one of +[a]+ or +[b]+ will actually be evaluated,
934 depending on the value of +$v+.
936 All internal computations involving integers are done with the C
937 type 'long long' if available, or 'long' otherwise, and all internal
938 computations involving floating-point are done with the C type
939 'double'.
941 When converting a string to floating-point, exponent overflow is
942 detected and results in a Tcl error.
943 For conversion to integer from string, detection of overflow depends
944 on the behaviour of some routines in the local C library, so it should
945 be regarded as unreliable.
946 In any case, overflow and underflow are generally not detected
947 reliably for intermediate results.
949 Conversion among internal representations for integer, floating-point,
950 string operands is done automatically as needed.
951 For arithmetic computations, integers are used until some
952 floating-point number is introduced, after which floating-point is used.
953 For example,
955 ----
956     5 / 4
957 ----
959 yields the result 1, while
961 ----
962     5 / 4.0
963     5 / ( [string length "abcd"] + 0.0 )
964 ----
966 both yield the result 1.25.
968 String values may be used as operands of the comparison operators,
969 although the expression evaluator tries to do comparisons as integer
970 or floating-point when it can.
971 If one of the operands of a comparison is a string and the other
972 has a numeric value, the numeric operand is converted back to
973 a string using the C 'sprintf' format specifier
974 '%d' for integers and '%g' for floating-point values.
975 For example, the expressions
977 ----
978     "0x03" > "2"
979     "0y" < "0x12"
980 ----
982 both evaluate to 1.  The first comparison is done using integer
983 comparison, and the second is done using string comparison after
984 the second operand is converted to the string '18'.
986 In general it is safest to enclose an expression in braces when
987 entering it in a command:  otherwise, if the expression contains
988 any white space then the Tcl interpreter will split it
989 among several arguments.  For example, the command
991 ----
992     expr $a + $b
993 ----
995 results in three arguments being passed to `expr`:  +$a+,
996 \+, and +$b+.  In addition, if the expression isn't in braces
997 then the Tcl interpreter will perform variable and command substitution
998 immediately (it will happen in the command parser rather than in
999 the expression parser).  In many cases the expression is being
1000 passed to a command that will evaluate the expression later (or
1001 even many times if, for example, the expression is to be used to
1002 decide when to exit a loop).  Usually the desired goal is to re-do
1003 the variable or command substitutions each time the expression is
1004 evaluated, rather than once and for all at the beginning.  For example,
1005 the command
1007 ----
1008     for {set i 1} $i<=10 {incr i} {...}        ** WRONG **
1009 ----
1011 is probably intended to iterate over all values of +i+ from 1 to 10.
1012 After each iteration of the body of the loop, `for` will pass
1013 its second argument to the expression evaluator to see whether or not
1014 to continue processing.  Unfortunately, in this case the value of +i+
1015 in the second argument will be substituted once and for all when the
1016 `for` command is parsed.  If +i+ was 0 before the `for`
1017 command was invoked then the second argument of `for` will be +0\<=10+
1018 which will always evaluate to 1, even though +i+ eventually
1019 becomes greater than 10.  In the above case the loop will never
1020 terminate.  Instead, the expression should be placed in braces:
1022 ----
1023     for {set i 1} {$i<=10} {incr i} {...}      ** RIGHT **
1024 ----
1026 This causes the substitution of 'i'
1027 to be delayed; it will be re-done each time the expression is
1028 evaluated, which is the desired result.
1030 LISTS
1031 -----
1032 The third major way that strings are interpreted in Tcl is as lists.
1033 A list is just a string with a list-like structure
1034 consisting of fields separated by white space.  For example, the
1035 string
1037 ----
1038     Al Sue Anne John
1039 ----
1041 is a list with four elements or fields.
1042 Lists have the same basic structure as command strings, except
1043 that a newline character in a list is treated as a field separator
1044 just like space or tab.  Conventions for braces and quotes
1045 and backslashes are the same for lists as for commands.  For example,
1046 the string
1048 ----
1049     a b\ c {d e {f g h}}
1050 ----
1052 is a list with three elements:  +a+, +b c+, and +d e {f g h}+.
1054 Whenever an element is extracted from a list, the same rules about
1055 braces and quotes and backslashes are applied as for commands.  Thus in
1056 the example above when the third element is extracted from the list,
1057 the result is
1059 ----
1060     d e {f g h}
1061 ----
1063 (when the field was extracted, all that happened was to strip off
1064 the outermost layer of braces).  Command substitution and
1065 variable substitution are never
1066 made on a list (at least, not by the list-processing commands; the
1067 list can always be passed to the Tcl interpreter for evaluation).
1069 The Tcl commands `concat`, `foreach`, `lappend`, `lindex`, `linsert`,
1070 `list`, `llength`, `lrange`, `lreplace`, `lsearch`, and `lsort` allow
1071 you to build lists, extract elements from them, search them, and perform
1072 other list-related functions.
1074 Advanced list commands include `lrepeat`, `lreverse`, `lmap`, `lassign`, `lset`.
1076 LIST EXPANSION
1077 --------------
1079 A new addition to Tcl 8.5 is the ability to expand a list into separate
1080 arguments. Support for this feature is also available in Jim.
1082 Consider the following attempt to exec a list:
1084 ----
1085     set cmd {ls -l}
1086     exec $cmd
1087 ----
1089 This will attempt to exec a command named "ls -l", which will clearly not
1090 work. Typically eval and concat are required to solve this problem, however
1091 it can be solved much more easily with +\{*\}+.
1093 ----
1094     exec {*}$cmd
1095 ----
1097 This will expand the following argument into individual elements and then evaluate
1098 the resulting command.
1100 Note that the official Tcl syntax is +\{*\}+, however +\{expand\}+ is retained
1101 for backward compatibility with experimental versions of this feature.
1103 REGULAR EXPRESSIONS
1104 -------------------
1105 Tcl provides two commands that support string matching using regular
1106 expressions, `regexp` and `regsub`, as well as `switch -regexp` and
1107 `lsearch -regexp`.
1109 Regular expressions may be implemented one of two ways. Either using the system's C library
1110 POSIX regular expression support, or using the built-in regular expression engine.
1111 The differences between these are described below.
1113 *NOTE* Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (+ARE+).
1115 POSIX Regular Expressions
1116 ~~~~~~~~~~~~~~~~~~~~~~~~~
1117 If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
1118 this support will be used by default. The type of regular expressions supported are
1119 Extended Regular Expressions (+ERE+) rather than Basic Regular Expressions (+BRE+).
1120 See REG_EXTENDED in the documentation.
1122 Using the system-supported POSIX regular expressions will typically
1123 make for the smallest code size, but some features such as UTF-8
1124 and +{backslash}w+, +{backslash}d+, +{backslash}s+ are not supported, and null characters
1125 in strings are not supported.
1127 See regex(3) and regex(7) for full details.
1129 Jim built-in Regular Expressions
1130 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1131 The Jim built-in regular expression engine may be selected with +./configure --with-jim-regexp+
1132 or it will be selected automatically if UTF-8 support is enabled.
1134 This engine supports UTF-8 as well as some +ARE+ features. The differences with both Tcl 7.x/8.x
1135 and POSIX are highlighted below.
1137 1. UTF-8 strings and patterns are both supported
1138 2. All Tcl character classes are supported (e.g. +[:alnum:]+, +[:digit:]+, +[:space:]+), but...
1139 3. Character classes apply to ASCII characters only
1140 4. Supported shorthand character classes: +{backslash}w+ = +[:alnum:]+, +{backslash}W+ = +^[:alnum:]+, +{backslash}d+ = +[:digit:],+ +{backslash}D+ = +^[:digit:],+ +{backslash}s+ = +[:space:]+, + +{backslash}S+ = +^[:space:]+
1141 5. Supported constraint escapes: +{backslash}m+ = +{backslash}<+ = start of word, +{backslash}M+ = +{backslash}>+ = end of word
1142 6. Backslash escapes may be used within regular expressions, such as +{backslash}n+ = newline, +{backslash}uNNNN+ = unicode
1143 7. Partially supported constraint escapes: +{backslash}A+ = start of string, +{backslash}Z+ = end of string
1144 8. Support for the +?+ non-greedy quantifier. e.g. +*?+
1145 9. Support for non-capturing parentheses +(?:...)+
1146 10. Jim Tcl considers that both patterns and strings end at a null character (+\x00+)
1148 COMMAND RESULTS
1149 ---------------
1150 Each command produces two results:  a code and a string.  The
1151 code indicates whether the command completed successfully or not,
1152 and the string gives additional information.  The valid codes are
1153 defined in jim.h, and are:
1155 +JIM_OK(0)+::
1156     This is the normal return code, and indicates that the command completed
1157     successfully.  The string gives the command's return value.
1159 +JIM_ERR(1)+::
1160     Indicates that an error occurred; the string gives a message describing
1161     the error.
1163 +JIM_RETURN(2)+::
1164     Indicates that the `return` command has been invoked, and that the
1165     current procedure (or top-level command or `source` command)
1166     should return immediately.  The
1167     string gives the return value for the procedure or command.
1169 +JIM_BREAK(3)+::
1170     Indicates that the `break` command has been invoked, so the
1171     innermost loop should abort immediately.  The string should always
1172     be empty.
1174 +JIM_CONTINUE(4)+::
1175     Indicates that the `continue` command has been invoked, so the
1176     innermost loop should go on to the next iteration.  The string
1177     should always be empty.
1179 +JIM_SIGNAL(5)+::
1180     Indicates that a signal was caught while executing a commands.
1181     The string contains the name of the signal caught.
1182     See the `signal` and `catch` commands.
1184 +JIM_EXIT(6)+::
1185     Indicates that the command called the `exit` command.
1186     The string contains the exit code.
1188 Tcl programmers do not normally need to think about return codes,
1189 since +JIM_OK+ is almost always returned.  If anything else is returned
1190 by a command, then the Tcl interpreter immediately stops processing
1191 commands and returns to its caller.  If there are several nested
1192 invocations of the Tcl interpreter in progress, then each nested
1193 command will usually return the error to its caller, until eventually
1194 the error is reported to the top-level application code.  The
1195 application will then display the error message for the user.
1197 In a few cases, some commands will handle certain `error` conditions
1198 themselves and not return them upwards.  For example, the `for`
1199 command checks for the +JIM_BREAK+ code; if it occurs, then `for`
1200 stops executing the body of the loop and returns +JIM_OK+ to its
1201 caller.  The `for` command also handles +JIM_CONTINUE+ codes and the
1202 procedure interpreter handles +JIM_RETURN+ codes.  The `catch`
1203 command allows Tcl programs to catch errors and handle them without
1204 aborting command interpretation any further.
1206 The `info returncodes` command may be used to programmatically map between
1207 return codes and names.
1209 PROCEDURES
1210 ----------
1211 Tcl allows you to extend the command interface by defining
1212 procedures.  A Tcl procedure can be invoked just like any other Tcl
1213 command (it has a name and it receives one or more arguments).
1214 The only difference is that its body isn't a piece of C code linked
1215 into the program; it is a string containing one or more other
1216 Tcl commands.
1218 The `proc` command is used to create a new Tcl command procedure:
1220 +*proc* 'name arglist ?statics? body'+
1222 The new command is named +'name'+, and it replaces any existing command
1223 there may have been by that name. Whenever the new command is
1224 invoked, the contents of +'body'+ will be executed by the Tcl
1225 interpreter.
1227 +'arglist'+ specifies the formal arguments to the procedure.
1228 It consists of a list, possibly empty, of the following
1229 argument specifiers:
1231 +name+::
1232     Required Argument - A simple argument name.
1234 +{name default}+::
1235     Optional Argument - A two-element list consisting of the
1236     argument name, followed by the default value, which will
1237     be used if the corresponding argument is not supplied.
1239 +&name+::
1240     Reference Argument - The caller is expected to pass the name of
1241     an existing variable. An implicit +`upvar` 1 origname name+ is done
1242     to make the variable available in the proc scope.
1244 +*args*+::
1245     Variable Argument - The special name +'args'+, which is
1246     assigned all remaining arguments (including none) as a list. The
1247     variable argument may only be specified once. Note that
1248     the syntax +{args newname}+ may be used to retain the special
1249     behaviour of +'args'+ with a different local name. In this case,
1250     the variable is named +'newname'+ rather than +'args'+.
1252 When the command is invoked, a local variable will be created for each of
1253 the formal arguments to the procedure; its value will be the value
1254 of corresponding argument in the invoking command or the argument's
1255 default value.
1257 Arguments with default values need not be specified in a procedure
1258 invocation.  However, there must be enough actual arguments for all
1259 required arguments, and there must not be any extra actual arguments
1260 (unless the Variable Argument is specified).
1262 Actual arguments are assigned to formal arguments as in left-to-right
1263 order with the following precedence.
1265 1. Required Arguments (including Reference Arguments)
1266 2. Optional Arguments
1267 3. Variable Argument
1269 The following example illustrates precedence. Assume a procedure declaration:
1271 ----
1272     proc p {{a A} args b {c C} d} {...}
1273 ----
1275 This procedure requires at least two arguments, but can accept an unlimited number.
1276 The following table shows how various numbers of arguments are assigned.
1277 Values marked as +-+ are assigned the default value.
1279 [width="40%",frame="topbot",options="header"]
1280 |==============
1281 |Number of arguments|a|args|b|c|d
1282 |2|-|-|1|-|2
1283 |3|1|-|2|-|3
1284 |4|1|-|2|3|4
1285 |5|1|2|3|4|5
1286 |6|1|2,3|4|5|6
1287 |==============
1289 When +'body'+ is being executed, variable names normally refer to local
1290 variables, which are created automatically when referenced and deleted
1291 when the procedure returns.  One local variable is automatically created
1292 for each of the procedure's arguments.  Global variables can be
1293 accessed by invoking the `global` command or via the +::+ prefix.
1295 New in Jim
1296 ~~~~~~~~~~
1297 In addition to procedure arguments, Jim procedures may declare static variables.
1298 These variables scoped to the procedure and initialised at procedure definition.
1299 Either from the static variable definition, or from the enclosing scope.
1301 Consider the following example:
1303 ----
1304     . set a 1
1305     . proc a {} {a {b 2}} {
1306         set c 1
1307         puts "$a $b $c"
1308         incr a
1309         incr b
1310         incr c
1311     }
1312     . a
1313     1 2 1
1314     . a
1315     2 3 1
1316 ----
1318 The static variable +'a'+ has no initialiser, so it is initialised from
1319 the enclosing scope with the value 1. (Note that it is an error if there
1320 is no variable with the same name in the enclosing scope). However +'b'+
1321 has an initialiser, so it is initialised to 2.
1323 Unlike a local variable, the value of a static variable is retained across
1324 invocations of the procedure.
1326 See the `proc` command for information on how to define procedures
1327 and what happens when they are invoked. See also <<_namespaces,NAMESPACES>>.
1329 VARIABLES - SCALARS AND ARRAYS
1330 ------------------------------
1331 Tcl allows the definition of variables and the use of their values
1332 either through '$'-style variable substitution, the `set`
1333 command, or a few other mechanisms.
1335 Variables need not be declared:  a new variable will automatically
1336 be created each time a new variable name is used.
1338 Tcl supports two types of variables:  scalars and arrays.
1339 A scalar variable has a single value, whereas an array variable
1340 can have any number of elements, each with a name (called
1341 its 'index') and a value.
1343 Array indexes may be arbitrary strings; they need not be numeric.
1344 Parentheses are used refer to array elements in Tcl commands.
1345 For example, the command
1347 ----
1348     set x(first) 44
1349 ----
1351 will modify the element of 'x' whose index is 'first'
1352 so that its new value is '44'.
1354 Two-dimensional arrays can be simulated in Tcl by using indexes
1355 that contain multiple concatenated values.
1356 For example, the commands
1358 ----
1359     set a(2,3) 1
1360     set a(3,6) 2
1361 ----
1363 set the elements of 'a' whose indexes are '2,3' and '3,6'.
1365 In general, array elements may be used anywhere in Tcl that scalar
1366 variables may be used.
1368 If an array is defined with a particular name, then there may
1369 not be a scalar variable with the same name.
1371 Similarly, if there is a scalar variable with a particular
1372 name then it is not possible to make array references to the
1373 variable.
1375 To convert a scalar variable to an array or vice versa, remove
1376 the existing variable with the `unset` command.
1378 The `array` command provides several features for dealing
1379 with arrays, such as querying the names of all the elements of
1380 the array and converting between an array and a list.
1382 Variables may be either global or local.  If a variable
1383 name is used when a procedure isn't being executed, then it
1384 automatically refers to a global variable.  Variable names used
1385 within a procedure normally refer to local variables associated with that
1386 invocation of the procedure.  Local variables are deleted whenever
1387 a procedure exits.  Either `global` command may be used to request
1388 that a name refer to a global variable for the duration of the current
1389 procedure (this is somewhat analogous to 'extern' in C), or the variable
1390 may be explicitly scoped with the +::+ prefix. For example
1392 ----
1393     . set a 1
1394     . set b 2
1395     . proc p {} {
1396         set c 3
1397         global a
1399         puts "$a $::b $c"
1400     }
1401     . p
1402 ----
1404 will output:
1406     1 2 3
1408 ARRAYS AS LISTS IN JIM
1409 ----------------------
1410 Unlike Tcl, Jim can automatically convert between a list (with an even
1411 number of elements) and an array value. This is similar to the way Tcl
1412 can convert between a string and a list.
1414 For example:
1416 ----
1417   set a {1 one 2 two}
1418   puts $a(2)
1419 ----
1421 will output:
1423 ----
1424   two
1425 ----
1427 Thus `array set` is equivalent to `set` when the variable does not
1428 exist or is empty.
1430 The reverse is also true where an array will be converted into
1431 a list.
1433 ----
1434   set a(1) one; set a(2) two
1435   puts $a
1436 ----
1438 will output:
1440 ----
1441   1 one 2 two
1442 ----
1444 DICTIONARY VALUES
1445 -----------------
1446 Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
1447 of this command. Dictionaries provide efficient access to key-value
1448 pairs, just like arrays, but dictionaries are pure values. This
1449 means that you can pass them to a procedure just as a list or a
1450 string. Tcl dictionaries are therefore much more like Tcl lists,
1451 except that they represent a mapping from keys to values, rather
1452 than an ordered sequence.
1454 You can nest dictionaries, so that the value for a particular key
1455 consists of another dictionary. That way you can elegantly build
1456 complicated data structures, such as hierarchical databases. You
1457 can also combine dictionaries with other Tcl data structures. For
1458 instance, you can build a list of dictionaries that themselves
1459 contain lists.
1461 Dictionaries are values that contain an efficient, order-preserving
1462 mapping from arbitrary keys to arbitrary values. Each key in the
1463 dictionary maps to a single value. They have a textual format that
1464 is exactly that of any list with an even number of elements, with
1465 each mapping in the dictionary being represented as two items in
1466 the list. When a command takes a dictionary and produces a new
1467 dictionary based on it (either returning it or writing it back into
1468 the variable that the starting dictionary was read from) the new
1469 dictionary will have the same order of keys, modulo any deleted
1470 keys and with new keys added on to the end. When a string is
1471 interpreted as a dictionary and it would otherwise have duplicate
1472 keys, only the last value for a particular key is used; the others
1473 are ignored, meaning that, "apple banana" and "apple carrot apple
1474 banana" are equivalent dictionaries (with different string
1475 representations).
1477 Note that in Jim, arrays are implemented as dictionaries.
1478 Thus automatic conversion between lists and dictionaries applies
1479 as it does for arrays.
1481 ----
1482   . dict set a 1 one
1483   1 one
1484   . dict set a 2 two
1485   1 one 2 two
1486   . puts $a
1487   1 one 2 two
1488   . puts $a(2)
1489   two
1490   . dict set a 3 T three
1491   1 one 2 two 3 {T three}
1492 ----
1494 See the `dict` command for more details.
1496 NAMESPACES
1497 ----------
1498 Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
1499 including a number of 3rd party components. While there is less need for namespaces
1500 in Jim Tcl (which does not strive to support large applications), it is convenient to
1501 provide a subset of the support for namespaces to easy porting code from Tcl.
1503 Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
1504 purposes. This feature is currently experimental. See README.namespaces for more information
1505 and the documentation of the `namespace` command.
1507 GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION
1508 -----------------------------------------------
1509 Unlike Tcl, Jim has some sophisticated support for functional programming.
1510 These are described briefly below.
1512 More information may be found at http://wiki.tcl.tk/13847
1514 References
1515 ~~~~~~~~~~
1516 A reference can be thought of as holding a value with one level of indirection,
1517 where the value may be garbage collected when unreferenced.
1518 Consider the following example:
1520 ----
1521     . set r [ref "One String" test]
1522     <reference.<test___>.00000000000000000000>
1523     . getref $r
1524     One String
1525 ----
1527 The operation `ref` creates a references to the value specified by the
1528 first argument. (The second argument is a "type" used for documentation purposes).
1530 The operation `getref` is the dereferencing operation which retrieves the value
1531 stored in the reference.
1533 ----
1534     . setref $r "New String"
1535     New String
1536     . getref $r
1537     New String
1538 ----
1540 The operation `setref` replaces the value stored by the reference. If the old value
1541 is no longer accessible by any reference, it will eventually be automatically be garbage
1542 collected.
1544 Garbage Collection
1545 ~~~~~~~~~~~~~~~~~~
1546 Normally, all values in Tcl are passed by value. As such values are copied and released
1547 automatically as necessary.
1549 With the introduction of references, it is possible to create values whose lifetime
1550 transcend their scope. To support this, case, the Jim system will periodically identify
1551 and discard objects which are no longer accessible by any reference.
1553 The `collect` command may be used to force garbage collection.  Consider a reference created
1554 with a finalizer:
1556 ----
1557     . proc f {ref value} { puts "Finaliser called for $ref,$value" }
1558     . set r [ref "One String" test f]
1559     <reference.<test___>.00000000000
1560     . collect
1561     0
1562     . set r ""
1563     . collect
1564     Finaliser called for <reference.<test___>.00000000000,One String
1565     1
1566 ----
1568 Note that once the reference, 'r', was modified so that it no longer
1569 contained a reference to the value, the garbage collector discarded
1570 the value (after calling the finalizer).
1572 The finalizer for a reference may be examined or changed with the `finalize` command
1574 ----
1575     . finalize $r
1576     f
1577     . finalize $r newf
1578     newf
1579 ----
1581 Lambda Function
1582 ~~~~~~~~~~~~~~~
1583 Jim provides a garbage collected `lambda` function. This is a procedure
1584 which is able to create an anonymous procedure.  Consider:
1586 ----
1587     . set f [lambda {a} {{x 0}} { incr x $a }]
1588     . $f 1
1589     1
1590     . $f 2
1591     3
1592     . set f ""
1593 ----
1595 This create an anonymous procedure (with the name stored in 'f'), with a static variable
1596 which is incremented by the supplied value and the result returned.
1598 Once the procedure name is no longer accessible, it will automatically be deleted
1599 when the garbage collector runs.
1601 The procedure may also be delete immediately by renaming it "". e.g.
1603 ----
1604     . rename $f ""
1605 ----
1607 UTF-8 AND UNICODE
1608 -----------------
1609 If Jim is built with UTF-8 support enabled (configure --enable-utf),
1610 then most string-related commands become UTF-8 aware.  These include,
1611 but are not limited to, `string match`, `split`, `glob`, `scan` and
1612 `format`.
1614 UTF-8 encoding has many advantages, but one of the complications is that
1615 characters can take a variable number of bytes. Thus the addition of
1616 `string bytelength` which returns the number of bytes in a string,
1617 while `string length` returns the number of characters.
1619 If UTF-8 support is not enabled, all commands treat bytes as characters
1620 and `string bytelength` returns the same value as `string length`.
1622 Note that even if UTF-8 support is not enabled, the +{backslash}uNNNN+ and related syntax
1623 is still available to embed UTF-8 sequences.
1625 Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +'U+1FFFFF'.
1627 String Matching
1628 ~~~~~~~~~~~~~~~
1629 Commands such as `string match`, `lsearch -glob`, `array names` and others use string
1630 pattern matching rules. These commands support UTF-8. For example:
1632 ----
1633   string match a\[\ua0-\ubf\]b "a\u00a3b"
1634 ----
1636 format and scan
1637 ~~~~~~~~~~~~~~~
1638 +format %c+ allows a unicode codepoint to be be encoded. For example, the following will return
1639 a string with two bytes and one character. The same as +{backslash}ub5+
1641 ----
1642   format %c 0xb5
1643 ----
1645 `format` respects widths as character widths, not byte widths. For example, the following will
1646 return a string with three characters, not three bytes.
1648 ----
1649   format %.3s \ub5\ub6\ub7\ub8
1650 ----
1652 Similarly, +scan ... %c+ allows a UTF-8 to be decoded to a unicode codepoint. The following will set
1653 +'a'+ to 181 (0xb5) and +'b'+ to 65 (0x41).
1655 ----
1656   scan \u00b5A %c%c a b
1657 ----
1659 `scan %s` will also accept a character class, including unicode ranges.
1661 String Classes
1662 ~~~~~~~~~~~~~~
1663 `string is` has *not* been extended to classify UTF-8 characters. Therefore, the following
1664 will return 0, even though the string may be considered to be alphabetic.
1666 ----
1667   string is alpha \ub5Test
1668 ----
1670 This does not affect the string classes 'ascii', 'control', 'digit', 'double', 'integer' or 'xdigit'.
1672 Case Mapping and Conversion
1673 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1674 Jim provides a simplified unicode case mapping. This means that case conversion
1675 and comparison will not increase or decrease the number of characters in a string.
1676 (Although it may change the number of bytes).
1678 `string toupper` will convert any lowercase letters to their uppercase equivalent.
1679 Any character which is not a letter or has no uppercase equivalent is left unchanged.
1680 Similarly for `string tolower` and `string totitle`.
1682 Commands which perform case insensitive matches, such as `string compare -nocase`
1683 and `lsearch -nocase` fold both strings to uppercase before comparison.
1685 Invalid UTF-8 Sequences
1686 ~~~~~~~~~~~~~~~~~~~~~~~
1687 Some UTF-8 character sequences are invalid, such as those beginning with '0xff',
1688 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
1689 and those which end prematurely, such as a lone '0xc2'.
1691 In these situations, the offending bytes are treated as single characters. For example,
1692 the following returns 2.
1694 ----
1695   string bytelength \xff\xff
1696 ----
1698 Regular Expressions
1699 ~~~~~~~~~~~~~~~~~~~
1700 If UTF-8 support is enabled, the built-in regular expression engine will be
1701 selected which supports UTF-8 strings and patterns.
1703 See <<_regular_expressions,REGULAR EXPRESSIONS>>
1705 BUILT-IN COMMANDS
1706 -----------------
1707 The Tcl library provides the following built-in commands, which will
1708 be available in any application using Tcl.  In addition to these
1709 built-in commands, there may be additional commands defined by each
1710 application, plus commands defined as Tcl procedures.
1712 In the command syntax descriptions below, words in +*boldface*+ are
1713 literals that you type verbatim to Tcl.
1715 Words in +'italics'+ are meta-symbols; they serve as names for any of
1716 a range of values that you can type.
1718 Optional arguments or groups of arguments are indicated by enclosing them
1719 in +?question-marks?+.
1721 Ellipses (+\...+) indicate that any number of additional
1722 arguments or groups of arguments may appear, in the same format
1723 as the preceding argument(s).
1725 [[CommandIndex]]
1726 Command Index
1727 ~~~~~~~~~~~~~
1728 @INSERTINDEX@
1730 alarm
1731 ~~~~~
1732 +*alarm* 'seconds'+
1734 Delivers the +SIGALRM+ signal to the process after the given
1735 number of seconds. If the platform supports 'ualarm(3)' then
1736 the argument may be a floating point value. Otherwise it must
1737 be an integer.
1739 Note that unless a signal handler for +SIGALRM+ has been installed
1740 (see `signal`), the process will exit on this signal.
1742 alias
1743 ~~~~~
1744 +*alias* 'name args\...'+
1746 Creates a single word alias (command) for one or more words. For example,
1747 the following creates an alias for the command `info exists`.
1749 ----
1750     alias e info exists
1751     if {[e var]} {
1752       ...
1753     }
1754 ----
1756 `alias` returns +'name'+, allowing it to be used with `local`.
1758 See also `proc`, `curry`, `lambda`, `local`, `info alias`, `exists -alias`
1760 append
1761 ~~~~~~
1762 +*append* 'varName value ?value value ...?'+
1764 Append all of the +'value'+ arguments to the current value
1765 of variable +'varName'+.  If +'varName'+ doesn't exist,
1766 it is given a value equal to the concatenation of all the
1767 +'value'+ arguments.
1769 This command provides an efficient way to build up long
1770 variables incrementally.
1771 For example, "`append a $b`" is much more efficient than
1772 "`set a $a$b`" if +$a+ is long.
1774 apply
1775 ~~~~~~
1776 +*apply* 'lambdaExpr ?arg1 arg2 \...?'+
1778 The command `apply` provides for anonymous procedure calls,
1779 similar to `lambda`, but without command name being created, even temporarily.
1781 The function  +'lambdaExpr'+ is a two element list +{args body}+
1782 or a three element list +{args body namespace}+. The first element
1783 args specifies the formal arguments, in the same form as the `proc` and `lambda` commands.
1785 array
1786 ~~~~~
1787 +*array* 'option arrayName ?arg\...?'+
1789 This command performs one of several operations on the
1790 variable given by +'arrayName'+.
1792 Note that in general, if the named array does not exist, the +'array'+ command behaves
1793 as though the array exists but is empty.
1795 The +'option'+ argument determines what action is carried out by the
1796 command.  The legal +'options'+ (which may be abbreviated) are:
1798 +*array exists* 'arrayName'+::
1799     Returns 1 if arrayName is an array variable, 0 if there is
1800     no variable by that name.
1802 +*array get* 'arrayName ?pattern?'+::
1803     Returns a list containing pairs of elements. The first
1804     element in each pair is the name of an element in arrayName
1805     and the second element of each pair is the value of the
1806     array element. The order of the pairs is undefined. If
1807     pattern is not specified, then all of the elements of the
1808     array are included in the result. If pattern is specified,
1809     then only those elements whose names match pattern (using
1810     the matching rules of string match) are included. If arrayName
1811     isn't the name of an array variable, or if the array contains
1812     no elements, then an empty list is returned.
1814 +*array names* 'arrayName ?pattern?'+::
1815     Returns a list containing the names of all of the elements
1816     in the array that match pattern. If pattern is omitted then
1817     the command returns all of the element names in the array.
1818     If pattern is specified, then only those elements whose
1819     names match pattern (using the matching rules of string
1820     match) are included. If there are no (matching) elements
1821     in the array, or if arrayName isn't the name of an array
1822     variable, then an empty string is returned.
1824 +*array set* 'arrayName list'+::
1825     Sets the values of one or more elements in arrayName. list
1826     must have a form like that returned by array get, consisting
1827     of an even number of elements. Each odd-numbered element
1828     in list is treated as an element name within arrayName, and
1829     the following element in list is used as a new value for
1830     that array element. If the variable arrayName does not
1831     already exist and list is empty, arrayName is created with
1832     an empty array value.
1834 +*array size* 'arrayName'+::
1835     Returns the number of elements in the array. If arrayName
1836     isn't the name of an array then 0 is returned.
1838 +*array unset* 'arrayName ?pattern?'+::
1839     Unsets all of the elements in the array that match pattern
1840     (using the matching rules of string match). If arrayName
1841     isn't the name of an array variable or there are no matching
1842     elements in the array, no error will be raised. If pattern
1843     is omitted and arrayName is an array variable, then the
1844     command unsets the entire array. The command always returns
1845     an empty string.
1847 break
1848 ~~~~~
1849 +*break*+
1851 This command may be invoked only inside the body of a loop command
1852 such as `for` or `foreach` or `while`.  It returns a +JIM_BREAK+ code
1853 to signal the innermost containing loop command to return immediately.
1855 case
1856 ~~~~
1857 The obsolete '+*case*+' command has been removed from Jim Tcl since v0.75.
1858 Use `switch` instead.
1860 catch
1861 ~~~~~
1862 +*catch* ?-?no?'code \...'? ?--? 'command ?resultVarName? ?optionsVarName?'+
1864 The `catch` command may be used to prevent errors from aborting
1865 command interpretation.  `catch` evaluates +'command'+, and returns a
1866 +JIM_OK+ code, regardless of any errors that might occur while
1867 executing +'command'+ (with the possible exception of +JIM_SIGNAL+ -
1868 see below).
1870 The return value from `catch` is a decimal string giving the code
1871 returned by the Tcl interpreter after executing +'command'+.  This
1872 will be '0' (+JIM_OK+) if there were no errors in +'command'+; otherwise
1873 it will have a non-zero value corresponding to one of the exceptional
1874 return codes (see jim.h for the definitions of code values, or the
1875 `info returncodes` command).
1877 If the +'resultVarName'+ argument is given, then it gives the name
1878 of a variable; `catch` will set the value of the variable to the
1879 string returned from +'command'+ (either a result or an error message).
1881 If the +'optionsVarName'+ argument is given, then it gives the name
1882 of a variable; `catch` will set the value of the variable to a
1883 dictionary. For any return code other than +JIM_RETURN+, the value
1884 for the key +-code+ will be set to the return code. For +JIM_RETURN+
1885 it will be set to the code given in `return -code`. Additionally,
1886 for the return code +JIM_ERR+, the value of the key +-errorinfo+
1887 will contain the current stack trace (the same result as `info stacktrace`),
1888 the value of the key +-errorcode+ will contain the
1889 same value as the global variable $::errorCode, and the value of
1890 the key +-level+ will be the current return level (see `return -level`).
1891 This can be useful to rethrow an error:
1893 ----
1894     if {[catch {...} msg opts]} {
1895         ...maybe do something with the error...
1896         incr opts(-level)
1897         return {*}$opts $msg
1898     }
1899 ----
1901 Normally `catch` will +'not'+ catch any of the codes +JIM_EXIT+, +JIM_EVAL+ or +JIM_SIGNAL+.
1902 The set of codes which will be caught may be modified by specifying the one more codes before
1903 +'command'+.
1905 e.g. To catch +JIM_EXIT+ but not +JIM_BREAK+ or +JIM_CONTINUE+
1907 ----
1908     catch -exit -nobreak -nocontinue -- { ... }
1909 ----
1911 The use of +--+ is optional. It signifies that no more return code options follow.
1913 Note that if a signal marked as `signal handle` is caught with `catch -signal`, the return value
1914 (stored in +'resultVarName'+) is name of the signal caught.
1918 +*cd* 'dirName'+
1920 Change the current working directory to +'dirName'+.
1922 Returns an empty string.
1924 This command can potentially be disruptive to an application, so it may
1925 be removed in some applications.
1927 clock
1928 ~~~~~
1929 +*clock seconds*+::
1930     Returns the current time as seconds since the epoch.
1932 +*clock clicks*+::
1933     Returns the current time in "clicks", a system-dependent, high-resolution time.
1935 +*clock microseconds*+::
1936     Returns the current time in microseconds.
1938 +*clock milliseconds*+::
1939     Returns the current time in milliseconds.
1941 +*clock format* 'seconds' ?*-format* 'format?' ?*-gmt* 'boolean?'+::
1942     Format the given time (seconds since the epoch) according to the given
1943     format. See strftime(3) for supported formats.
1944     If no format is supplied, "%c" is used.
1945   ::
1946     If +'boolean'+ is true, processing is performed in UTC.
1947     If +'boolean'+ is false (the default), processing  is performeed in the local time zone.
1949 +*clock scan* 'str' *-format* 'format' ?*-gmt* 'boolean?'+::
1950     Scan the given time string using the given format string.
1951     See strptime(3) for supported formats.
1952     See `clock format` for the handling of '-gmt'.
1954 close
1955 ~~~~~
1956 +*close* 'fileId'+
1958 +'fileId' *close*+
1960 Closes the file given by +'fileId'+.
1961 +'fileId'+ must be the return value from a previous invocation
1962 of the `open` command; after this command, it should not be
1963 used anymore.
1965 collect
1966 ~~~~~~~
1967 +*collect*+
1969 Normally reference garbage collection is automatically performed periodically.
1970 However it may be run immediately with the `collect` command.
1972 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
1974 concat
1975 ~~~~~~
1976 +*concat* 'arg ?arg \...?'+
1978 This command treats each argument as a list and concatenates them
1979 into a single list.  It permits any number of arguments.  For example,
1980 the command
1982 ----
1983     concat a b {c d e} {f {g h}}
1984 ----
1986 will return
1988 ----
1989     a b c d e f {g h}
1990 ----
1992 as its result.
1994 continue
1995 ~~~~~~~~
1996 +*continue*+
1998 This command may be invoked only inside the body of a loop command such
1999 as `for` or `foreach` or `while`.  It returns a  +JIM_CONTINUE+ code to
2000 signal the innermost containing loop command to skip the remainder of
2001 the loop's body but continue with the next iteration of the loop.
2003 curry
2004 ~~~~~
2005 +*alias* 'args\...'+
2007 Similar to `alias` except it creates an anonymous procedure (lambda) instead of
2008 a named procedure.
2010 the following creates a local, unnamed alias for the command `info exists`.
2012 ----
2013     set e [local curry info exists]
2014     if {[$e var]} {
2015       ...
2016     }
2017 ----
2019 `curry` returns the name of the procedure.
2021 See also `proc`, `alias`, `lambda`, `local`.
2023 dict
2024 ~~~~
2025 +*dict* 'option ?arg\...?'+
2027 Performs one of several operations on dictionary values.
2029 The +'option'+ argument determines what action is carried out by the
2030 command.  The legal +'options'+ are:
2032 +*dict create* '?key value \...?'+::
2033     Create and return a new dictionary value that contains each of
2034     the key/value mappings listed as  arguments (keys and values
2035     alternating, with each key being followed by its associated
2036     value.)
2038 +*dict exists* 'dictionary key ?key \...?'+::
2039     Returns a boolean value indicating whether the given key (or path
2040     of keys through a set of nested dictionaries) exists in the given
2041     dictionary value.  This returns a true value exactly when `dict get`
2042     on that path will succeed.
2044 +*dict get* 'dictionary ?key \...?'+::
2045     Given a dictionary value (first argument) and a key (second argument),
2046     this will retrieve the value for that key. Where several keys are
2047     supplied, the behaviour of the command shall be as if the result
2048     of "`dict get $dictVal $key`" was passed as the first argument to
2049     dict get with the remaining arguments as second (and possibly
2050     subsequent) arguments. This facilitates lookups in nested dictionaries.
2051     If no keys are provided, dict would return a list containing pairs
2052     of elements in a manner similar to array get. That is, the first
2053     element of each pair would be the key and the second element would
2054     be the value for that key.  It is an error to attempt to retrieve
2055     a value for a key that is not present in the dictionary.
2057 +*dict keys* 'dictionary ?pattern?'+::
2058     Returns a list of the keys in the dictionary.
2059     If pattern is specified, then only those keys whose
2060     names match +'pattern'+ (using the matching rules of string
2061     match) are included.
2063 +*dict merge* ?'dictionary \...'?+::
2064     Return a dictionary that contains the contents of each of the
2065     +'dictionary'+ arguments. Where two (or more) dictionaries
2066     contain a mapping for the same key, the resulting dictionary
2067     maps that key to the value according to the last dictionary on
2068     the command line containing a mapping for that key.
2070 +*dict set* 'dictionaryName key ?key \...? value'+::
2071     This operation takes the +'name'+ of a variable containing a dictionary
2072     value and places an updated dictionary value in that variable
2073     containing a mapping from the given key to the given value. When
2074     multiple keys are present, this operation creates or updates a chain
2075     of nested dictionaries.
2077 +*dict size* 'dictionary'+::
2078     Return the number of key/value mappings in the given dictionary value.
2080 +*dict unset* 'dictionaryName key ?key \...? value'+::
2081     This operation (the companion to `dict set`) takes the name of a
2082     variable containing a dictionary value and places an updated
2083     dictionary value in that variable that does not contain a mapping
2084     for the given key. Where multiple keys are present, this describes
2085     a path through nested dictionaries to the mapping to remove. At
2086     least one key must be specified, but the last key on the key-path
2087     need not exist. All other components on the path must exist.
2089 +*dict with* 'dictionaryName key ?key \...? script'+::
2090     Execute the Tcl script in +'script'+ with the value for each
2091     key in +'dictionaryName'+ mapped to a variable with the same
2092     name. Where one or more keys are given, these indicate a chain
2093     of nested dictionaries, with the innermost dictionary being the
2094     one opened out for the execution of body. Making +'dictionaryName'+
2095     unreadable will make the updates to the dictionary be discarded,
2096     and this also happens if the contents of +'dictionaryName'+ are
2097     adjusted so that the chain of dictionaries no longer exists.
2098     The result of `dict with` is (unless some kind of error occurs)
2099     the result of the evaluation of body.
2100  ::
2101     The variables are mapped in the scope enclosing the `dict with`;
2102     it is recommended that this command only be used in a local
2103     scope (procedure). Because of this, the variables set by
2104     `dict with` will continue to exist after the command finishes (unless
2105     explicitly unset). Note that changes to the contents of +'dictionaryName'+
2106     only happen when +'script'+ terminates.
2108 +*dict for, values, incr, append, lappend, update, info, replace*+ to be documented...
2112 +*env* '?name? ?default?'+
2114 If +'name'+ is supplied, returns the value of +'name'+ from the initial
2115 environment (see getenv(3)). An error is returned if +'name'+ does not
2116 exist in the environment, unless +'default'+ is supplied - in which case
2117 that value is returned instead.
2119 If no arguments are supplied, returns a list of all environment variables
2120 and their values as +{name value \...}+
2122 See also the global variable +::env+
2126 +*eof* 'fileId'+
2128 +'fileId' *eof*+
2130 Returns 1 if an end-of-file condition has occurred on +'fileId'+,
2131 0 otherwise.
2133 +'fileId'+ must have been the return value from a previous call to `open`,
2134 or it may be +stdin+, +stdout+, or +stderr+ to refer to one of the
2135 standard I/O channels.
2137 error
2138 ~~~~~
2139 +*error* 'message ?stacktrace?'+
2141 Returns a +JIM_ERR+ code, which causes command interpretation to be
2142 unwound.  +'message'+ is a string that is returned to the application
2143 to indicate what went wrong.
2145 If the +'stacktrace'+ argument is provided and is non-empty,
2146 it is used to initialize the stacktrace.
2148 This feature is most useful in conjunction with the `catch` command:
2149 if a caught error cannot be handled successfully, +'stacktrace'+ can be used
2150 to return a stack trace reflecting the original point of occurrence
2151 of the error:
2153 ----
2154     catch {...} errMsg
2155     ...
2156     error $errMsg [info stacktrace]
2157 ----
2159 See also `errorInfo`, `info stacktrace`, `catch` and `return`
2161 errorInfo
2162 ~~~~~~~~~
2163 +*errorInfo* 'error ?stacktrace?'+
2165 Returns a human-readable representation of the given error message and stack trace.
2166 Typical usage is:
2168 ----
2169     if {[catch {...} error]} {
2170         puts stderr [errorInfo $error [info stacktrace]]
2171         exit 1
2172     }
2173 ----
2175 See also `error`.
2177 eval
2178 ~~~~
2179 +*eval* 'arg ?arg\...?'+
2181 `eval` takes one or more arguments, which together comprise a Tcl
2182 command (or collection of Tcl commands separated by newlines in the
2183 usual way).  `eval` concatenates all its arguments in the same
2184 fashion as the `concat` command, passes the concatenated string to the
2185 Tcl interpreter recursively, and returns the result of that
2186 evaluation (or any error generated by it).
2188 exec
2189 ~~~~
2190 +*exec* 'arg ?arg\...?'+
2192 This command treats its arguments as the specification
2193 of one or more UNIX commands to execute as subprocesses.
2194 The commands take the form of a standard shell pipeline;
2195 +|+ arguments separate commands in the
2196 pipeline and cause standard output of the preceding command
2197 to be piped into standard input of the next command (or +|&+ for
2198 both standard output and standard error).
2200 Under normal conditions the result of the `exec` command
2201 consists of the standard output produced by the last command
2202 in the pipeline followed by the standard error output.
2204 If any of the commands writes to its standard error file,
2205 then this will be included in the result after the standard output
2206 of the last command.
2208 Note that unlike Tcl, data written to standard error does not cause
2209 `exec` to return an error.
2211 If any of the commands in the pipeline exit abnormally or
2212 are killed or suspended, then `exec` will return an error.
2213 If no standard error output was produced, or is redirected,
2214 the error message will include the normal result, as above,
2215 followed by error messages describing the abnormal terminations.
2217 If any standard error output was produced, these abnormal termination
2218 messages are suppressed.
2220 If the last character of the result or error message
2221 is a newline then that character is deleted from the result
2222 or error message for consistency with normal
2223 Tcl return values.
2225 An +'arg'+ may have one of the following special forms:
2227 +>filename+::
2228     The standard output of the last command in the pipeline
2229     is redirected to the file.  In this situation `exec`
2230     will normally return an empty string.
2232 +>>filename+::
2233     As above, but append to the file.
2235 +>@fileId+::
2236     The standard output of the last command in the pipeline is
2237     redirected to the given (writable) file descriptor (e.g. stdout,
2238     stderr, or the result of `open`). In this situation `exec`
2239     will normally return an empty string.
2241 +2>filename+::
2242     The standard error of the last command in the pipeline
2243     is redirected to the file.
2245 +2>>filename+::
2246     As above, but append to the file.
2248 +2>@fileId+::
2249     The standard error of the last command in the pipeline is
2250     redirected to the given (writable) file descriptor.
2252 +2>@1+::
2253     The standard error of the last command in the pipeline is
2254     redirected to the same file descriptor as the standard output.
2256 +>&filename+::
2257     Both the standard output and standard error of the last command
2258     in the pipeline is redirected to the file.
2260 +>>&filename+::
2261     As above, but append to the file.
2263 +<filename+::
2264     The standard input of the first command in the pipeline
2265     is taken from the file.
2267 +<<string+::
2268     The standard input of the first command is taken as the
2269     given immediate value.
2271 +<@fileId+::
2272     The standard input of the first command in the pipeline
2273     is taken from the given (readable) file descriptor.
2275 If there is no redirection of standard input, standard error
2276 or standard output, these are connected to the corresponding
2277 input or output of the application.
2279 If the last +'arg'+ is +&+ then the command will be
2280 executed in background.
2281 In this case the standard output from the last command
2282 in the pipeline will
2283 go to the application's standard output unless
2284 redirected in the command, and error output from all
2285 the commands in the pipeline will go to the application's
2286 standard error file. The return value of exec in this case
2287 is a list of process ids (pids) in the pipeline.
2289 Each +'arg'+ becomes one word for a command, except for
2290 +|+, +<+, +<<+, +>+, and +&+ arguments, and the
2291 arguments that follow +<+, +<<+, and +>+.
2293 The first word in each command is taken as the command name;
2294 the directories in the PATH environment variable are searched for
2295 an executable by the given name.
2297 No `glob` expansion or other shell-like substitutions
2298 are performed on the arguments to commands.
2300 If the command fails, the global $::errorCode (and the -errorcode
2301 option in `catch`) will be set to a list, as follows:
2303 +*CHILDKILLED* 'pid sigName msg'+::
2304         This format is used when a child process has been killed
2305         because of a signal. The pid element will be the process's
2306         identifier (in decimal). The sigName element will be the
2307         symbolic name of the signal that caused the process to
2308         terminate; it will be one of the names from the include
2309         file signal.h, such as SIGPIPE. The msg element will be a
2310         short human-readable message describing the signal, such
2311         as "write on pipe with no readers" for SIGPIPE.
2313 +*CHILDSUSP* 'pid sigName msg'+::
2314         This format is used when a child process has been suspended
2315         because of a signal. The pid element will be the process's
2316         identifier, in decimal. The sigName element will be the
2317         symbolic name of the signal that caused the process to
2318         suspend; this will be one of the names from the include
2319         file signal.h, such as SIGTTIN. The msg element will be a
2320         short human-readable message describing the signal, such
2321         as "background tty read" for SIGTTIN.
2323 +*CHILDSTATUS* 'pid code'+::
2324         This format is used when a child process has exited with a
2325         non-zero exit status. The pid element will be the process's
2326         identifier (in decimal) and the code element will be the
2327         exit code returned by the process (also in decimal).
2329 The environment for the executed command is set from $::env (unless
2330 this variable is unset, in which case the original environment is used).
2332 exists
2333 ~~~~~~
2334 +*exists ?-var|-proc|-command|-alias?* 'name'+
2336 Checks the existence of the given variable, procedure, command
2337 or alias respectively and returns 1 if it exists or 0 if not.  This command
2338 provides a more simplified/convenient version of `info exists`,
2339 `info procs` and `info commands`.
2341 If the type is omitted, a type of '-var' is used. The type may be abbreviated.
2343 exit
2344 ~~~~
2345 +*exit* '?returnCode?'+
2347 Terminate the process, returning +'returnCode'+ to the
2348 parent as the exit status.
2350 If +'returnCode'+ isn't specified then it defaults
2351 to 0.
2353 Note that exit can be caught with `catch`.
2355 expr
2356 ~~~~
2357 +*expr* 'arg'+
2359 Calls the expression processor to evaluate +'arg'+, and returns
2360 the result as a string.  See the section <<_expressions,EXPRESSIONS>> above.
2362 Note that Jim supports a shorthand syntax for `expr` as +$(\...)+
2363 The following two are identical.
2365 ----
2366   set x [expr {3 * 2 + 1}]
2367   set x $(3 * 2 + 1)
2368 ----
2370 file
2371 ~~~~
2372 +*file* 'option name ?arg\...?'+
2374 Operate on a file or a file name.  +'name'+ is the name of a file.
2376 +'option'+ indicates what to do with the file name.  Any unique
2377 abbreviation for +'option'+ is acceptable.  The valid options are:
2379 +*file atime* 'name'+::
2380     Return a decimal string giving the time at which file +'name'+
2381     was last accessed.  The time is measured in the standard UNIX
2382     fashion as seconds from a fixed starting time (often January 1, 1970).
2383     If the file doesn't exist or its access time cannot be queried then an
2384     error is generated.
2386 +*file copy ?-force?* 'source target'+::
2387     Copies file +'source'+ to file +'target'+. The source file must exist.
2388     The target file must not exist, unless +-force+ is specified.
2390 +*file delete ?-force? ?--?* 'name\...'+::
2391     Deletes file or directory +'name'+. If the file or directory doesn't exist, nothing happens.
2392     If it can't be deleted, an error is generated. Non-empty directories will not be deleted
2393     unless the +-force+ options is given. In this case no errors will be generated, even
2394     if the file/directory can't be deleted. Use +'--'+ if there is any possibility of
2395     the first name being +'-force'+.
2397 +*file dirname* 'name'+::
2398     Return all of the characters in +'name'+ up to but not including
2399     the last slash character.  If there are no slashes in +'name'+
2400     then return +.+ (a single dot).  If the last slash in +'name'+ is its first
2401     character, then return +/+.
2403 +*file executable* 'name'+::
2404     Return '1' if file +'name'+ is executable by
2405     the current user, '0' otherwise.
2407 +*file exists* 'name'+::
2408     Return '1' if file +'name'+ exists and the current user has
2409     search privileges for the directories leading to it, '0' otherwise.
2411 +*file extension* 'name'+::
2412     Return all of the characters in +'name'+ after and including the
2413     last dot in +'name'+.  If there is no dot in +'name'+ then return
2414     the empty string.
2416 +*file isdirectory* 'name'+::
2417     Return '1' if file +'name'+ is a directory,
2418     '0' otherwise.
2420 +*file isfile* 'name'+::
2421     Return '1' if file +'name'+ is a regular file,
2422     '0' otherwise.
2424 +*file join* 'arg\...'+::
2425     Joins multiple path components. Note that if any components is
2426     an absolute path, the preceding components are ignored.
2427     Thus +"`file` join /tmp /root"+ returns +"/root"+.
2429 +*file link* ?*-hard|-symbolic*? 'newname target'+::
2430     Creates a hard link (default) or symbolic link from +'newname'+ to +'target'+.
2431     Note that the sense of this command is the opposite of `file rename` and `file copy`
2432     and also of `ln`, but this is compatible with Tcl.
2433     An error is returned if +'target'+ doesn't exist or +'newname'+ already exists.
2435 +*file lstat* 'name varName'+::
2436     Same as 'stat' option (see below) except uses the +'lstat'+
2437     kernel call instead of +'stat'+.  This means that if +'name'+
2438     refers to a symbolic link the information returned in +'varName'+
2439     is for the link rather than the file it refers to.  On systems that
2440     don't support symbolic links this option behaves exactly the same
2441     as the 'stat' option.
2443 +*file mkdir* 'dir1 ?dir2\...?'+::
2444     Creates each directory specified. For each pathname +'dir'+ specified,
2445     this command will create all non-existing parent directories
2446     as well as +'dir'+ itself. If an existing directory is specified,
2447     then no action is taken and no error is returned. Trying to
2448     overwrite an existing file with a directory will result in an
2449     error.  Arguments are processed in the order specified, halting
2450     at the first error, if any.
2452 +*file mtime* 'name ?time?'+::
2453     Return a decimal string giving the time at which file +'name'+
2454     was last modified.  The time is measured in the standard UNIX
2455     fashion as seconds from a fixed starting time (often January 1, 1970).
2456     If the file doesn't exist or its modified time cannot be queried then an
2457     error is generated. If +'time'+ is given, sets the modification time
2458     of the file to the given value.
2460 +*file mtimeus* 'name ?time_us?'+::
2461     As for `file mtime` except the time value is in microseconds
2462     since the epoch (see also `clock microseconds`).
2463     Note that some platforms and some filesystems don't support high
2464     resolution timestamps for files.
2466 +*file normalize* 'name'+::
2467     Return the normalized path of +'name'+. See 'realpath(3)'.
2469 +*file owned* 'name'+::
2470     Return '1' if file +'name'+ is owned by the current user,
2471     '0' otherwise.
2473 +*file readable* 'name'+::
2474     Return '1' if file +'name'+ is readable by
2475     the current user, '0' otherwise.
2477 +*file readlink* 'name'+::
2478     Returns the value of the symbolic link given by +'name'+ (i.e. the
2479     name of the file it points to).  If
2480     +'name'+ isn't a symbolic link or its value cannot be read, then
2481     an error is returned.  On systems that don't support symbolic links
2482     this option is undefined.
2484 +*file rename* ?*-force*? 'oldname' 'newname'+::
2485     Renames the file from the old name to the new name.
2486     If +'newname'+ already exists, an error is returned unless +'-force'+ is
2487     specified.
2489 +*file rootname* 'name'+::
2490     Return all of the characters in +'name'+ up to but not including
2491     the last '.' character in the name.  If +'name'+ doesn't contain
2492     a dot, then return +'name'+.
2494 +*file split* 'name'+::
2495     Returns a list whose elements are the path components in +'name'+.
2496     The first element of the list will have the same path type as
2497     +'name'+. All other elements will be relative. Path separators
2498     will be discarded.
2500 +*file stat* 'name ?varName?'+::
2501     Invoke the 'stat' kernel call on +'name'+, and return the result
2502     as a dictionary with the following keys: 'atime',
2503     'ctime', 'dev', 'gid', 'ino', 'mode', 'mtime',
2504     'nlink', 'size', 'type', 'uid', 'mtimeus' (if supported - see `file mtimeus`)
2505     Each element except 'type' is a decimal string with the value of
2506     the corresponding field from the 'stat' return structure; see the
2507     manual entry for 'stat' for details on the meanings of the values.
2508     The 'type' element gives the type of the file in the same form
2509     returned by the command `file type`.
2510     If +'varName'+ is specified, it is taken to be the name of an array
2511     variable and the values are also stored into the array.
2513 +*file tail* 'name'+::
2514     Return all of the characters in +'name'+ after the last slash.
2515     If +'name'+ contains no slashes then return +'name'+.
2517 +*file tempfile* '?template?'+::
2518     Creates and returns the name of a unique temporary file. If +'template'+ is omitted, a
2519     default template will be used to place the file in /tmp. See 'mkstemp(3)' for
2520     the format of the template and security concerns.
2522 +*file type* 'name'+::
2523     Returns a string giving the type of file +'name'+, which will be
2524     one of +file+, +directory+, +characterSpecial+,
2525     +blockSpecial+, +fifo+, +link+, or +socket+.
2527 +*file writable* 'name'+::
2528     Return '1' if file +'name'+ is writable by
2529     the current user, '0' otherwise.
2531 The `file` commands that return 0/1 results are often used in
2532 conditional or looping commands, for example:
2534 ----
2535     if {![file exists foo]} {
2536         error {bad file name}
2537     } else {
2538         ...
2539     }
2540 ----
2542 finalize
2543 ~~~~~~~~
2544 +*finalize* 'reference ?command?'+
2546 If +'command'+ is omitted, returns the finalizer command for the given reference.
2548 Otherwise, sets a new finalizer command for the given reference. +'command'+ may be
2549 the empty string to remove the current finalizer.
2551 The reference must be a valid reference create with the `ref`
2552 command.
2554 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
2556 flush
2557 ~~~~~
2558 +*flush* 'fileId'+
2560 +'fileId' *flush*+
2562 Flushes any output that has been buffered for +'fileId'+.  +'fileId'+ must
2563 have been the return value from a previous call to `open`, or it may be
2564 +stdout+ or +stderr+ to access one of the standard I/O streams; it must
2565 refer to a file that was opened for writing.  This command returns an
2566 empty string.
2570 +*for* 'start test next body'+
2572 `for` is a looping command, similar in structure to the C `for` statement.
2573 The +'start'+, +'next'+, and +'body'+ arguments must be Tcl command strings,
2574 and +'test'+ is an expression string.
2576 The `for` command first invokes the Tcl interpreter to execute +'start'+.
2577 Then it repeatedly evaluates +'test'+ as an expression; if the result is
2578 non-zero it invokes the Tcl interpreter on +'body'+, then invokes the Tcl
2579 interpreter on +'next'+, then repeats the loop.  The command terminates
2580 when +'test'+ evaluates to 0.
2582 If a `continue` command is invoked within +'body'+ then any remaining
2583 commands in the current execution of +'body'+ are skipped; processing
2584 continues by invoking the Tcl interpreter on +'next'+, then evaluating
2585 +'test'+, and so on.
2587 If a `break` command is invoked within +'body'+ or +'next'+, then the `for`
2588 command will return immediately.
2590 The operation of `break` and `continue` are similar to the corresponding
2591 statements in C.
2593 `for` returns an empty string.
2595 foreach
2596 ~~~~~~~
2597 +*foreach* 'varName list body'+
2599 +*foreach* 'varList list ?varList2 list2 \...? body'+
2601 In this command, +'varName'+ is the name of a variable, +'list'+
2602 is a list of values to assign to +'varName'+, and +'body'+ is a
2603 collection of Tcl commands.
2605 For each field in +'list'+ (in order from left to right), `foreach` assigns
2606 the contents of the field to +'varName'+ (as if the `lindex` command
2607 had been used to extract the field), then calls the Tcl interpreter to
2608 execute +'body'+.
2610 If instead of being a simple name, +'varList'+ is used, multiple assignments
2611 are made each time through the loop, one for each element of +'varList'+.
2613 For example, if there are two elements in +'varList'+ and six elements in
2614 the list, the loop will be executed three times.
2616 If the length of the list doesn't evenly divide by the number of elements
2617 in +'varList'+, the value of the remaining variables in the last iteration
2618 of the loop are undefined.
2620 The `break` and `continue` statements may be invoked inside +'body'+,
2621 with the same effect as in the `for` command.
2623 `foreach` returns an empty string.
2625 format
2626 ~~~~~~
2627 +*format* 'formatString ?arg \...?'+
2629 This command generates a formatted string in the same way as the
2630 C 'sprintf' procedure (it uses 'sprintf' in its
2631 implementation).  +'formatString'+ indicates how to format
2632 the result, using +%+ fields as in 'sprintf', and the additional
2633 arguments, if any, provide values to be substituted into the result.
2635 All of the 'sprintf' options are valid; see the 'sprintf'
2636 man page for details.  Each +'arg'+ must match the expected type
2637 from the +%+ field in +'formatString'+; the `format` command
2638 converts each argument to the correct type (floating, integer, etc.)
2639 before passing it to 'sprintf' for formatting.
2641 The only unusual conversion is for +%c+; in this case the argument
2642 must be a decimal string, which will then be converted to the corresponding
2643 ASCII (or UTF-8) character value.
2645 In addition, Jim Tcl provides basic support for conversion to binary with +%b+.
2647 `format` does backslash substitution on its +'formatString'+
2648 argument, so backslash sequences in +'formatString'+ will be handled
2649 correctly even if the argument is in braces.
2651 The return value from `format` is the formatted string.
2653 getref
2654 ~~~~~~
2655 +*getref* 'reference'+
2657 Returns the string associated with +'reference'+. The reference must
2658 be a valid reference create with the `ref` command.
2660 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
2662 gets
2663 ~~~~
2664 +*gets* 'fileId ?varName?'+
2666 +'fileId' *gets* '?varName?'+
2668 Reads the next line from the file given by +'fileId'+ and discards
2669 the terminating newline character.
2671 If +'varName'+ is specified, then the line is placed in the variable
2672 by that name and the return value is a count of the number of characters
2673 read (not including the newline).
2675 If the end of the file is reached before reading
2676 any characters then -1 is returned and +'varName'+ is set to an
2677 empty string.
2679 If +'varName'+ is not specified then the return value will be
2680 the line (minus the newline character) or an empty string if
2681 the end of the file is reached before reading any characters.
2683 An empty string will also be returned if a line contains no characters
2684 except the newline, so `eof` may have to be used to determine
2685 what really happened.
2687 If the last character in the file is not a newline character, then
2688 `gets` behaves as if there were an additional newline character
2689 at the end of the file.
2691 +'fileId'+ must be +stdin+ or the return value from a previous
2692 call to `open`; it must refer to a file that was opened
2693 for reading.
2695 glob
2696 ~~~~
2697 +*glob* ?*-nocomplain*? ?*-directory* 'dir'? ?*-tails*? ?*--*? 'pattern ?pattern \...?'+
2699 This command performs filename globbing, using csh rules.  The returned
2700 value from `glob` is the list of expanded filenames.
2702 If +-nocomplain+ is specified as the first argument then an empty
2703 list may be returned;  otherwise an error is returned if the expanded
2704 list is empty.  The +-nocomplain+ argument must be provided
2705 exactly: an abbreviation will not be accepted.
2707 If +-directory+ is given, the +'dir'+ is understood to contain a
2708 directory name to search in. This allows globbing inside directories
2709 whose names may contain glob-sensitive characters. The returned names
2710 include the directory name unless +'-tails'+ is specified.
2712 If +'-tails'+ is specified, along with +-directory+, the returned names
2713 are relative to the given directory.
2715 global
2716 ~~~~~~
2718 +*global* 'varName ?varName \...?'+
2720 This command is ignored unless a Tcl procedure is being interpreted.
2721 If so, then it declares each given +'varName'+ to be a global variable
2722 rather than a local one.  For the duration of the current procedure
2723 (and only while executing in the current procedure), any reference to
2724 +'varName'+ will be bound to a global variable instead
2725 of a local one.
2727 An alternative to using `global` is to use the +::+ prefix
2728 to explicitly name a variable in the global scope.
2732 +*if* 'expr1' ?*then*? 'body1' *elseif* 'expr2' ?*then*? 'body2' *elseif* \... ?*else*? ?'bodyN'?+
2734 The `if` command evaluates +'expr1'+ as an expression (in the same way
2735 that `expr` evaluates its argument).  The value of the expression must
2736 be numeric; if it is non-zero then +'body1'+ is executed by passing it to
2737 the Tcl interpreter.
2739 Otherwise +'expr2'+ is evaluated as an expression and if it is non-zero
2740 then +'body2'+ is executed, and so on.
2742 If none of the expressions evaluates to non-zero then +'bodyN'+ is executed.
2744 The +then+ and +else+ arguments are optional "noise words" to make the
2745 command easier to read.
2747 There may be any number of +elseif+ clauses, including zero.  +'bodyN'+
2748 may also be omitted as long as +else+ is omitted too.
2750 The return value from the command is the result of the body script that
2751 was executed, or an empty string if none of the expressions was non-zero
2752 and there was no +'bodyN'+.
2754 incr
2755 ~~~~
2756 +*incr* 'varName ?increment?'+
2758 Increment the value stored in the variable whose name is +'varName'+.
2759 The value of the variable must be integral.
2761 If +'increment'+ is supplied then its value (which must be an
2762 integer) is added to the value of variable +'varName'+;  otherwise
2763 1 is added to +'varName'+.
2765 The new value is stored as a decimal string in variable +'varName'+
2766 and also returned as result.
2768 If the variable does not exist, the variable is implicitly created
2769 and set to +0+ first.
2771 info
2772 ~~~~
2774 +*info* 'option ?arg\...?'+::
2776 Provide information about various internals to the Tcl interpreter.
2777 The legal +'option'+'s (which may be abbreviated) are:
2779 +*info args* 'procname'+::
2780     Returns a list containing the names of the arguments to procedure
2781     +'procname'+, in order.  +'procname'+ must be the name of a
2782     Tcl command procedure.
2784 +*info alias* 'command'+::
2785     +'command'+ must be an alias created with `alias`. In which case the target
2786     command and arguments, as passed to `alias` are returned. See `exists -alias`
2788 +*info body* 'procname'+::
2789     Returns the body of procedure +'procname'+.  +'procname'+ must be
2790     the name of a Tcl command procedure.
2792 +*info channels*+::
2793     Returns a list of all open file handles from `open` or `socket`
2795 +*info commands* ?'pattern'?+::
2796     If +'pattern'+ isn't specified, returns a list of names of all the
2797     Tcl commands, including both the built-in commands written in C and
2798     the command procedures defined using the `proc` command.
2799     If +'pattern'+ is specified, only those names matching +'pattern'+
2800     are returned.  Matching is determined using the same rules as for
2801     `string match`.
2803 +*info complete* 'command' ?'missing'?+::
2804     Returns 1 if +'command'+ is a complete Tcl command in the sense of
2805     having no unclosed quotes, braces, brackets or array element names,
2806     If the command doesn't appear to be complete then 0 is returned.
2807     This command is typically used in line-oriented input environments
2808     to allow users to type in commands that span multiple lines;  if the
2809     command isn't complete, the script can delay evaluating it until additional
2810     lines have been typed to complete the command. If +'varName'+ is specified, the
2811     missing character is stored in the variable with that name.
2813 +*info exists* 'varName'+::
2814     Returns '1' if the variable named +'varName'+ exists in the
2815     current context (either as a global or local variable), returns '0'
2816     otherwise.
2818 +*info frame* ?'number'?+::
2819     If +'number'+ is not specified, this command returns a number
2820     which is the same result as `info level` - the current stack frame level.
2821     If +'number'+ is specified, then the result is a list consisting of the procedure,
2822     filename and line number for the procedure call at level +'number'+ on the stack.
2823     If +'number'+ is positive then it selects a particular stack level (1 refers
2824     to the top-most active procedure, 2 to the procedure it called, and
2825     so on); otherwise it gives a level relative to the current level
2826     (0 refers to the current procedure, -1 to its caller, and so on).
2827     The level has an identical meaning to `info level`.
2829 +*info globals* ?'pattern'?+::
2830     If +'pattern'+ isn't specified, returns a list of all the names
2831     of currently-defined global variables.
2832     If +'pattern'+ is specified, only those names matching +'pattern'+
2833     are returned.  Matching is determined using the same rules as for
2834     `string match`.
2836 +*info hostname*+::
2837     An alias for `os.gethostname` for compatibility with Tcl 6.x
2839 +*info level* ?'number'?+::
2840     If +'number'+ is not specified, this command returns a number
2841     giving the stack level of the invoking procedure, or 0 if the
2842     command is invoked at top-level.  If +'number'+ is specified,
2843     then the result is a list consisting of the name and arguments for the
2844     procedure call at level +'number'+ on the stack.  If +'number'+
2845     is positive then it selects a particular stack level (1 refers
2846     to the top-most active procedure, 2 to the procedure it called, and
2847     so on); otherwise it gives a level relative to the current level
2848     (0 refers to the current procedure, -1 to its caller, and so on).
2849     See the `uplevel` command for more information on what stack
2850     levels mean.
2852 +*info locals* ?'pattern'?+::
2853     If +'pattern'+ isn't specified, returns a list of all the names
2854     of currently-defined local variables, including arguments to the
2855     current procedure, if any.  Variables defined with the `global`
2856     and `upvar` commands will not be returned.  If +'pattern'+ is
2857     specified, only those names matching +'pattern'+ are returned.
2858     Matching is determined using the same rules as for `string match`.
2860 +*info nameofexecutable*+::
2861     Returns the name of the binary file from which the application
2862     was invoked. A full path will be returned, unless the path
2863     can't be determined, in which case the empty string will be returned.
2865 +*info procs* ?'pattern'?+::
2866     If +'pattern'+ isn't specified, returns a list of all the
2867     names of Tcl command procedures.
2868     If +'pattern'+ is specified, only those names matching +'pattern'+
2869     are returned.  Matching is determined using the same rules as for
2870     `string match`.
2872 +*info references*+::
2873     Returns a list of all references which have not yet been garbage
2874     collected.
2876 +*info returncodes* ?'code'?+::
2877     Returns a list representing the mapping of standard return codes
2878     to names. e.g. +{0 ok 1 error 2 return \...}+. If a code is given,
2879     instead returns the name for the given code.
2881 +*info script*+::
2882     If a Tcl script file is currently being evaluated (i.e. there is a
2883     call to 'Jim_EvalFile' active or there is an active invocation
2884     of the `source` command), then this command returns the name
2885     of the innermost file being processed.  Otherwise the command returns an
2886     empty string.
2888 +*info source* 'script ?filename line?'+::
2889     With a single argument, returns the original source location of the given script as a list of
2890     +{filename linenumber}+. If the source location can't be determined, the
2891     list +{{} 0}+ is returned. If +'filename'+ and +'line'+ are given, returns a copy
2892     of +'script'+ with the associate source information. This can be useful to produce
2893     useful messages from `eval`, etc. if the original source information may be lost.
2895 +*info stacktrace*+::
2896     After an error is caught with `catch`, returns the stack trace as a list
2897     of +{procedure filename line \...}+.
2899 +*info statics* 'procname'+::
2900     Returns a dictionary of the static variables of procedure
2901     +'procname'+.  +'procname'+ must be the name of a Tcl command
2902     procedure. An empty dictionary is returned if the procedure has
2903     no static variables.
2905 +*info version*+::
2906     Returns the version number for this version of Jim in the form +*x.yy*+.
2908 +*info vars* ?'pattern'?+::
2909     If +'pattern'+ isn't specified,
2910     returns a list of all the names of currently-visible variables, including
2911     both locals and currently-visible globals.
2912     If +'pattern'+ is specified, only those names matching +'pattern'+
2913     are returned.  Matching is determined using the same rules as for
2914     `string match`.
2916 join
2917 ~~~~
2918 +*join* 'list ?joinString?'+
2920 The +'list'+ argument must be a valid Tcl list.  This command returns the
2921 string formed by joining all of the elements of +'list'+ together with
2922 +'joinString'+ separating each adjacent pair of elements.
2924 The +'joinString'+ argument defaults to a space character.
2926 kill
2927 ~~~~
2928 +*kill* ?'SIG'|*-0*? 'pid'+
2930 Sends the given signal to the process identified by +'pid'+.
2932 The signal may be specified by name or number in one of the following forms:
2934 * +TERM+
2935 * +SIGTERM+
2936 * +-TERM+
2937 * +15+
2938 * +-15+
2940 The signal name may be in either upper or lower case.
2942 The special signal name +-0+ simply checks that a signal +'could'+ be sent.
2944 If no signal is specified, SIGTERM is used.
2946 An error is raised if the signal could not be delivered.
2948 lambda
2949 ~~~~~~
2950 +*lambda* 'args ?statics? body'+
2952 The `lambda` command is identical to `proc`, except rather than
2953 creating a named procedure, it creates an anonymous procedure and returns
2954 the name of the procedure.
2956 See `proc` and <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
2958 lappend
2959 ~~~~~~~
2960 +*lappend* 'varName value ?value value \...?'+
2962 Treat the variable given by +'varName'+ as a list and append each of
2963 the +'value'+ arguments to that list as a separate element, with spaces
2964 between elements.
2966 If +'varName'+ doesn't exist, it is created as a list with elements given
2967 by the +'value'+ arguments. `lappend` is similar to `append` except that
2968 each +'value'+ is appended as a list element rather than raw text.
2970 This command provides a relatively efficient way to build up large lists.
2971 For example,
2973 ----
2974     lappend a $b
2975 ----
2977 is much more efficient than
2979 ----
2980     set a [concat $a [list $b]]
2981 ----
2983 when +$a+ is long.
2985 lassign
2986 ~~~~~~~
2987 +*lassign* 'list varName ?varName \...?'+
2989 This command treats the value +'list'+ as a list and assigns successive elements from that list to
2990 the variables given by the +'varName'+ arguments in order. If there are more variable names than
2991 list elements, the remaining variables are set to the empty string. If there are more list elements
2992 than variables, a list of unassigned elements is returned.
2994 ----
2995     . lassign {1 2 3} a b; puts a=$a,b=$b
2996     3
2997     a=1,b=2
2998 ----
3000 local
3001 ~~~~~
3002 +*local* 'cmd ?arg\...?'+
3004 First, `local` evaluates +'cmd'+ with the given arguments. The return value must
3005 be the name of an existing command, which is marked as having local scope.
3006 This means that when the current procedure exits, the specified
3007 command is deleted. This can be useful with `lambda`, local procedures or
3008 to automatically close a filehandle.
3010 In addition, if a command already exists with the same name,
3011 the existing command will be kept rather than deleted, and may be called
3012 via `upcall`. The previous command will be restored when the current
3013 procedure exits. See `upcall` for more details.
3015 In this example, a local procedure is created. Note that the procedure
3016 continues to have global scope while it is active.
3018 ----
3019     proc outer {} {
3020       # proc ... returns "inner" which is marked local
3021       local proc inner {} {
3022         # will be deleted when 'outer' exits
3023       }
3025       inner
3026       ...
3027     }
3028 ----
3030 In this example, the lambda is deleted at the end of the procedure rather
3031 than waiting until garbage collection.
3033 ----
3034     proc outer {} {
3035       set x [lambda inner {args} {
3036         # will be deleted when 'outer' exits
3037       }]
3038       # Use 'function' here which simply returns $x
3039       local function $x
3041       $x ...
3042       ...
3043     }
3044 ----
3046 loop
3047 ~~~~
3048 +*loop* 'var first limit ?incr? body'+
3050 Similar to `for` except simpler and possibly more efficient.
3051 With a positive increment, equivalent to:
3053 ----
3054     for {set var $first} {$var < $limit} {incr var $incr} $body
3055 ----
3057 If +'incr'+ is not specified, 1 is used.
3058 Note that setting the loop variable inside the loop does not
3059 affect the loop count.
3061 lindex
3062 ~~~~~~
3063 +*lindex* 'list ?index ...?'+
3065 Treats +'list'+ as a Tcl list and returns element +'index'+ from it
3066 (0 refers to the first element of the list).
3067 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'index'+.
3069 In extracting the element, +'lindex'+ observes the same rules concerning
3070 braces and quotes and backslashes as the Tcl command interpreter; however,
3071 variable substitution and command substitution do not occur.
3073 If no index values are given, simply returns +'list'+
3075 If +'index'+ is negative or greater than or equal to the number of elements
3076 in +'list'+, then an empty string is returned.
3078 If additional index arguments are supplied, then each argument is
3079 used in turn to select an element from the previous indexing
3080 operation, allowing the script to select elements from sublists.
3082 linsert
3083 ~~~~~~~
3084 +*linsert* 'list index element ?element element \...?'+
3086 This command produces a new list from +'list'+ by inserting all
3087 of the +'element'+ arguments just before the element +'index'+
3088 of +'list'+. Each +'element'+ argument will become
3089 a separate element of the new list. If +'index'+ is less than
3090 or equal to zero, then the new elements are inserted at the
3091 beginning of the list. If +'index'+ is greater than or equal
3092 to the number of elements in the list, then the new elements are
3093 appended to the list.
3095 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'index'+.
3097 list
3098 ~~~~
3100 +*list* 'arg ?arg \...?'+
3102 This command returns a list comprised of all the arguments, +'arg'+. Braces
3103 and backslashes get added as necessary, so that the `lindex` command
3104 may be used on the result to re-extract the original arguments, and also
3105 so that `eval` may be used to execute the resulting list, with
3106 +'arg1'+ comprising the command's name and the other args comprising
3107 its arguments. `list` produces slightly different results than
3108 `concat`:  `concat` removes one level of grouping before forming
3109 the list, while `list` works directly from the original arguments.
3110 For example, the command
3112 ----
3113     list a b {c d e} {f {g h}}
3114 ----
3116 will return
3118 ----
3119     a b {c d e} {f {g h}}
3120 ----
3122 while `concat` with the same arguments will return
3124 ----
3125     a b c d e f {g h}
3126 ----
3128 llength
3129 ~~~~~~~
3130 +*llength* 'list'+
3132 Treats +'list'+ as a list and returns a decimal string giving
3133 the number of elements in it.
3135 lset
3136 ~~~~
3137 +*lset* 'varName ?index ..? newValue'+
3139 Sets an element in a list.
3141 The `lset` command accepts a parameter, +'varName'+, which it interprets
3142 as the name of a variable containing a Tcl list. It also accepts
3143 zero or more indices into the list. Finally, it accepts a new value
3144 for an element of varName. If no indices are presented, the command
3145 takes the form:
3147 ----
3148     lset varName newValue
3149 ----
3151 In this case, newValue replaces the old value of the variable
3152 varName.
3154 When presented with a single index, the `lset` command
3155 treats the content of the varName variable as a Tcl list. It addresses
3156 the index'th element in it (0 refers to the first element of the
3157 list). When interpreting the list, `lset` observes the same rules
3158 concerning braces and quotes and backslashes as the Tcl command
3159 interpreter; however, variable substitution and command substitution
3160 do not occur. The command constructs a new list in which the
3161 designated element is replaced with newValue. This new list is
3162 stored in the variable varName, and is also the return value from
3163 the `lset` command.
3165 If index is negative or greater than or equal to the number of
3166 elements in $varName, then an error occurs.
3168 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'index'+.
3170 If additional index arguments are supplied, then each argument is
3171 used in turn to address an element within a sublist designated by
3172 the previous indexing operation, allowing the script to alter
3173 elements in sublists. The command,
3175 ----
3176     lset a 1 2 newValue
3177 ----
3179 replaces element 2 of sublist 1 with +'newValue'+.
3181 The integer appearing in each index argument must be greater than
3182 or equal to zero. The integer appearing in each index argument must
3183 be strictly less than the length of the corresponding list. In other
3184 words, the `lset` command cannot change the size of a list. If an
3185 index is outside the permitted range, an error is reported.
3187 lmap
3188 ~~~~
3190 +*lmap* 'varName list body'+
3192 +*lmap* 'varList list ?varList2 list2 \...? body'+
3194 `lmap` is a "collecting" `foreach` which returns a list of its results.
3196 For example:
3198 ----
3199     . lmap i {1 2 3 4 5} {expr $i*$i}
3200     1 4 9 16 25
3201     . lmap a {1 2 3} b {A B C} {list $a $b}
3202     {1 A} {2 B} {3 C}
3203 ----
3205 If the body invokes `continue`, no value is added for this iteration.
3206 If the body invokes `break`, the loop ends and no more values are added.
3208 load
3209 ~~~~
3210 +*load* 'filename'+
3212 Loads the dynamic extension, +'filename'+. Generally the filename should have
3213 the extension +.so+. The initialisation function for the module must be based
3214 on the name of the file. For example loading +hwaccess.so+ will invoke
3215 the initialisation function, +Jim_hwaccessInit+. Normally the `load` command
3216 should not be used directly. Instead it is invoked automatically by `package require`.
3218 lrange
3219 ~~~~~~
3220 +*lrange* 'list first last'+
3222 +'list'+ must be a valid Tcl list. This command will return a new
3223 list consisting of elements +'first'+ through +'last'+, inclusive.
3225 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'first'+ and +'last'+.
3227 If +'last'+ is greater than or equal to the number of elements
3228 in the list, then it is treated as if it were +end+.
3230 If +'first'+ is greater than +'last'+ then an empty string
3231 is returned.
3233 Note: +"`lrange` 'list first first'"+ does not always produce the
3234 same result as +"`lindex` 'list first'"+ (although it often does
3235 for simple fields that aren't enclosed in braces); it does, however,
3236 produce exactly the same results as +"`list` [`lindex` 'list first']"+
3238 lreplace
3239 ~~~~~~~~
3241 +*lreplace* 'list first last ?element element \...?'+
3243 Returns a new list formed by replacing one or more elements of
3244 +'list'+ with the +'element'+ arguments.
3246 +'first'+ gives the index in +'list'+ of the first element
3247 to be replaced.
3249 If +'first'+ is less than zero then it refers to the first
3250 element of +'list'+;  the element indicated by +'first'+
3251 must exist in the list.
3253 +'last'+ gives the index in +'list'+ of the last element
3254 to be replaced;  it must be greater than or equal to +'first'+.
3256 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'first'+ and +'last'+.
3258 The +'element'+ arguments specify zero or more new arguments to
3259 be added to the list in place of those that were deleted.
3261 Each +'element'+ argument will become a separate element of
3262 the list.
3264 If no +'element'+ arguments are specified, then the elements
3265 between +'first'+ and +'last'+ are simply deleted.
3267 lrepeat
3268 ~~~~~~~~
3269 +*lrepeat* 'number element1 ?element2 \...?'+
3271 Build a list by repeating elements +'number'+ times (which must be
3272 a positive integer).
3274 ----
3275     . lrepeat 3 a b
3276     a b a b a b
3277 ----
3279 lreverse
3280 ~~~~~~~~
3281 +*lreverse* 'list'+
3283 Returns the list in reverse order.
3285 ----
3286     . lreverse {1 2 3}
3287     3 2 1
3288 ----
3290 lsearch
3291 ~~~~~~~
3292 +*lsearch* '?options? list pattern'+
3294 This command searches the elements +'list'+ to see if one of them matches +'pattern'+. If so, the
3295 command returns the index of the first matching element (unless the options +-all+, +-inline+ or +-bool+ are
3296 specified.) If not, the command returns -1. The option arguments indicates how the elements of
3297 the list are to be matched against pattern and must have one of the values below:
3299 *Note* that this command is different from Tcl in that default match type is +-exact+ rather than +-glob+.
3301 +*-exact*+::
3302     +'pattern'+ is a literal string that is compared for exact equality against each list element.
3303     This is the default.
3305 +*-glob*+::
3306     +'pattern'+ is a glob-style pattern which is matched against each list element using the same
3307     rules as the string match command.
3309 +*-regexp*+::
3310     +'pattern'+ is treated as a regular expression and matched against each list element using
3311     the rules described by `regexp`.
3313 +*-command* 'cmdname'+::
3314     +'cmdname'+ is a command which is used to match the pattern against each element of the
3315     list. It is invoked as +'cmdname' ?*-nocase*? 'pattern listvalue'+ and should return 1
3316     for a match, or 0 for no match.
3318 +*-all*+::
3319     Changes the result to be the list of all matching indices (or all matching values if
3320     +-inline+ is specified as well). If indices are returned, the indices will be in numeric
3321     order. If values are returned, the order of the values will be the order of those values
3322     within the input list.
3324 +*-inline*+::
3325     The matching value is returned instead of its index (or an empty string if no value
3326     matches). If +-all+ is also specified, then the result of the command is the list of all
3327     values that matched. The +-inline+ and +-bool+ options are mutually exclusive.
3329 +*-bool*+::
3330     Changes the result to '1' if a match was found, or '0' otherwise. If +-all+ is also specified,
3331     the result will be a list of '0' and '1' for each element of the list depending upon whether
3332     the corresponding element matches. The +-inline+ and +-bool+ options are mutually exclusive.
3334 +*-not*+::
3335     This negates the sense of the match, returning the index (or value
3336     if +-inline+ is specified) of the first non-matching value in the
3337     list. If +-bool+ is also specified, the '0' will be returned if a
3338     match is found, or '1' otherwise. If +-all+ is also specified,
3339     non-matches will be returned rather than matches.
3341 +*-nocase*+::
3342     Causes comparisons to be handled in a case-insensitive manner.
3344 lsort
3345 ~~~~~
3346 +*lsort* ?*-index* 'listindex'? ?*-nocase|-integer|-real|-command* 'cmdname'? ?*-unique*? ?*-decreasing*|*-increasing*? 'list'+
3348 Sort the elements of +'list'+, returning a new list in sorted order.
3349 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.
3351 If +-nocase+ is specified, comparisons are case-insensitive.
3353 If +-integer+ is specified, numeric sorting is used.
3355 If +-real+ is specified, floating point number sorting is used.
3357 If +-command 'cmdname'+ is specified, +'cmdname'+ is treated as a command
3358 name. For each comparison, +'cmdname $value1 $value2+' is called which
3359 should compare the values and return an integer less than, equal
3360 to, or greater than zero if the +'$value1'+ is to be considered less
3361 than, equal to, or greater than +'$value2'+, respectively.
3363 If +-decreasing+ is specified, the resulting list is in the opposite
3364 order to what it would be otherwise. +-increasing+ is the default.
3366 If +-unique+ is specified, then only the last set of duplicate elements found in the list will be retained.
3367 Note that duplicates are determined relative to the comparison used in the sort. Thus if +-index 0+ is used,
3368 +{1 a}+ and +{1 b}+ would be considered duplicates and only the second element, +{1 b}+, would be retained.
3370 If +-index 'listindex'+ is specified, each element of the list is treated as a list and
3371 the given index is extracted from the list for comparison. The list index may
3372 be any valid list index, such as +1+, +end+ or +end-2+.
3374 defer
3375 ~~~~~
3376 +*defer* 'script'+
3378 This command is a simple helper command to add a script to the '+$jim::defer+' variable
3379 that will run when the current proc or interpreter exits. For example:
3381 ----
3382     . proc a {} { defer {puts "Leaving a"}; puts "Exit" }
3383     . a
3384     Exit
3385     Leaving a
3386 ----
3388 If the '+$jim::defer+' variable exists, it is treated as a list of scripts to run
3389 when the proc or interpreter exits.
3391 open
3392 ~~~~
3393 +*open* 'fileName ?access?'+
3395 +*open* '|command-pipeline ?access?'+
3397 Opens a file and returns an identifier
3398 that may be used in future invocations
3399 of commands like `read`, `puts`, and `close`.
3400 +'fileName'+ gives the name of the file to open.
3402 The +'access'+ argument indicates the way in which the file is to be accessed.
3403 It may have any of the following values:
3405 +r+::
3406     Open the file for reading only; the file must already exist.
3408 +r++::
3409     Open the file for both reading and writing; the file must
3410     already exist.
3412 +w+::
3413     Open the file for writing only. Truncate it if it exists. If it doesn't
3414     exist, create a new file.
3416 +w++::
3417     Open the file for reading and writing. Truncate it if it exists.
3418     If it doesn't exist, create a new file.
3420 +a+::
3421     Open the file for writing only. The file must already exist, and the file
3422     is positioned so that new data is appended to the file.
3424 +a++::
3425     Open the file for reading and writing. If the file doesn't
3426     exist, create a new empty file. Set the initial access position
3427     to the end of the file.
3429 +'access'+ defaults to 'r'.
3431 If a file is opened for both reading and writing, then `seek`
3432 must be invoked between a read and a write, or vice versa.
3434 If the first character of +'fileName'+ is "|" then the remaining
3435 characters of +'fileName'+ are treated as a list of arguments that
3436 describe a command pipeline to invoke, in the same style as the
3437 arguments for exec. In this case, the channel identifier returned
3438 by open may be used to write to the command's input pipe or read
3439 from its output pipe, depending on the value of +'access'+. If write-only
3440 access is used (e.g. +'access'+ is 'w'), then standard output for the
3441 pipeline is directed to the current standard output unless overridden
3442 by the command. If read-only access is used (e.g. +'access'+ is r),
3443 standard input for the pipeline is taken from the current standard
3444 input unless overridden by the command.
3446 The `pid` command may be used to return the process ids of the commands
3447 forming the command pipeline.
3449 See also `socket`, `pid`, `exec`
3451 package
3452 ~~~~~~~
3453 +*package provide* 'name ?version?'+
3455 Indicates that the current script provides the package named +'name'+.
3456 If no version is specified, '1.0' is used.
3458 Any script which provides a package may include this statement
3459 as the first statement, although it is not required.
3461 +*package require* 'name ?version?'*+
3463 Searches for the package with the given +'name'+ by examining each path
3464 in '$::auto_path' and trying to load '$path/$name.so' as a dynamic extension,
3465 or '$path/$name.tcl' as a script package.
3467 The first such file which is found is considered to provide the package.
3468 (The version number is ignored).
3470 If '$name.so' exists, it is loaded with the `load` command,
3471 otherwise if '$name.tcl' exists it is loaded with the `source` command.
3473 If `load` or `source` fails, `package require` will fail immediately.
3474 No further attempt will be made to locate the file.
3478 +*pid*+
3480 +*pid* 'fileId'+
3482 The first form returns the process identifier of the current process.
3484 The second form accepts a handle returned by `open` and returns a list
3485 of the process ids forming the pipeline in the same form as `exec ... &`.
3486 If 'fileId' represents a regular file handle rather than a command pipeline,
3487 the empty string is returned instead.
3489 See also `open`, `exec`
3491 proc
3492 ~~~~
3493 +*proc* 'name args ?statics? body'+
3495 The `proc` command creates a new Tcl command procedure, +'name'+.
3496 When the new command is invoked, the contents of +'body'+ will be executed.
3497 Tcl interpreter. +'args'+ specifies the formal arguments to the procedure.
3498 If specified, +'statics'+, declares static variables which are bound to the
3499 procedure.
3501 See <<_procedures,PROCEDURES> for detailed information about Tcl procedures.
3503 The `proc` command returns +'name'+ (which is useful with `local`).
3505 When a procedure is invoked, the procedure's return value is the
3506 value specified in a `return` command.  If the procedure doesn't
3507 execute an explicit `return`, then its return value is the value
3508 of the last command executed in the procedure's body.
3510 If an error occurs while executing the procedure body, then the
3511 procedure-as-a-whole will return that same error.
3513 puts
3514 ~~~~
3515 +*puts* ?*-nonewline*? '?fileId? string'+
3517 +'fileId' *puts* ?*-nonewline*? 'string'+
3519 Writes the characters given by +'string'+ to the file given
3520 by +'fileId'+. +'fileId'+ must have been the return
3521 value from a previous call to `open`, or it may be
3522 +stdout+ or +stderr+ to refer to one of the standard I/O
3523 channels; it must refer to a file that was opened for
3524 writing.
3526 In the first form, if no +'fileId'+ is specified then it defaults to +stdout+.
3527 `puts` normally outputs a newline character after +'string'+,
3528 but this feature may be suppressed by specifying the +-nonewline+
3529 switch.
3531 Output to files is buffered internally by Tcl; the `flush`
3532 command may be used to force buffered characters to be output.
3534 pipe
3535 ~~~~
3536 Creates a pair of `aio` channels and returns the handles as a list: +{read write}+
3538 ----
3539     lassign [pipe] r w
3541     # Must close $w after exec
3542     exec ps >@$w &
3543     $w close
3545     $r readable ...
3546 ----
3550 +*pwd*+
3552 Returns the path name of the current working directory.
3554 rand
3555 ~~~~
3556 +*rand* '?min? ?max?'+
3558 Returns a random integer between +'min'+ (defaults to 0) and +'max'+
3559 (defaults to the maximum integer).
3561 If only one argument is given, it is interpreted as +'max'+.
3563 range
3564 ~~~~
3565 +*range* '?start? end ?step?'+
3567 Returns a list of integers starting at +'start'+ (defaults to 0)
3568 and ranging up to but not including +'end'+ in steps of +'step'+ defaults to 1).
3570 ----
3571     . range 5
3572     0 1 2 3 4
3573     . range 2 5
3574     2 3 4
3575     . range 2 10 4
3576     2 6
3577     . range 7 4 -2
3578     7 5
3579 ----
3581 read
3582 ~~~~
3583 +*read* ?*-nonewline*? 'fileId'+
3585 +'fileId' *read* ?*-nonewline*?+
3587 +*read* 'fileId numBytes'+
3589 +'fileId' *read* 'numBytes'+
3591 In the first form, all of the remaining bytes are read from the file
3592 given by +'fileId'+; they are returned as the result of the command.
3593 If the +-nonewline+ switch is specified then the last
3594 character of the file is discarded if it is a newline.
3596 In the second form, the extra argument specifies how many bytes to read;
3597 exactly this many bytes will be read and returned, unless there are fewer than
3598 +'numBytes'+ bytes left in the file; in this case, all the remaining
3599 bytes are returned.
3601 +'fileId'+ must be +stdin+ or the return value from a previous call
3602 to `open`; it must refer to a file that was opened for reading.
3604 regexp
3605 ~~~~~~
3606 +*regexp ?-nocase? ?-line? ?-indices? ?-start* 'offset'? *?-all? ?-inline? ?--?* 'exp string ?matchVar? ?subMatchVar subMatchVar \...?'+
3608 Determines whether the regular expression +'exp'+ matches part or
3609 all of +'string'+ and returns 1 if it does, 0 if it doesn't.
3611 See <<_regular_expressions,REGULAR EXPRESSIONS>> above for complete information on the
3612 syntax of +'exp'+ and how it is matched against +'string'+.
3614 If additional arguments are specified after +'string'+ then they
3615 are treated as the names of variables to use to return
3616 information about which part(s) of +'string'+ matched +'exp'+.
3617 +'matchVar'+ will be set to the range of +'string'+ that
3618 matched all of +'exp'+. The first +'subMatchVar'+ will contain
3619 the characters in +'string'+ that matched the leftmost parenthesized
3620 subexpression within +'exp'+, the next +'subMatchVar'+ will
3621 contain the characters that matched the next parenthesized
3622 subexpression to the right in +'exp'+, and so on.
3624 Normally, +'matchVar'+ and the each +'subMatchVar'+ are set to hold the
3625 matching characters from `string`, however see +-indices+ and
3626 +-inline+ below.
3628 If there are more values for +'subMatchVar'+ than parenthesized subexpressions
3629 within +'exp'+, or if a particular subexpression in +'exp'+ doesn't
3630 match the string (e.g. because it was in a portion of the expression
3631 that wasn't matched), then the corresponding +'subMatchVar'+ will be
3632 set to +"-1 -1"+ if +-indices+ has been specified or to an empty
3633 string otherwise.
3635 The following switches modify the behaviour of +'regexp'+
3637 +*-nocase*+::
3638     Causes upper-case and lower-case characters to be treated as
3639     identical during the matching process.
3641 +*-line*+::
3642     Use newline-sensitive matching. By default, newline
3643     is a completely ordinary character with no special meaning in
3644     either REs or strings. With this flag, +[^+ bracket expressions
3645     and +.+ never match newline, an +^+ anchor matches the null
3646     string after any newline in the string in addition to its normal
3647     function, and the +$+ anchor matches the null string before any
3648     newline in the string in addition to its normal function.
3650 +*-indices*+::
3651     Changes what is stored in the subMatchVars. Instead of
3652     storing the matching characters from string, each variable
3653     will contain a list of two decimal strings giving the indices
3654     in string of the first and last characters in the matching
3655     range of characters.
3657 +*-start* 'offset'+::
3658     Specifies a character index offset into the string at which to start
3659     matching the regular expression. If +-indices+ is
3660     specified, the indices will be indexed starting from the
3661     absolute beginning of the input string. +'offset'+ will be
3662     constrained to the bounds of the input string.
3664 +*-all*+::
3665     Causes the regular expression to be matched as many times as possible
3666     in the string, returning the total number of matches found. If this
3667     is specified with match variables, they will contain information
3668     for the last match only.
3670 +*-inline*+::
3671     Causes the command to return, as a list, the data that would otherwise
3672     be placed in match variables. When using +-inline+, match variables
3673     may not be specified. If used with +-all+, the list will be concatenated
3674     at each iteration, such that a flat list is always returned. For
3675     each match iteration, the command will append the overall match
3676     data, plus one element for each subexpression in the regular
3677     expression.
3679 +*--*+::
3680     Marks the end of switches. The argument following this one will be
3681     treated as +'exp'+ even if it starts with a +-+.
3683 regsub
3684 ~~~~~~
3685 +*regsub ?-nocase? ?-all? ?-line? ?-start* 'offset'? ?*--*? 'exp string subSpec ?varName?'+
3687 This command matches the regular expression +'exp'+ against
3688 +'string'+ using the rules described in REGULAR EXPRESSIONS
3689 above.
3691 If +'varName'+ is specified, the commands stores +'string'+ to +'varName'+
3692 with the substitutions detailed below, and returns the number of
3693 substitutions made (normally 1 unless +-all+ is specified).
3694 This is 0 if there were no matches.
3696 If +'varName'+ is not specified, the substituted string will be returned
3697 instead.
3699 When copying +'string'+, the portion of +'string'+ that
3700 matched +'exp'+ is replaced with +'subSpec'+.
3701 If +'subSpec'+ contains a +&+ or +{backslash}0+, then it is replaced
3702 in the substitution with the portion of +'string'+ that
3703 matched +'exp'+.
3705 If +'subSpec'+ contains a +{backslash}n+, where +'n'+ is a digit
3706 between 1 and 9, then it is replaced in the substitution with
3707 the portion of +'string'+ that matched the +'n'+\'-th
3708 parenthesized subexpression of +'exp'+.
3709 Additional backslashes may be used in +'subSpec'+ to prevent special
3710 interpretation of +&+ or +{backslash}0+ or +{backslash}n+ or
3711 backslash.
3713 The use of backslashes in +'subSpec'+ tends to interact badly
3714 with the Tcl parser's use of backslashes, so it's generally
3715 safest to enclose +'subSpec'+ in braces if it includes
3716 backslashes.
3718 The following switches modify the behaviour of +'regsub'+
3720 +*-nocase*+::
3721     Upper-case characters in +'string'+ are converted to lower-case
3722     before matching against +'exp'+;  however, substitutions
3723     specified by +'subSpec'+ use the original unconverted form
3724     of +'string'+.
3726 +*-all*+::
3727     All ranges in +'string'+ that match +'exp'+ are found and substitution
3728     is performed for each of these ranges, rather than only the
3729     first. The +&+ and +{backslash}n+ sequences are handled for
3730     each substitution using the information from the corresponding
3731     match.
3733 +*-line*+::
3734     Use newline-sensitive matching. By default, newline
3735     is a completely ordinary character with no special meaning in
3736     either REs or strings.  With this flag, +[^+ bracket expressions
3737     and +.+ never match newline, an +^+ anchor matches the null
3738     string after any newline in the string in addition to its normal
3739     function, and the +$+ anchor matches the null string before any
3740     newline in the string in addition to its normal function.
3742 +*-start* 'offset'+::
3743     Specifies a character index offset into the string at which to
3744     start matching the regular expression. +'offset'+ will be
3745     constrained to the bounds of the input string.
3747 +*--*+::
3748     Marks the end of switches. The argument following this one will be
3749     treated as +'exp'+ even if it starts with a +-+.
3753 +*ref* 'string tag ?finalizer?'+
3755 Create a new reference containing +'string'+ of type +'tag'+.
3756 If +'finalizer'+ is specified, it is a command which will be invoked
3757 when the a garbage collection cycle runs and this reference is
3758 no longer accessible.
3760 The finalizer is invoked as:
3762 ----
3763     finalizer reference string
3764 ----
3766 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
3768 rename
3769 ~~~~~~
3770 +*rename* 'oldName newName'+
3772 Rename the command that used to be called +'oldName'+ so that it
3773 is now called +'newName'+.  If +'newName'+ is an empty string
3774 (e.g. {}) then +'oldName'+ is deleted.  The `rename` command
3775 returns an empty string as result.
3777 return
3778 ~~~~~~
3779 +*return* ?*-code* 'code'? ?*-errorinfo* 'stacktrace'? ?*-errorcode* 'errorcode'? ?*-level* 'n'? ?'value'?+
3781 Return immediately from the current procedure (or top-level command
3782 or `source` command), with +'value'+ as the return value.  If +'value'+
3783 is not specified, an empty string will be returned as result.
3785 If +-code+ is specified (as either a number or ok, error, break,
3786 continue, signal, return or exit), this code will be used instead
3787 of +JIM_OK+. This is generally useful when implementing flow of control
3788 commands.
3790 If +-level+ is specified and greater than 1, it has the effect of delaying
3791 the new return code from +-code+. This is useful when rethrowing an error
3792 from `catch`. See the implementation of try/catch in tclcompat.tcl for
3793 an example of how this is done.
3795 Note: The following options are only used when +-code+ is JIM_ERR.
3797 If +-errorinfo+ is specified (as returned from `info stacktrace`)
3798 it is used to initialize the stacktrace.
3800 If +-errorcode+ is specified, it is used to set the global variable $::errorCode.
3802 scan
3803 ~~~~
3804 +*scan* 'string format varName1 ?varName2 \...?'+
3806 This command parses fields from an input string in the same fashion
3807 as the C 'sscanf' procedure.  +'string'+ gives the input to be parsed
3808 and +'format'+ indicates how to parse it, using '%' fields as in
3809 'sscanf'.  All of the 'sscanf' options are valid; see the 'sscanf'
3810 man page for details.  Each +'varName'+ gives the name of a variable;
3811 when a field is scanned from +'string'+, the result is converted back
3812 into a string and assigned to the corresponding +'varName'+.  The
3813 only unusual conversion is for '%c'.  For '%c' conversions a single
3814 character value is converted to a decimal string, which is then
3815 assigned to the corresponding +'varName'+; no field width may be
3816 specified for this conversion.
3818 seek
3819 ~~~~
3820 +*seek* 'fileId offset ?origin?'+
3822 +'fileId' *seek* 'offset ?origin?'+
3824 Change the current access position for +'fileId'+.
3825 The +'offset'+ and +'origin'+ arguments specify the position at
3826 which the next read or write will occur for +'fileId'+.
3827 +'offset'+ must be a number (which may be negative) and +'origin'+
3828 must be one of the following:
3830 +*start*+::
3831     The new access position will be +'offset'+ bytes from the start
3832     of the file.
3834 +*current*+::
3835     The new access position will be +'offset'+ bytes from the current
3836     access position; a negative +'offset'+ moves the access position
3837     backwards in the file.
3839 +*end*+::
3840     The new access position will be +'offset'+ bytes from the end of
3841     the file.  A negative +'offset'+ places the access position before
3842     the end-of-file, and a positive +'offset'+ places the access position
3843     after the end-of-file.
3845 The +'origin'+ argument defaults to +start+.
3847 +'fileId'+ must have been the return value from a previous call to
3848 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
3849 of the standard I/O channels.
3851 This command returns an empty string.
3855 +*set* 'varName ?value?'+
3857 Returns the value of variable +'varName'+.
3859 If +'value'+ is specified, then set the value of +'varName'+ to +'value'+,
3860 creating a new variable if one doesn't already exist, and return
3861 its value.
3863 If +'varName'+ contains an open parenthesis and ends with a
3864 close parenthesis, then it refers to an array element:  the characters
3865 before the open parenthesis are the name of the array, and the characters
3866 between the parentheses are the index within the array.
3867 Otherwise +'varName'+ refers to a scalar variable.
3869 If no procedure is active, then +'varName'+ refers to a global
3870 variable.
3872 If a procedure is active, then +'varName'+ refers to a parameter
3873 or local variable of the procedure, unless the +'global'+ command
3874 has been invoked to declare +'varName'+ to be global.
3876 The +::+ prefix may also be used to explicitly reference a variable
3877 in the global scope.
3879 setref
3880 ~~~~~~
3881 +*setref* 'reference string'+
3883 Store a new string in +'reference'+, replacing the existing string.
3884 The reference must be a valid reference create with the `ref`
3885 command.
3887 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
3889 signal
3890 ~~~~~~
3891 Command for signal handling.
3893 See `kill` for the different forms which may be used to specify signals.
3895 Commands which return a list of signal names do so using the canonical form:
3896 "+SIGINT SIGTERM+".
3898 +*signal handle* ?'signals \...'?+::
3899     If no signals are given, returns a list of all signals which are currently
3900     being handled.
3901     If signals are specified, these are added to the list of signals currently
3902     being handled.
3904 +*signal ignore* ?'signals \...'?+::
3905     If no signals are given, returns a lists all signals which are currently
3906     being ignored.
3907     If signals are specified, these are added to the list of signals
3908     currently being ignored. These signals are still delivered, but
3909     are not considered by `catch -signal` or `try -signal`. Use
3910     `signal check` to determine which signals have occurred but
3911     been ignored.
3913 +*signal block* ?'signals \...'?+::
3914     If no signals are given, returns a lists all signals which are currently
3915     being blocked.
3916     If signals are specified, these are added to the list of signals
3917     currently being blocked. These signals are not delivered to the process.
3918     This can be useful for signals such as +SIGPIPE+, especially in conjunction
3919     with `exec` as child processes inherit the parent's signal disposition.
3921 +*signal default* ?'signals \...'?+::
3922     If no signals are given, returns a lists all signals which currently have
3923     the default behaviour.
3924     If signals are specified, these are added to the list of signals which have
3925     the default behaviour.
3927 +*signal check ?-clear?* ?'signals \...'?+::
3928     Returns a list of signals which have been delivered to the process
3929     but are 'ignored'. If signals are specified, only that set of signals will
3930     be checked, otherwise all signals will be checked.
3931     If +-clear+ is specified, any signals returned are removed and will not be
3932     returned by subsequent calls to `signal check` unless delivered again.
3934 +*signal throw* ?'signal'?+::
3935     Raises the given signal, which defaults to +SIGINT+ if not specified.
3936     The behaviour is identical to:
3938 ----
3939     kill signal [pid]
3940 ----
3942 Note that `signal handle` and `signal ignore` represent two forms of signal
3943 handling. `signal handle` is used in conjunction with `catch -signal` or `try -signal`
3944 to immediately abort execution when the signal is delivered. Alternatively, `signal ignore`
3945 is used in conjunction with `signal check` to handle signal synchronously. Consider the
3946 two examples below.
3948 Prevent a processing from taking too long
3950 ----
3951     signal handle SIGALRM
3952     alarm 20
3953     try -signal {
3954         .. possibly long running process ..
3955         alarm 0
3956     } on signal {sig} {
3957         puts stderr "Process took too long"
3958     }
3959 ----
3961 Handle SIGHUP to reconfigure:
3963 ----
3964     signal ignore SIGHUP
3965     while {1} {
3966         ... handle configuration/reconfiguration ...
3967         while {[signal check -clear SIGHUP] eq ""} {
3968             ... do processing ..
3969         }
3970         # Received SIGHUP, so reconfigure
3971     }
3972 ----
3974 Note: signal handling is currently not supported in child interpreters.
3975 In these interpreters, the signal command does not exist.
3977 sleep
3978 ~~~~~
3979 +*sleep* 'seconds'+
3981 Pauses for the given number of seconds, which may be a floating
3982 point value less than one to sleep for less than a second, or an
3983 integer to sleep for one or more seconds.
3985 source
3986 ~~~~~~
3987 +*source* 'fileName'+
3989 Read file +'fileName'+ and pass the contents to the Tcl interpreter
3990 as a sequence of commands to execute in the normal fashion.  The return
3991 value of `source` is the return value of the last command executed
3992 from the file.  If an error occurs in executing the contents of the
3993 file, then the `source` command will return that error.
3995 If a `return` command is invoked from within the file, the remainder of
3996 the file will be skipped and the `source` command will return
3997 normally with the result from the `return` command.
3999 split
4000 ~~~~~
4001 +*split* 'string ?splitChars?'+
4003 Returns a list created by splitting +'string'+ at each character
4004 that is in the +'splitChars'+ argument.
4006 Each element of the result list will consist of the
4007 characters from +'string'+ between instances of the
4008 characters in +'splitChars'+.
4010 Empty list elements will be generated if +'string'+ contains
4011 adjacent characters in +'splitChars'+, or if the first or last
4012 character of +'string'+ is in +'splitChars'+.
4014 If +'splitChars'+ is an empty string then each character of
4015 +'string'+ becomes a separate element of the result list.
4017 +'splitChars'+ defaults to the standard white-space characters.
4018 For example,
4020 ----
4021     split "comp.unix.misc" .
4022 ----
4024 returns +'"comp unix misc"'+ and
4026 ----
4027     split "Hello world" {}
4028 ----
4030 returns +'"H e l l o { } w o r l d"'+.
4032 stackdump
4033 ~~~~~~~~~
4035 +*stackdump* 'stacktrace'+
4037 Creates a human readable representation of a stack trace.
4039 stacktrace
4040 ~~~~~~~~~~
4042 +*stacktrace*+
4044 Returns a live stack trace as a list of +proc file line proc file line \...+.
4045 Iteratively uses `info frame` to create the stack trace. This stack trace is in the
4046 same form as produced by `catch` and `info stacktrace`
4048 See also `stackdump`.
4050 string
4051 ~~~~~~
4053 +*string* 'option arg ?arg \...?'+
4055 Perform one of several string operations, depending on +'option'+.
4056 The legal options (which may be abbreviated) are:
4058 +*string bytelength* 'string'+::
4059     Returns the length of the string in bytes. This will return
4060     the same value as `string length` if UTF-8 support is not enabled,
4061     or if the string is composed entirely of ASCII characters.
4062     See <<_utf_8_and_unicode,UTF-8 AND UNICODE>>.
4064 +*string byterange* 'string first last'+::
4065     Like `string range` except works on bytes rather than characters.
4066     These commands are identical if UTF-8 support is not enabled.
4068 +*string cat* '?string1 string2 \...?'+::
4069     Concatenates the given strings into a single string.
4071 +*string compare ?-nocase?* ?*-length* 'len? string1 string2'+::
4072     Perform a character-by-character comparison of strings +'string1'+ and
4073     +'string2'+ in the same way as the C 'strcmp' procedure.  Return
4074     -1, 0, or 1, depending on whether +'string1'+ is lexicographically
4075     less than, equal to, or greater than +'string2'+. If +-length+
4076     is specified, then only the first +'len'+ characters are used
4077     in the comparison.  If +'len'+ is negative, it is ignored.
4078     Performs a case-insensitive comparison if +-nocase+ is specified.
4080 +*string equal ?-nocase?* '?*-length* len?' 'string1 string2'+::
4081     Returns 1 if the strings are equal, or 0 otherwise. If +-length+
4082     is specified, then only the first +'len'+ characters are used
4083     in the comparison.  If +'len'+ is negative, it is ignored.
4084     Performs a case-insensitive comparison if +-nocase+ is specified.
4086 +*string first* 'string1 string2 ?firstIndex?'+::
4087     Search +'string2'+ for a sequence of characters that exactly match
4088     the characters in +'string1'+.  If found, return the index of the
4089     first character in the first such match within +'string2'+.  If not
4090     found, return -1. If +'firstIndex'+ is specified, matching will start
4091     from +'firstIndex'+ of +'string1'+.
4092  ::
4093     See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'firstIndex'+.
4095 +*string index* 'string charIndex'+::
4096     Returns the +'charIndex'+'th character of the +'string'+
4097     argument.  A +'charIndex'+ of 0 corresponds to the first
4098     character of the string.
4099     If +'charIndex'+ is less than 0 or greater than
4100     or equal to the length of the string then an empty string is
4101     returned.
4102  ::
4103     See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'charIndex'+.
4105 +*string is* 'class' ?*-strict*? 'string'+::
4106     Returns 1 if +'string'+ is a valid member of the specified character
4107     class, otherwise returns 0. If +-strict+ is specified, then an
4108     empty string returns 0, otherwise an empty string will return 1
4109     on any class. The following character classes are recognized
4110     (the class name can be abbreviated):
4111   ::
4112   +alnum+;;  Any alphabet or digit character.
4113   +alpha+;;  Any alphabet character.
4114   +ascii+;;  Any character with a value less than 128 (those that are in the 7-bit ascii range).
4115   +boolean+;;  Any of the valid string formats for a boolean value in Tcl (0, false, no, off, 1, true, yes, on)
4116   +control+;; Any control character.
4117   +digit+;;  Any digit character.
4118   +double+;; Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
4119              In case of under/overflow in the value, 0 is returned.
4120   +graph+;;  Any printing character, except space.
4121   +integer+;; Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
4122   +lower+;;  Any lower case alphabet character.
4123   +print+;;  Any printing character, including space.
4124   +punct+;;  Any punctuation character.
4125   +space+;;  Any space character.
4126   +upper+;;  Any upper case alphabet character.
4127   +xdigit+;; Any hexadecimal digit character ([0-9A-Fa-f]).
4128  ::
4129     Note that string classification does +'not'+ respect UTF-8. See <<_utf_8_and_unicode,UTF-8 AND UNICODE>>.
4130  ::
4131     Note that only +'lowercase'+ boolean values are recognized (Tcl accepts any case).
4133 +*string last* 'string1 string2 ?lastIndex?'+::
4134     Search +'string2'+ for a sequence of characters that exactly match
4135     the characters in +'string1'+.  If found, return the index of the
4136     first character in the last such match within +'string2'+.  If there
4137     is no match, then return -1. If +'lastIndex'+ is specified, only characters
4138     up to +'lastIndex'+ of +'string2'+ will be considered in the match.
4139  ::
4140     See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'lastIndex'+.
4142 +*string length* 'string'+::
4143     Returns a decimal string giving the number of characters in +'string'+.
4144     If UTF-8 support is enabled, this may be different than the number of bytes.
4145     See <<_utf_8_and_unicode,UTF-8 AND UNICODE>>.
4147 +*string map ?-nocase?* 'mapping string'+::
4148     Replaces substrings in +'string'+ based on the key-value pairs in
4149     +'mapping'+, which is a list of +key value key value \...+ as in the form
4150     returned by `array get`. Each instance of a key in the string will be
4151     replaced with its corresponding value.  If +-nocase+ is specified, then
4152     matching is done without regard to case differences. Both key and value may
4153     be multiple characters.  Replacement is done in an ordered manner, so the
4154     key appearing first in the list will be checked first, and so on. +'string'+ is
4155     only iterated over once, so earlier key replacements will have no affect for
4156     later key matches. For example,
4158 ----
4159       string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc
4160 ----
4162  ::
4163     will return the string +01321221+.
4164  ::
4165     Note that if an earlier key is a prefix of a later one, it will completely mask the later
4166     one.  So if the previous example is reordered like this,
4168 ----
4169       string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc
4170 ----
4172  ::
4173     it will return the string +02c322c222c+.
4175 +*string match ?-nocase?* 'pattern string'+::
4176     See if +'pattern'+ matches +'string'+; return 1 if it does, 0
4177     if it doesn't.  Matching is done in a fashion similar to that
4178     used by the C-shell.  For the two strings to match, their contents
4179     must be identical except that the following special sequences
4180     may appear in +'pattern'+:
4182     +*+;;
4183         Matches any sequence of characters in +'string'+,
4184         including a null string.
4186     +?+;;
4187         Matches any single character in +'string'+.
4189     +['chars']+;;
4190         Matches any character in the set given by +'chars'+.
4191         If a sequence of the form +'x-y'+ appears in +'chars'+,
4192         then any character between +'x'+ and +'y'+, inclusive,
4193         will match.
4195     +{backslash}x+;;
4196         Matches the single character +'x'+.  This provides a way of
4197         avoiding the special interpretation of the characters +{backslash}*?[]+
4198         in +'pattern'+.
4199  ::
4200     Performs a case-insensitive comparison if +-nocase+ is specified.
4202 +*string range* 'string first last'+::
4203     Returns a range of consecutive characters from +'string'+, starting
4204     with the character whose index is +'first'+ and ending with the
4205     character whose index is +'last'+.  An index of 0 refers to the
4206     first character of the string.
4207  ::
4208     See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'first'+ and +'last'+.
4209  ::
4210     If +'first'+ is less than zero then it is treated as if it were zero, and
4211     if +'last'+ is greater than or equal to the length of the string then
4212     it is treated as if it were +end+.  If +'first'+ is greater than
4213     +'last'+ then an empty string is returned.
4215 +*string repeat* 'string count'+::
4216     Returns a new string consisting of +'string'+ repeated +'count'+ times.
4218 +*string replace* 'string first last ?newstring?'+::
4219     Removes a range of consecutive characters from +'string'+, starting
4220     with the character whose index is +'first'+ and ending with the
4221     character whose index is +'last'+.  If +'newstring'+ is specified,
4222     then it is placed in the removed character range. If +'first'+ is
4223     less than zero then it is treated as if it were zero, and if +'last'+
4224     is greater than or equal to the length of the string then it is
4225     treated as if it were +end+. If +'first'+ is greater than +'last'+
4226     or the length of the initial string, or +'last'+ is less than 0,
4227     then the initial string is returned untouched.
4229 +*string reverse* 'string'+::
4230     Returns a string that is the same length as +'string'+ but
4231     with its characters in the reverse order.
4233 +*string tolower* 'string'+::
4234     Returns a value equal to +'string'+ except that all upper case
4235     letters have been converted to lower case.
4237 +*string totitle* 'string'+::
4238     Returns a value equal to +'string'+ except that the first character
4239     is converted to title case (or upper case if there is no UTF-8 titlecase variant)
4240     and all remaining characters have been converted to lower case.
4242 +*string toupper* 'string'+::
4243     Returns a value equal to +'string'+ except that all lower case
4244     letters have been converted to upper case.
4246 +*string trim* 'string ?chars?'+::
4247     Returns a value equal to +'string'+ except that any leading
4248     or trailing characters from the set given by +'chars'+ are
4249     removed.
4250     If +'chars'+ is not specified then white space is removed
4251     (spaces, tabs, newlines, and carriage returns).
4253 +*string trimleft* 'string ?chars?'+::
4254     Returns a value equal to +'string'+ except that any
4255     leading characters from the set given by +'chars'+ are
4256     removed.
4257     If +'chars'+ is not specified then white space is removed
4258     (spaces, tabs, newlines, and carriage returns).
4260 +*string trimright* 'string ?chars?'+::
4261     Returns a value equal to +'string'+ except that any
4262     trailing characters from the set given by +'chars'+ are
4263     removed.
4264     If +'chars'+ is not specified then white space is removed
4265     (spaces, tabs, newlines, and carriage returns).
4266     Null characters are always removed.
4268 subst
4269 ~~~~~
4270 +*subst ?-nobackslashes? ?-nocommands? ?-novariables?* 'string'+
4272 This command performs variable substitutions, command substitutions,
4273 and backslash substitutions on its string argument and returns the
4274 fully-substituted result. The substitutions are performed in exactly
4275 the same way as for Tcl commands. As a result, the string argument
4276 is actually substituted twice, once by the Tcl parser in the usual
4277 fashion for Tcl commands, and again by the subst command.
4279 If any of the +-nobackslashes+, +-nocommands+, or +-novariables+ are
4280 specified, then the corresponding substitutions are not performed.
4281 For example, if +-nocommands+ is specified, no command substitution
4282 is performed: open and close brackets are treated as ordinary
4283 characters with no special interpretation.
4285 *Note*: when it performs its substitutions, subst does not give any
4286 special treatment to double quotes or curly braces. For example,
4287 the following script returns +xyz \{44\}+, not +xyz \{$a\}+.
4289 ----
4290     set a 44
4291     subst {xyz {$a}}
4292 ----
4295 switch
4296 ~~~~~~
4297 +*switch* '?options? string pattern body ?pattern body \...?'+
4299 +*switch* '?options? string {pattern body ?pattern body \...?}'+
4301 The `switch` command matches its string argument against each of
4302 the pattern arguments in order. As soon as it finds a pattern that
4303 matches string it evaluates the following body and returns the
4304 result of that evaluation. If the last pattern argument is default
4305 then it matches anything. If no pattern argument matches string and
4306 no default is given, then the `switch` command returns an empty string.
4307 If the initial arguments to switch start with - then they are treated
4308 as options. The following options are currently supported:
4310     +-exact+::
4311         Use exact matching when comparing string to a
4312         pattern. This is the default.
4314     +-glob+::
4315         When matching string to the patterns, use glob-style
4316         matching (i.e. the same as implemented by the string
4317         match command).
4319     +-regexp+::
4320         When matching string to the patterns, use regular
4321         expression matching (i.e. the same as implemented
4322         by the regexp command).
4324     +-command 'commandname'+::
4325         When matching string to the patterns, use the given command, which
4326         must be a single word. The command is invoked as
4327         'commandname pattern string', or 'commandname -nocase pattern string'
4328         and must return 1 if matched, or 0 if not.
4330     +--+::
4331         Marks the end of options. The argument following
4332         this one will be treated as string even if it starts
4333         with a +-+.
4335 Two syntaxes are provided for the pattern and body arguments. The
4336 first uses a separate argument for each of the patterns and commands;
4337 this form is convenient if substitutions are desired on some of the
4338 patterns or commands. The second form places all of the patterns
4339 and commands together into a single argument; the argument must
4340 have proper list structure, with the elements of the list being the
4341 patterns and commands. The second form makes it easy to construct
4342 multi-line `switch` commands, since the braces around the whole list
4343 make it unnecessary to include a backslash at the end of each line.
4344 Since the pattern arguments are in braces in the second form, no
4345 command or variable substitutions are performed on them; this makes
4346 the behaviour of the second form different than the first form in
4347 some cases.
4349 If a body is specified as +-+ it means that the body for the next
4350 pattern should also be used as the body for this pattern (if the
4351 next pattern also has a body of +-+ then the body after that is
4352 used, and so on). This feature makes it possible to share a single
4353 body among several patterns.
4355 Below are some examples of `switch` commands:
4357 ----
4358     switch abc a - b {format 1} abc {format 2} default {format 3}
4359 ----
4361 will return 2,
4363 ----
4364     switch -regexp aaab {
4365            ^a.*b$ -
4366            b {format 1}
4367            a* {format 2}
4368            default {format 3}
4369     }
4370 ----
4372 will return 1, and
4374 ----
4375     switch xyz {
4376            a -
4377            b {format 1}
4378            a* {format 2}
4379            default {format 3}
4380     }
4381 ----
4383 will return 3.
4385 tailcall
4386 ~~~~~~~~
4387 +*tailcall* 'cmd ?arg\...?'+
4389 The `tailcall` command provides an optimised way of invoking a command whilst replacing
4390 the current call frame. This is similar to 'exec' in Bourne Shell.
4392 The following are identical except the first immediately replaces the current call frame.
4394 ----
4395   tailcall a b c
4396 ----
4398 ----
4399   return [uplevel 1 [list a b c]]
4400 ----
4402 `tailcall` is useful as a dispatch mechanism:
4404 ----
4405   proc a {cmd args} {
4406     tailcall sub_$cmd {*}$args
4407   }
4408   proc sub_cmd1 ...
4409   proc sub_cmd2 ...
4410 ----
4412 tell
4413 ~~~~
4414 +*tell* 'fileId'+
4416 +'fileId' *tell*+
4418 Returns a decimal string giving the current access position in
4419 +'fileId'+.
4421 +'fileId'+ must have been the return value from a previous call to
4422 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
4423 of the standard I/O channels.
4425 throw
4426 ~~~~~
4427 +*throw* 'code ?msg?'+
4429 This command throws an exception (return) code along with an optional message.
4430 This command is mostly for convenient usage with `try`.
4432 The command +throw break+ is equivalent to +break+.
4433 The command +throw 20 message+ can be caught with an +on 20 \...+ clause to `try`.
4435 time
4436 ~~~~
4437 +*time* 'command ?count?'+
4439 This command will call the Tcl interpreter +'count'+
4440 times to execute +'command'+ (or once if +'count'+ isn't
4441 specified).  It will then return a string of the form
4443 ----
4444     503 microseconds per iteration
4445 ----
4447 which indicates the average amount of time required per iteration,
4448 in microseconds.
4450 Time is measured in elapsed time, not CPU time.
4454 +*try* '?catchopts? tryscript' ?*on* 'returncodes {?resultvar? ?optsvar?} handlerscript \...'? ?*finally* 'finalscript'?+
4456 The `try` command is provided as a convenience for exception handling.
4458 This interpeter first evaluates +'tryscript'+ under the effect of the catch
4459 options +'catchopts'+ (e.g. +-signal -noexit --+, see `catch`).
4461 It then evaluates the script for the first matching 'on' handler
4462 (there many be zero or more) based on the return code from the `try`
4463 section. For example a normal +JIM_ERR+ error will be matched by
4464 an 'on error' handler.
4466 Finally, any +'finalscript'+ is evaluated.
4468 The result of this command is the result of +'tryscript'+, except in the
4469 case where an exception occurs in a matching 'on' handler script or the 'finally' script,
4470 in which case the result is this new exception.
4472 The specified +'returncodes'+ is a list of return codes either as names ('ok', 'error', 'break', etc.)
4473 or as integers.
4475 If +'resultvar'+ and +'optsvar'+ are specified, they are set as for `catch` before evaluating
4476 the matching handler.
4478 For example:
4480 ----
4481     set f [open input]
4482     try -signal {
4483         process $f
4484     } on {continue break} {} {
4485         error "Unexpected break/continue"
4486     } on error {msg opts} {
4487         puts "Dealing with error"
4488         return {*}$opts $msg
4489     } on signal sig {
4490         puts "Got signal: $sig"
4491     } finally {
4492         $f close
4493     }
4494 ----
4496 If break, continue or error are raised, they are dealt with by the matching
4497 handler.
4499 In any case, the file will be closed via the 'finally' clause.
4501 See also `throw`, `catch`, `return`, `error`.
4503 unknown
4504 ~~~~~~~
4505 +*unknown* 'cmdName ?arg arg ...?'+
4507 This command doesn't actually exist as part of Tcl, but Tcl will
4508 invoke it if it does exist.
4510 If the Tcl interpreter encounters a command name for which there
4511 is not a defined command, then Tcl checks for the existence of
4512 a command named `unknown`.
4514 If there is no such command, then the interpreter returns an
4515 error.
4517 If the `unknown` command exists, then it is invoked with
4518 arguments consisting of the fully-substituted name and arguments
4519 for the original non-existent command.
4521 The `unknown` command typically does things like searching
4522 through library directories for a command procedure with the name
4523 +'cmdName'+, or expanding abbreviated command names to full-length,
4524 or automatically executing unknown commands as UNIX sub-processes.
4526 In some cases (such as expanding abbreviations) `unknown` will
4527 change the original command slightly and then (re-)execute it.
4528 The result of the `unknown` command is used as the result for
4529 the original non-existent command.
4531 unset
4532 ~~~~~
4533 +*unset ?-nocomplain? ?--?* '?name name ...?'+
4535 Remove variables.
4536 Each +'name'+ is a variable name, specified in any of the
4537 ways acceptable to the `set` command.
4539 If a +'name'+ refers to an element of an array, then that
4540 element is removed without affecting the rest of the array.
4542 If a +'name'+ consists of an array name with no parenthesized
4543 index, then the entire array is deleted.
4545 The `unset` command returns an empty string as result.
4547 An error occurs if any of the variables doesn't exist, unless '-nocomplain'
4548 is specified. The '--' argument may be specified to stop option processing
4549 in case the variable name may be '-nocomplain'.
4551 upcall
4552 ~~~~~~~
4553 +*upcall* 'command ?args ...?'+
4555 May be used from within a proc defined as `local` `proc` in order to call
4556 the previous, hidden version of the same command.
4558 If there is no previous definition of the command, an error is returned.
4560 uplevel
4561 ~~~~~~~
4562 +*uplevel* '?level? command ?command ...?'+
4564 All of the +'command'+ arguments are concatenated as if they had
4565 been passed to `concat`; the result is then evaluated in the
4566 variable context indicated by +'level'+.  `uplevel` returns
4567 the result of that evaluation.  If +'level'+ is an integer, then
4568 it gives a distance (up the procedure calling stack) to move before
4569 executing the command.  If +'level'+ consists of +\#+ followed by
4570 a number then the number gives an absolute level number.  If +'level'+
4571 is omitted then it defaults to +1+.  +'level'+ cannot be
4572 defaulted if the first +'command'+ argument starts with a digit or +#+.
4574 For example, suppose that procedure 'a' was invoked
4575 from top-level, and that it called 'b', and that 'b' called 'c'.
4576 Suppose that 'c' invokes the `uplevel` command.  If +'level'+
4577 is +1+ or +#2+  or omitted, then the command will be executed
4578 in the variable context of 'b'.  If +'level'+ is +2+ or +#1+
4579 then the command will be executed in the variable context of 'a'.
4581 If +'level'+ is '3' or +#0+ then the command will be executed
4582 at top-level (only global variables will be visible).
4583 The `uplevel` command causes the invoking procedure to disappear
4584 from the procedure calling stack while the command is being executed.
4585 In the above example, suppose 'c' invokes the command
4587 ----
4588     uplevel 1 {set x 43; d}
4589 ----
4591 where 'd' is another Tcl procedure.  The `set` command will
4592 modify the variable 'x' in 'b's context, and 'd' will execute
4593 at level 3, as if called from 'b'.  If it in turn executes
4594 the command
4596 ----
4597     uplevel {set x 42}
4598 ----
4600 then the `set` command will modify the same variable 'x' in 'b's
4601 context:  the procedure 'c' does not appear to be on the call stack
4602 when 'd' is executing.  The command `info level` may
4603 be used to obtain the level of the current procedure.
4605 `uplevel` makes it possible to implement new control
4606 constructs as Tcl procedures (for example, `uplevel` could
4607 be used to implement the `while` construct as a Tcl procedure).
4609 upvar
4610 ~~~~~
4611 +*upvar* '?level? otherVar myVar ?otherVar myVar ...?'+
4613 This command arranges for one or more local variables in the current
4614 procedure to refer to variables in an enclosing procedure call or
4615 to global variables.
4617 +'level'+ may have any of the forms permitted for the `uplevel`
4618 command, and may be omitted if the first letter of the first +'otherVar'+
4619 isn't +#+ or a digit (it defaults to '1').
4621 For each +'otherVar'+ argument, `upvar` makes the variable
4622 by that name in the procedure frame given by +'level'+ (or at
4623 global level, if +'level'+ is +#0+) accessible
4624 in the current procedure by the name given in the corresponding
4625 +'myVar'+ argument.
4627 The variable named by +'otherVar'+ need not exist at the time of the
4628 call;  it will be created the first time +'myVar'+ is referenced, just like
4629 an ordinary variable.
4631 `upvar` may only be invoked from within procedures.
4633 `upvar` returns an empty string.
4635 The `upvar` command simplifies the implementation of call-by-name
4636 procedure calling and also makes it easier to build new control constructs
4637 as Tcl procedures.
4638 For example, consider the following procedure:
4640 ----
4641     proc add2 name {
4642         upvar $name x
4643         set x [expr $x+2]
4644     }
4645 ----
4647 'add2' is invoked with an argument giving the name of a variable,
4648 and it adds two to the value of that variable.
4649 Although 'add2' could have been implemented using `uplevel`
4650 instead of `upvar`, `upvar` makes it simpler for 'add2'
4651 to access the variable in the caller's procedure frame.
4653 wait
4654 ~~~~
4655 +*wait*+
4657 +*wait -nohang* 'pid'+
4659 With no arguments, cleans up any processes started by `exec ... &` that have completed
4660 (reaps zombie processes).
4662 With one or two arguments, waits for a process by id, either returned by `exec ... &`
4663 or by `os.fork` (if supported).
4665 Waits for the process to complete, unless +-nohang+ is specified, in which case returns
4666 immediately if the process is still running.
4668 Returns a list of 3 elements.
4670 +{NONE x x}+ if the process does not exist or has already been waited for, or
4671 if -nohang is specified, and the process is still alive.
4673 +{CHILDSTATUS <pid> <exit-status>}+ if the process exited normally.
4675 +{CHILDKILLED <pid> <signal>}+ if the process terminated on a signal.
4677 +{CHILDSUSP <pid> none}+ if the process terminated for some other reason.
4679 Note that on platforms supporting waitpid(2), +pid+ can also be given special values such
4680 as 0 or -1. See waitpid(2) for more detail.
4682 while
4683 ~~~~~
4684 +*while* 'test body'+
4686 The +'while'+ command evaluates +'test'+ as an expression
4687 (in the same way that `expr` evaluates its argument).
4688 The value of the expression must be numeric; if it is non-zero
4689 then +'body'+ is executed by passing it to the Tcl interpreter.
4691 Once +'body'+ has been executed then +'test'+ is evaluated
4692 again, and the process repeats until eventually +'test'+
4693 evaluates to a zero numeric value.  `continue`
4694 commands may be executed inside +'body'+ to terminate the current
4695 iteration of the loop, and `break`
4696 commands may be executed inside +'body'+ to cause immediate
4697 termination of the `while` command.
4699 The `while` command always returns an empty string.
4701 OPTIONAL-EXTENSIONS
4702 -------------------
4704 The following extensions may or may not be available depending upon
4705 what options were selected when Jim Tcl was built.
4708 [[cmd_1]]
4709 posix: os.fork, os.gethostname, os.getids, os.uptime
4710 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4711 +*os.fork*+::
4712     Invokes 'fork(2)' and returns the result.
4714 +*os.gethostname*+::
4715     Invokes 'gethostname(3)' and returns the result.
4717 +*os.getids*+::
4718     Returns the various user/group ids for the current process.
4720 ----
4721     . os.getids
4722     uid 1000 euid 1000 gid 100 egid 100
4723 ----
4725 +*os.uptime*+::
4726     Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.
4728 ANSI I/O (aio) and EVENTLOOP API
4729 --------------------------------
4730 Jim provides an alternative object-based API for I/O.
4732 See `open` and `socket` for commands which return an I/O handle.
4736 +$handle *accept* ?addrvar?+::
4737     Server socket only: Accept a connection and return stream.
4738     If +'addrvar'+ is specified, the address of the connected client is stored
4739     in the named variable in the form 'addr:port' for IP sockets or 'path' for Unix domain sockets.
4740     See `socket` for details.
4742 +$handle *buffering none|line|full*+::
4743     Sets the buffering mode of the stream.
4745 +$handle *close ?r(ead)|w(rite)|-nodelete?*+::
4746     Closes the stream.
4747     The +'read'+ and +'write'+ arguments perform a "half-close" on a socket. See the 'shutdown(2)' man page.
4748     The +'-nodelete'+ option is applicable only for Unix domain sockets. It closes the socket
4749     but does not delete the bound path (e.g. after `os.fork`).
4752 +$handle *copyto* 'tofd ?size?'+::
4753     Copy bytes to the file descriptor +'tofd'+. If +'size'+ is specified, at most
4754     that many bytes will be copied. Otherwise copying continues until the end
4755     of the input file. Returns the number of bytes actually copied.
4757 +$handle *eof*+::
4758     Returns 1 if stream is at eof
4760 +$handle *filename*+::
4761     Returns the original filename associated with the handle.
4762     Handles returned by `socket` give the socket type instead of a filename.
4764 +$handle *flush*+::
4765     Flush the stream
4767 +$handle *gets* '?var?'+::
4768     Read one line and return it or store it in the var
4770 +$handle *isatty*+::
4771     Returns 1 if the stream is a tty device.
4773 +$handle *lock ?-wait?*+::
4774     Apply a POSIX lock to the open file associated with the handle using
4775     'fcntl(F_SETLK)', or 'fcntl(F_SETLKW)' to wait for the lock to be available if +'-wait'+
4776     is specified.
4777     The handle must be open for write access.
4778     Returns 1 if the lock was successfully obtained, 0 otherwise.
4779     An error occurs if the handle is not suitable for locking (e.g.
4780     if it is not open for write)
4782 +$handle *ndelay ?0|1?*+::
4783     Set O_NDELAY (if arg). Returns current/new setting.
4784     Note that in general ANSI I/O interacts badly with non-blocking I/O.
4785     Use with care.
4787 +$handle *peername*+::
4788     Returns the remote address or path of the connected socket. See 'getpeername(2)'.
4790 +$handle *puts ?-nonewline?* 'str'+::
4791     Write the string, with newline unless -nonewline
4793 +$handle *read ?-nonewline?* '?len?'+::
4794     Read and return bytes from the stream. To eof if no len.
4796 +$handle *recvfrom* 'maxlen ?addrvar?'+::
4797     Receives a message from the handle via recvfrom(2) and returns it.
4798     At most +'maxlen'+ bytes are read. If +'addrvar'+ is specified, the sending address
4799     of the message is stored in the named variable in the form 'addr:port' for IP sockets
4800     or 'path' for Unix domain sockets. See `socket` for details.
4802 +$handle *seek* 'offset' *?start|current|end?*+::
4803     Seeks in the stream (default 'current')
4805 +$handle *sendto* 'str ?address'+::
4806     Sends the string, +'str'+, to the given address (host:port or path) via the socket using 'sendto(2)'.
4807     This is intended for udp/dgram sockets and may give an error or behave in unintended
4808     ways for other handle types.
4809     Returns the number of bytes written.
4811 +$handle *sockname*+::
4812     Returns the bound address or path of the socket. See 'getsockname(2)'.
4814 +$handle *sockopt* '?name value?'+::
4815     With no arguments, returns a dictionary of socket options currently set for the handle
4816     (will be empty for a non-socket). With +'name'+ and +'value'+, sets the socket option
4817     to the given value. Currently supports the following boolean socket options:
4818     +broadcast, debug, keepalive, nosigpipe, oobinline, tcp_nodelay+, and the following
4819     integer socket options: +sndbuf, rcvbuf+
4821 +$handle *sync*+::
4822     Flush the stream, then 'fsync(2)' to commit any changes to storage.
4823     Only available on platforms that support 'fsync(2)'.
4825 +$handle *tell*+::
4826     Returns the current seek position
4828 +$handle *tty* ?settings?+::
4829     If no arguments are given, returns a dictionary containing the tty settings for the stream.
4830     If arguments are given, they must either be a dictionary, or +setting value \...+
4831     Abbrevations are supported for both settings and values, so the following is acceptable:
4832     +$f tty parity e input c out raw+.
4833     Only available on platforms that support 'termios(3)'. Supported settings are:
4835     +*baud* 'rate'+;;
4836         Baud rate. e.g. 115200
4838     +*data 5|6|7|8*+;;
4839         Number of data bits
4841     +*stop 1|2*+;;
4842         Number of stop bits
4844     +*parity even|odd|none*+;;
4845         Parity setting
4847     +*handshake xonxoff|rtscts|none*+;;
4848         Handshaking type
4850     +*input raw|cooked*+;;
4851         Input character processing. In raw mode, the usual key sequences such as ^C do
4852         not generate signals.
4854     +*output raw|cooked*+;;
4855         Output character processing. Typically CR -> CRNL is disabled in raw mode.
4857     +*vmin* 'numchars'+;;
4858         Minimum number of characters to read.
4860     +*vtime* 'time'+;;
4861         Timeout for noncanonical read (units of 0.1 seconds)
4863 +$handle *ssl* ?*-server* 'cert priv'?+::
4864     Upgrades the stream to a SSL/TLS session and returns the handle.
4866 +$handle *unlock*+::
4867     Release a POSIX lock previously acquired by `aio lock`.
4869 +$handle *verify*+::
4870     Verifies the certificate of a SSL/TLS stream peer
4872 +*load_ssl_certs* 'dir'+::
4873     Loads SSL/TLS CA certificates for use during verification
4875 fconfigure
4876 ~~~~~~~~~~
4877 +*fconfigure* 'handle' *?-blocking 0|1? ?-buffering noneline|full? ?-translation* 'mode'?+::
4878     For compatibility with Tcl, a limited form of the `fconfigure`
4879     command is supported.
4880     * `fconfigure ... -blocking` maps to `aio ndelay`
4881     * `fconfigure ... -buffering` maps to `aio buffering`
4882     * `fconfigure ... -translation` is accepted but ignored
4884 [[cmd_2]]
4885 eventloop: after, vwait, update
4886 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4888 The following commands allow a script to be invoked when the given condition occurs.
4889 If no script is given, returns the current script. If the given script is the empty, the
4890 handler is removed.
4892 +$handle *readable* '?readable-script?'+::
4893     Sets or returns the script for when the socket is readable.
4895 +$handle *writable* '?writable-script?'+::
4896     Sets or returns the script for when the socket is writable.
4898 +$handle *onexception* '?exception-script?'+::
4899     Sets or returns the script for when oob data received.
4901 For compatibility with 'Tcl', these may be prefixed with `fileevent`.  e.g.
4903  ::
4904     +fileevent $handle *readable* '\...'+
4906 Time-based execution is also available via the eventloop API.
4908 +*after* 'ms'+::
4909     Sleeps for the given number of milliseconds. No events are
4910     processed during this time.
4912 +*after* 'ms'|*idle* 'script ?script \...?'+::
4913     The scripts are concatenated and executed after the given
4914     number of milliseconds have elapsed.  If 'idle' is specified,
4915     the script will run the next time the event loop is processed
4916     with `vwait` or `update`. The script is only run once and
4917     then removed.  Returns an event id.
4919 +*after cancel* 'id|command'+::
4920     Cancels an `after` event with the given event id or matching
4921     command (script).  Returns the number of milliseconds
4922     remaining until the event would have fired.  Returns the
4923     empty string if no matching event is found.
4925 +*after info* '?id?'+::
4926     If +'id'+ is not given, returns a list of current `after`
4927     events.  If +'id'+ is given, returns a list containing the
4928     associated script and either 'timer' or 'idle' to indicated
4929     the type of the event. An error occurs if +'id'+ does not
4930     match an event.
4932 +*vwait* 'variable'+::
4933     A call to `vwait` enters the eventloop. `vwait` processes
4934     events until the named (global) variable changes or all
4935     event handlers are removed. The variable need not exist
4936     beforehand.  If there are no event handlers defined, `vwait`
4937     returns immediately.
4939 +*update ?idletasks?*+::
4940     A call to `update` enters the eventloop to process expired events, but
4941     no new events. If 'idletasks' is specified, only expired time events are handled,
4942     not file events.
4943     Returns once handlers have been run for all expired events.
4945 Scripts are executed at the global scope. If an error occurs during a handler script,
4946 an attempt is made to call (the user-defined command) `bgerror` with the details of the error.
4947 If the `bgerror` command does not exist, the error message details are printed to stderr instead.
4949 If a file event handler script generates an error, the handler is automatically removed
4950 to prevent infinite errors. (A time event handler is always removed after execution).
4952 +*bgerror* 'msg'+::
4953     Called when an event handler script generates an error. Note that the normal command resolution
4954     rules are used for bgerror. First the name is resolved in the current namespace, then in the
4955     global scope.
4957 socket
4958 ~~~~~~
4959 Various socket types may be created.
4961 +*socket unix* 'path'+::
4962     A unix domain socket client connected to 'path'
4964 +*socket unix.server* 'path'+::
4965     A unix domain socket server listening on 'path'
4967 +*socket unix.dgram* '?path?'+::
4968     A unix domain socket datagram client, optionally connected to 'path'
4970 +*socket unix.dgram.server* 'path'+::
4971     A unix domain socket datagram server server listening on 'path'
4973 +*socket ?-ipv6? stream* 'addr:port'+::
4974     A TCP socket client. (See the forms for +'addr'+ below)
4976 +*socket ?-ipv6? stream.server* '?addr:?port'+::
4977     A TCP socket server (+'addr'+ defaults to +0.0.0.0+ for IPv4 or +[::]+ for IPv6).
4979 +*socket ?-ipv6? dgram* ?'addr:port'?+::
4980     A UDP socket client. If the address is not specified,
4981     the client socket will be unbound and 'sendto' must be used
4982     to indicated the destination.
4984 +*socket ?-ipv6? dgram.server* 'addr:port'+::
4985     A UDP socket server.
4987 +*socket pipe*+::
4988     A synonym for `pipe`
4990 +*socket pair*+::
4991     A socketpair (see socketpair(2)). Like `pipe`, this command returns
4992     a list of two channels: {s1 s2}. These channels are both readable and writable.
4994 This command creates a socket connected (client) or bound (server) to the given
4995 address.
4997 The returned value is channel and may generally be used with the various file I/O
4998 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.
5000 ----
5001     . set f [socket stream www.google.com:80]
5002     aio.sockstream1
5003     . $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
5004     . $f gets
5005     HTTP/1.0 302 Found
5006     . $f close
5007 ----
5009 Server sockets, however support only 'accept', which is most useful in conjunction with
5010 the EVENTLOOP API.
5012 ----
5013     set f [socket stream.server 80]
5014     $f readable {
5015         set client [$f accept]
5016         $client gets $buf
5017         ...
5018         $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
5019         $client close
5020     }
5021     vwait done
5022 ----
5024 The address, +'addr'+, can be given in one of the following forms:
5026 1. For IPv4 socket types, an IPv4 address such as 192.168.1.1
5027 2. For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
5028 3. A hostname
5030 Note that on many systems, listening on an IPv6 address such as [::] will
5031 also accept requests via IPv4.
5033 Where a hostname is specified, the +'first'+ returned address is used
5034 which matches the socket type is used.
5036 An unconnected dgram socket (either 'dgram' or 'unix.dgram') must use
5037 `sendto` to specify the destination address.
5039 The path for Unix domain sockets is automatically removed when the socket
5040 is closed. Use `close -nodelete` in the rare case where this behaviour
5041 should be avoided (e.g. after `os.fork`).
5043 syslog
5044 ~~~~~~
5045 +*syslog* '?options? ?priority? message'+
5047 This  command sends message to system syslog facility with given
5048 priority. Valid priorities are:
5050     emerg, alert, crit, err, error, warning, notice, info, debug
5052 If a message is specified, but no priority is specified, then a
5053 priority of info is used.
5055 By default, facility user is used and the value of global tcl variable
5056 argv0 is used as ident string. However, any of the following options
5057 may be specified before priority to control these parameters:
5059 +*-facility* 'value'+::
5060     Use specified facility instead of user. The following
5061     values for facility are recognized:
5063     authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
5064     uucp, local0-local7
5066 +*-ident* 'string'+::
5067     Use given string instead of argv0 variable for ident string.
5069 +*-options* 'integer'+::
5070     Set syslog options such as +LOG_CONS+, +LOG_NDELAY+. You should
5071     use numeric values of those from your system syslog.h file,
5072     because I haven't got time to implement yet another hash
5073     table.
5075 pack: pack, unpack
5076 ~~~~~~~~~~~~~~~~~~
5077 The optional 'pack' extension provides commands to encode and decode binary strings.
5079 +*pack* 'varName value' *-intle|-intbe|-floatle|-floatbe|-str* 'bitwidth ?bitoffset?'+::
5080     Packs the binary representation of +'value'+ into the variable
5081     +'varName'+. The value is packed according to the given type
5082     (integer/floating point/string, big-endian/little-endian), width and bit offset.
5083     The variable is created if necessary (like `append`).
5084     The variable is expanded if necessary.
5086 +*unpack* 'binvalue' *-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str* 'bitpos bitwidth'+::
5087     Unpacks bits from +'binvalue'+ at bit position +'bitpos'+ and with +'bitwidth'+.
5088     Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
5089     and signed/unsigned) and returns it. For integer types, +'bitwidth'+
5090     may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
5091     +'bitwidth'+ may be 32 bits (for single precision numbers) or 64 bits (for double precision).
5092     For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
5093     access outside the length of the value will return 0 for integer types, 0.0 for floating point types
5094     or the empty string for the string type.
5096 zlib
5097 ~~~~
5098 The optional 'zlib' extension provides a Tcl-compatible subset of the `zlib` command.
5100 +*crc32* 'data' '?startValue?'+::
5101     Returns the CRC32 checksum of a buffer. Optionally, an initial value may be specified; this is most useful
5102     for calculating the checksum of chunked data read from a stream (for instance, a pipe).
5104 +*deflate* 'string' '?level?'+::
5105     Compresses a buffer and outputs a raw, Deflate-compressed stream. Optionally, a compression level (1-9) may
5106     be specified to choose the desired speed vs. compression rate ratio.
5108 +*inflate* 'data' '?bufferSize?'+::
5109     Decompresses a raw, Deflate-compressed stream. When the uncompressed data size is known and specified, memory
5110     allocation is more efficient. Otherwise, decomperssion is chunked and therefore slower.
5112 +*gzip* 'string' '?-level level?'+::
5113     Compresses a buffer and adds a gzip header.
5115 +*gunzip* 'data' '?-buffersize size?'+::
5116     Decompresses a gzip-compressed buffer. Decompression is chunked, with a default, small buffer size of 64K
5117     which guarantees lower memory footprint at the cost of speed. It is recommended to use a bigger size, on
5118     systems without a severe memory constraint.
5120 binary
5121 ~~~~~~
5122 The optional, pure-Tcl 'binary' extension provides the Tcl-compatible `binary scan` and `binary format`
5123 commands based on the low-level `pack` and `unpack` commands.
5125 See the Tcl documentation at: http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm
5127 Note that 'binary format' with f/r/R specifiers (single-precision float) uses the value of Infinity
5128 in case of overflow.
5130 oo: class, super
5131 ~~~~~~~~~~~~~~~~
5132 The optional, pure-Tcl 'oo' extension provides object-oriented (OO) support for Jim Tcl.
5134 See the online documentation (http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/) for more details.
5136 +*class* 'classname ?baseclasses? classvars'+::
5137     Create a new class, +'classname'+, with the given dictionary
5138     (+'classvars'+) as class variables. These are the initial variables
5139     which all newly created objects of this class are initialised with.
5140     If a list of baseclasses is given, methods and instance variables
5141     are inherited.
5143 +*super* 'method ?args \...?'+::
5144     From within a method, invokes the given method on the base class.
5145     Note that this will only call the last baseclass given.
5147 tree
5148 ~~~~
5149 The optional, pure-Tcl 'tree' extension implements an OO, general purpose tree structure
5150 similar to that provided by tcllib ::struct::tree (http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/struct_tree.html)
5152 A tree is a collection of nodes, where each node (except the root node) has a single parent
5153 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.
5155 +*tree*+::
5156     Creates and returns a new tree object with a single node named "root".
5157     All operations on the tree are invoked through this object.
5159 +$tree *destroy*+::
5160     Destroy the tree and all it's nodes. (Note that the tree will also
5161     be automatically garbage collected once it goes out of scope).
5163 +$tree *set* 'nodename key value'+::
5164     Set the value for the given attribute key.
5166 +$tree *lappend* 'nodename key value \...'+::
5167     Append to the (list) value(s) for the given attribute key, or set if not yet set.
5169 +$tree *keyexists* 'nodename key'+::
5170     Returns 1 if the given attribute key exists.
5172 +$tree *get* 'nodename key'+::
5173     Returns the value associated with the given attribute key.
5175 +$tree *getall* 'nodename'+::
5176     Returns the entire attribute dictionary associated with the given key.
5178 +$tree *depth* 'nodename'+::
5179     Returns the depth of the given node. The depth of "root" is 0.
5181 +$tree *parent* 'nodename'+::
5182     Returns the node name of the parent node, or "" for the root node.
5184 +$tree *numchildren* 'nodename'+::
5185     Returns the number of child nodes.
5187 +$tree *children* 'nodename'+::
5188     Returns a list of the child nodes.
5190 +$tree *next* 'nodename'+::
5191     Returns the next sibling node, or "" if none.
5193 +$tree *insert* 'nodename ?index?'+::
5194     Add a new child node to the given node. The index is a list index
5195     such as +3+ or +end-2+. The default index is +end+.
5196     Returns the name of the newly added node.
5198 +$tree *walk* 'nodename' *dfs|bfs* {'actionvar nodevar'} 'script'+::
5199     Walks the tree starting from the given node, either breadth first (+bfs+)
5200     depth first (+dfs+).
5201     The value +"enter"+ or +"exit"+ is stored in variable +'actionvar'+.
5202     The name of each node is stored in +'nodevar'+.
5203     The script is evaluated twice for each node, on entry and exit.
5205 +$tree *dump*+::
5206     Dumps the tree contents to stdout
5208 tcl::prefix
5209 ~~~~~~~~~~~
5210 The optional tclprefix extension provides the Tcl8.6-compatible `tcl::prefix` command
5211 (http://www.tcl.tk/man/tcl8.6/TclCmd/prefix.htm) for matching strings against a table
5212 of possible values (typically commands or options).
5214 +*tcl::prefix all* 'table string'+::
5215     Returns a list of all elements in +'table'+ that begin with the prefix +'string'+.
5217 +*tcl::prefix longest* 'table string'+::
5218     Returns the longest common prefix of all elements in +'table'+ that begin with the prefix +'string'+.
5220 +*tcl::prefix match* '?options? table string'+::
5221     If +'string'+ equals one element in +'table'+ or is a prefix to
5222     exactly one element, the matched element is returned. If not, the
5223     result depends on the +-error+ option.
5225     * +*-exact*+ Accept only exact matches.
5226     * +*-message* 'string'+ Use +'string'+ in the error message at a mismatch. Default is "option".
5227     * +*-error* 'options'+ The options are used when no match is found. If +'options'+ is
5228       empty, no error is generated and an empty string is returned.
5229       Otherwise the options are used as return options when
5230       generating the error message. The default corresponds to
5231       setting +-level 0+.
5233 tcl::autocomplete
5234 ~~~~~~~~~~~~~~~~~
5235 Scriptable command line completion is supported in the interactive shell, 'jimsh', through
5236 the `tcl::autocomplete` callback. A simple implementation is provided, however this may
5237 be replaced with a custom command instead if desired.
5239 In the interactive shell, press <TAB> to activate command line completion.
5241 +*tcl::autocomplete* 'commandline'+::
5242     This command is called with the current command line when the user presses <TAB>.
5243     The command should return a list of all possible command lines that match the current command line.
5244     For example if +*pr*+ is the current command line, the list +*{prefix proc}*+ may be returned.
5246 history
5247 ~~~~~~~
5248 The optional history extension provides script access to the command line editing
5249 and history support available in 'jimsh'. See 'examples/jtclsh.tcl' for an example.
5250 Note: if line editing support is not available, `history getline` acts like `gets` and
5251 the remaining subcommands do nothing.
5253 +*history load* 'filename'+::
5254     Load history from a (text) file. If the file does not exist or is not readable,
5255     it is ignored.
5257 +*history getline* 'prompt ?varname?'+::
5258     Displays the given prompt and allows a line to be entered. Similarly to `gets`,
5259     if +'varname'+ is given, it receives the line and the length of the line is returned,
5260     or -1 on EOF. If +'varname'+ is not given, the line is returned directly.
5262 +*history completion* 'command'+::
5263     Sets an autocompletion command (see `tcl::autocomplete`) that is active during `history getline`.
5264     If the command is empty, autocompletion is disabled.
5266 +*history add* 'line'+::
5267     Adds the given line to the history buffer.
5269 +*history save* 'filename'+::
5270     Saves the current history buffer to the given file.
5272 +*history show*+::
5273     Displays the current history buffer to standard output.
5275 namespace
5276 ~~~~~~~~~
5277 Provides namespace-related functions. See also: http://www.tcl.tk/man/tcl8.6/TclCmd/namespace.htm
5279 +*namespace code* 'script'+::
5280     Captures the current namespace context for later execution of
5281     the script +'script'+. It returns a new script in which script has
5282     been wrapped in a +*namespace inscope*+ command.
5284 +*namespace current*+::
5285     Returns the fully-qualified name for the current namespace.
5287 +*namespace delete* '?namespace ...?'+::
5288     Deletes all commands and variables with the given namespace prefixes.
5290 +*namespace eval* 'namespace arg ?arg...?'+::
5291     Activates a namespace called +'namespace'+ and evaluates some code in that context.
5293 +*namespace origin* 'command'+::
5294     Returns the fully-qualified name of the original command to which the imported command +'command'+ refers.
5296 +*namespace parent* ?namespace?+::
5297     Returns the fully-qualified name of the parent namespace for namespace +'namespace'+, if given, otherwise
5298     for the current namespace.
5300 +*namespace qualifiers* 'string'+::
5301     Returns any leading namespace qualifiers for +'string'+
5303 +*namespace tail* 'string'+::
5304     Returns the simple name at the end of a qualified string.
5306 +*namespace upvar* 'namespace ?arg...?'+::
5307     This command arranges for zero or more local variables in the current procedure to refer to variables in +'namespace'+
5309 +*namespace which* '?-command|-variable? name'+::
5310     Looks up +'name'+ as either a command (the default) or variable and returns its fully-qualified name.
5312 interp
5313 ~~~~~~
5314 The optional 'interp' command allows sub-interpreters to be created where commands may be run
5315 independently (but synchronously) of the main interpreter.
5317 +*interp*+::
5318     Creates and returns a new interpreter object (command).
5319     The created interpeter contains any built-in commands along with static extensions,
5320     but does not include any dynamically loaded commands (package require, load).
5321     These must be reloaded in the child interpreter if required.
5323 +*$interp delete*+::
5324     Deletes the interpeter object.
5326 +*$interp eval* 'script' ...+::
5327     Evaluates a script in the context for the child interpreter, in the same way as 'eval'.
5329 +*$interp alias* 'alias childcmd parentcmd ?arg ...?'+::
5330     Similar to 'alias', but creates a command, +'childcmd'+, in the child interpreter that is an
5331     alias for +'parentcmd'+ in the parent interpreter, with the given, fixed arguments.
5332     The alias may be deleted in the child with 'rename'.
5334 [[BuiltinVariables]]
5335 BUILT-IN VARIABLES
5336 ------------------
5338 The following global variables are created automatically
5339 by the Tcl library.
5341 +*env*+::
5342     This variable is set by Jim as an array
5343     whose elements are the environment variables for the process.
5344     Reading an element will return the value of the corresponding
5345     environment variable.
5346     This array is initialised at startup from the `env` command.
5347     It may be modified and will affect the environment passed to
5348     commands invoked with `exec`.
5350 +*platform_tcl*+::
5351     This variable is set by Jim as an array containing information
5352     about the platform on which Jim was built. Currently this includes
5353     'os' and 'platform'.
5355 +*auto_path*+::
5356     This variable contains a list of paths to search for packages.
5357     It defaults to a location based on where jim is installed
5358     (e.g. +/usr/local/lib/jim+), but may be changed by +jimsh+
5359     or the embedding application. Note that +jimsh+ will consider
5360     the environment variable +$JIMLIB+ to be a list of colon-separated
5361     list of paths to add to +*auto_path*+.
5363 +*errorCode*+::
5364     This variable holds the value of the -errorcode return
5365     option set by the most recent error that occurred in this
5366     interpreter. This list value represents additional information
5367     about the error in a form that is easy to process with
5368     programs. The first element of the list identifies a general
5369     class of errors, and determines the format of the rest of
5370     the list. The following formats for -errorcode return options
5371     are used by the Tcl core; individual applications may define
5372     additional formats. Currently only `exec` sets this variable.
5373     Otherwise it will be +NONE+.
5375 The following global variables are set by jimsh.
5377 +*tcl_interactive*+::
5378     This variable is set to 1 if jimsh is started in interactive mode
5379     or 0 otherwise.
5381 +*tcl_platform*+::
5382     This variable is set by Jim as an array containing information
5383     about the platform upon which Jim was built. The following is an
5384     example of the contents of this array.
5386 ----
5387     tcl_platform(byteOrder)     = littleEndian
5388     tcl_platform(engine)        = Jim
5389     tcl_platform(os)            = Darwin
5390     tcl_platform(platform)      = unix
5391     tcl_platform(pointerSize)   = 8
5392     tcl_platform(threaded)      = 0
5393     tcl_platform(wordSize)      = 8
5394     tcl_platform(pathSeparator) = :
5395 ----
5397 +*argv0*+::
5398     If jimsh is invoked to run a script, this variable contains the name
5399     of the script.
5401 +*argv*+::
5402     If jimsh is invoked to run a script, this variable contains a list
5403     of any arguments supplied to the script.
5405 +*argc*+::
5406     If jimsh is invoked to run a script, this variable contains the number
5407     of arguments supplied to the script.
5409 +*jim::argv0*+::
5410     The value of argv[0] when jimsh was invoked.
5412 The following variables have special meaning to Jim Tcl:
5414 +*jim::defer*+::
5415     If this variable is set, it is considered to be a list of scripts to evaluate
5416     when the current proc exits (local variables), or the interpreter exits (global variable).
5417     See `defer`.
5419 +*history::multiline*+::
5420     If this variable is set to "1", interactive line editing operates in multiline mode.
5421     That is, long lines will wrap across multiple lines rather than scrolling within a
5422     single line.
5424 CHANGES IN PREVIOUS RELEASES
5425 ----------------------------
5427 === In v0.70 ===
5429 1. +platform_tcl()+ settings are now automatically determined
5430 2. Add aio `$handle filename`
5431 3. Add `info channels`
5432 4. The 'bio' extension is gone. Now `aio` supports 'copyto'.
5433 5. Add `exists` command
5434 6. Add the pure-Tcl 'oo' extension
5435 7. The `exec` command now only uses vfork(), not fork()
5436 8. Unit test framework is less verbose and more Tcl-compatible
5437 9. Optional UTF-8 support
5438 10. Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
5439 11. Command line editing in interactive mode, e.g. 'jimsh'
5441 === In v0.63 ===
5443 1. `source` now checks that a script is complete (.i.e. not missing a brace)
5444 2. 'info complete' now uses the real parser and so is 100% accurate
5445 3. Better access to live stack frames with 'info frame', `stacktrace` and `stackdump`
5446 4. `tailcall` no longer loses stack trace information
5447 5. Add `alias` and `curry`
5448 6. `lambda`, `alias` and `curry` are implemented via `tailcall` for efficiency
5449 7. `local` allows procedures to be deleted automatically at the end of the current procedure
5450 8. udp sockets are now supported for both clients and servers.
5451 9. vfork-based exec is now working correctly
5452 10. Add 'file tempfile'
5453 11. Add 'socket pipe'
5454 12. Enhance 'try ... on ... finally' to be more Tcl 8.6 compatible
5455 13. It is now possible to `return` from within `try`
5456 14. IPv6 support is now included
5457 15. Add 'string is'
5458 16. Event handlers works better if an error occurs. eof handler has been removed.
5459 17. `exec` now sets $::errorCode, and catch sets opts(-errorcode) for exit status
5460 18. Command pipelines via open "|..." are now supported
5461 19. `pid` can now return pids of a command pipeline
5462 20. Add 'info references'
5463 21. Add support for 'after +'ms'+', 'after idle', 'after info', `update`
5464 22. `exec` now sets environment based on $::env
5465 23. Add 'dict keys'
5466 24. Add support for 'lsort -index'
5468 === In v0.62 ===
5470 1. Add support to `exec` for '>&', '>>&', '|&', '2>@1'
5471 2. Fix `exec` error messages when special token (e.g. '>') is the last token
5472 3. Fix `subst` handling of backslash escapes.
5473 4. Allow abbreviated options for `subst`
5474 5. Add support for `return`, `break`, `continue` in subst
5475 6. Many `expr` bug fixes
5476 7. Add support for functions in `expr` (e.g. int(), abs()), and also 'in', 'ni' list operations
5477 8. The variable name argument to `regsub` is now optional
5478 9. Add support for 'unset -nocomplain'
5479 10. Add support for list commands: `lassign`, `lrepeat`
5480 11. Fully-functional `lsearch` is now implemented
5481 12. Add 'info nameofexecutable' and 'info returncodes'
5482 13. Allow `catch` to determine what return codes are caught
5483 14. Allow `incr` to increment an unset variable by first setting to 0
5484 15. Allow 'args' and optional arguments to the left or required arguments in `proc`
5485 16. Add 'file copy'
5486 17. Add 'try ... finally' command
5489 LICENCE
5490 -------
5492  Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
5493  Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
5494  Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
5495  Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
5496  Copyright 2008 Andrew Lunn <andrew@lunn.ch>
5497  Copyright 2008 Duane Ellis <openocd@duaneellis.com>
5498  Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
5499  Copyright 2009 Steve Bennett <steveb@workware.net.au>
5501 [literal]
5502  Redistribution and use in source and binary forms, with or without
5503  modification, are permitted provided that the following conditions
5504  are met:
5505  1. Redistributions of source code must retain the above copyright
5506     notice, this list of conditions and the following disclaimer.
5507  2. Redistributions in binary form must reproduce the above
5508     copyright notice, this list of conditions and the following
5509     disclaimer in the documentation and/or other materials
5510     provided with the distribution.
5512  THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
5513  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
5514  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
5515  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
5516  JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
5517  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5518  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5519  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5520  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
5521  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5522  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5523  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5525  The views and conclusions contained in the software and documentation
5526  are those of the authors and should not be interpreted as representing
5527  official policies, either expressed or implied, of the Jim Tcl Project.