1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
6 <meta http-equiv=
"Content-Type" content=
"application/xhtml+xml; charset=UTF-8" />
7 <meta name=
"generator" content=
"AsciiDoc 8.6.10" />
8 <title>Jim Tcl(n)
</title>
9 <style type=
"text/css">
10 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
14 font-family: Georgia,serif;
18 h1, h2, h3, h4, h5, h6,
19 div.title, caption.title,
20 thead, p.table.header,
22 #author, #revnumber, #revdate, #revremark,
24 font-family: Arial,Helvetica,sans-serif;
28 margin:
1em
5%
1em
5%;
33 text-decoration: underline;
49 h1, h2, h3, h4, h5, h6 {
57 border-bottom:
2px solid silver;
77 border:
1px solid silver;
88 ul
> li { color: #aaa; }
89 ul
> li
> * { color: black; }
91 .monospaced, code, pre {
92 font-family:
"Courier New", Courier, monospace;
99 white-space: pre-wrap;
109 #revnumber, #revdate, #revremark {
114 border-top:
2px solid silver;
120 padding-bottom:
0.5em;
124 padding-bottom:
0.5em;
129 margin-bottom:
1.5em;
131 div.imageblock, div.exampleblock, div.verseblock,
132 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
133 div.admonitionblock {
135 margin-bottom:
1.5em;
137 div.admonitionblock {
139 margin-bottom:
2.0em;
144 div.content { /* Block element content. */
148 /* Block element titles. */
149 div.title, caption.title {
154 margin-bottom:
0.5em;
160 td div.title:first-child {
163 div.content div.title:first-child {
166 div.content + div.title {
170 div.sidebarblock
> div.content {
172 border:
1px solid #dddddd;
173 border-left:
4px solid #f0f0f0;
177 div.listingblock
> div.content {
178 border:
1px solid #dddddd;
179 border-left:
5px solid #f0f0f0;
184 div.quoteblock, div.verseblock {
188 border-left:
5px solid #f0f0f0;
192 div.quoteblock
> div.attribution {
197 div.verseblock
> pre.content {
198 font-family: inherit;
201 div.verseblock
> div.attribution {
205 /* DEPRECATED: Pre version
8.2.7 verse style literal block. */
206 div.verseblock + div.attribution {
210 div.admonitionblock .icon {
214 text-decoration: underline;
216 padding-right:
0.5em;
218 div.admonitionblock td.content {
220 border-left:
3px solid #dddddd;
223 div.exampleblock
> div.content {
224 border-left:
3px solid #dddddd;
228 div.imageblock div.content { padding-left:
0; }
229 span.image img { border-style: none; vertical-align: text-bottom; }
230 a.image:visited { color: white; }
234 margin-bottom:
0.8em;
247 list-style-position: outside;
250 list-style-type: decimal;
253 list-style-type: lower-alpha;
256 list-style-type: upper-alpha;
259 list-style-type: lower-roman;
262 list-style-type: upper-roman;
265 div.compact ul, div.compact ol,
266 div.compact p, div.compact p,
267 div.compact div, div.compact div {
269 margin-bottom:
0.1em;
281 margin-bottom:
0.8em;
284 padding-bottom:
15px;
286 dt.hdlist1.strong, td.hdlist1.strong {
292 padding-right:
0.8em;
298 div.hdlist.compact tr {
307 .footnote, .footnoteref {
311 span.footnote, span.footnoteref {
312 vertical-align: super;
316 margin:
20px
0 20px
0;
320 #footnotes div.footnote {
326 border-top:
1px solid silver;
335 padding-right:
0.5em;
336 padding-bottom:
0.3em;
344 #footer-badges { display: none; }
348 margin-bottom:
2.5em;
356 margin-bottom:
0.1em;
359 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
376 span.aqua { color: aqua; }
377 span.black { color: black; }
378 span.blue { color: blue; }
379 span.fuchsia { color: fuchsia; }
380 span.gray { color: gray; }
381 span.green { color: green; }
382 span.lime { color: lime; }
383 span.maroon { color: maroon; }
384 span.navy { color: navy; }
385 span.olive { color: olive; }
386 span.purple { color: purple; }
387 span.red { color: red; }
388 span.silver { color: silver; }
389 span.teal { color: teal; }
390 span.white { color: white; }
391 span.yellow { color: yellow; }
393 span.aqua-background { background: aqua; }
394 span.black-background { background: black; }
395 span.blue-background { background: blue; }
396 span.fuchsia-background { background: fuchsia; }
397 span.gray-background { background: gray; }
398 span.green-background { background: green; }
399 span.lime-background { background: lime; }
400 span.maroon-background { background: maroon; }
401 span.navy-background { background: navy; }
402 span.olive-background { background: olive; }
403 span.purple-background { background: purple; }
404 span.red-background { background: red; }
405 span.silver-background { background: silver; }
406 span.teal-background { background: teal; }
407 span.white-background { background: white; }
408 span.yellow-background { background: yellow; }
410 span.big { font-size:
2em; }
411 span.small { font-size:
0.6em; }
413 span.underline { text-decoration: underline; }
414 span.overline { text-decoration: overline; }
415 span.line-through { text-decoration: line-through; }
417 div.unbreakable { page-break-inside: avoid; }
427 margin-bottom:
1.5em;
429 div.tableblock
> table {
430 border:
3px solid #
527bbd;
432 thead, p.table.header {
439 /* Because the table frame attribute is overriden by CSS in most browsers. */
440 div.tableblock
> table[
frame=
"void"] {
443 div.tableblock
> table[
frame=
"hsides"] {
444 border-left-style: none;
445 border-right-style: none;
447 div.tableblock
> table[
frame=
"vsides"] {
448 border-top-style: none;
449 border-bottom-style: none;
460 margin-bottom:
1.5em;
462 thead, p.tableblock.header {
473 border-color: #
527bbd;
474 border-collapse: collapse;
476 th.tableblock, td.tableblock {
480 border-color: #
527bbd;
483 table.tableblock.frame-topbot {
484 border-left-style: hidden;
485 border-right-style: hidden;
487 table.tableblock.frame-sides {
488 border-top-style: hidden;
489 border-bottom-style: hidden;
491 table.tableblock.frame-none {
492 border-style: hidden;
495 th.tableblock.halign-left, td.tableblock.halign-left {
498 th.tableblock.halign-center, td.tableblock.halign-center {
501 th.tableblock.halign-right, td.tableblock.halign-right {
505 th.tableblock.valign-top, td.tableblock.valign-top {
508 th.tableblock.valign-middle, td.tableblock.valign-middle {
509 vertical-align: middle;
511 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
512 vertical-align: bottom;
523 padding-bottom:
0.5em;
524 border-top:
2px solid silver;
525 border-bottom:
2px solid silver;
530 body.manpage div.sectionbody {
535 body.manpage div#toc { display: none; }
540 <script type=
"text/javascript">
542 var asciidoc = { // Namespace.
544 /////////////////////////////////////////////////////////////////////
545 // Table Of Contents generator
546 /////////////////////////////////////////////////////////////////////
548 /* Author: Mihai Bazon, September
2002
549 * http://students.infoiasi.ro/~mishoo
551 * Table Of Content generator
554 * Feel free to use this script under the terms of the GNU General Public
555 * License, as long as you do not remove or alter this notice.
558 /* modified by Troy D. Hanson, September
2006. License: GPL */
559 /* modified by Stuart Rackham,
2006,
2009. License: GPL */
562 toc: function (toclevels) {
564 function getText(el) {
566 for (var i = el.firstChild; i != null; i = i.nextSibling) {
567 if (i.nodeType ==
3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
569 else if (i.firstChild != null)
575 function TocEntry(el, text, toclevel) {
578 this.toclevel = toclevel;
581 function tocEntries(el, toclevels) {
582 var result = new Array;
583 var re = new RegExp('[hH]([
1-'+(toclevels+
1)+'])');
584 // Function that scans the DOM tree for header elements (the DOM2
585 // nodeIterator API would be a better technique but not supported by all
587 var iterate = function (el) {
588 for (var i = el.firstChild; i != null; i = i.nextSibling) {
589 if (i.nodeType ==
1 /* Node.ELEMENT_NODE */) {
590 var mo = re.exec(i.tagName);
591 if (mo && (i.getAttribute(
"class") || i.getAttribute(
"className")) !=
"float") {
592 result[result.length] = new TocEntry(i, getText(i), mo[
1]-
1);
602 var toc = document.getElementById(
"toc");
607 // Delete existing TOC entries in case we're reloading the TOC.
608 var tocEntriesToRemove = [];
610 for (i =
0; i < toc.childNodes.length; i++) {
611 var entry = toc.childNodes[i];
612 if (entry.nodeName.toLowerCase() == 'div'
613 && entry.getAttribute(
"class")
614 && entry.getAttribute(
"class").match(/^toclevel/))
615 tocEntriesToRemove.push(entry);
617 for (i =
0; i < tocEntriesToRemove.length; i++) {
618 toc.removeChild(tocEntriesToRemove[i]);
621 // Rebuild TOC entries.
622 var entries = tocEntries(document.getElementById(
"content"), toclevels);
623 for (var i =
0; i < entries.length; ++i) {
624 var entry = entries[i];
625 if (entry.element.id ==
"")
626 entry.element.id =
"_toc_" + i;
627 var a = document.createElement(
"a");
628 a.href =
"#" + entry.element.id;
629 a.appendChild(document.createTextNode(entry.text));
630 var div = document.createElement(
"div");
632 div.className =
"toclevel" + entry.toclevel;
633 toc.appendChild(div);
635 if (entries.length ==
0)
636 toc.parentNode.removeChild(toc);
640 /////////////////////////////////////////////////////////////////////
641 // Footnotes generator
642 /////////////////////////////////////////////////////////////////////
644 /* Based on footnote generation code from:
645 * http://www.brandspankingnew.net/archive/
2005/
07/format_footnote.html
648 footnotes: function () {
649 // Delete existing footnote entries in case we're reloading the footnodes.
651 var noteholder = document.getElementById(
"footnotes");
655 var entriesToRemove = [];
656 for (i =
0; i < noteholder.childNodes.length; i++) {
657 var entry = noteholder.childNodes[i];
658 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute(
"class") ==
"footnote")
659 entriesToRemove.push(entry);
661 for (i =
0; i < entriesToRemove.length; i++) {
662 noteholder.removeChild(entriesToRemove[i]);
665 // Rebuild footnote entries.
666 var cont = document.getElementById(
"content");
667 var spans = cont.getElementsByTagName(
"span");
670 for (i=
0; i
<spans.length; i++) {
671 if (spans[i].className ==
"footnote") {
673 var note = spans[i].getAttribute(
"data-note");
675 // Use [\s\S] in place of . so multi-line matches work.
676 // Because JavaScript has no s (dotall) regex flag.
677 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[
1];
679 "[<a id='_footnoteref_" + n +
"' href='#_footnote_" + n +
680 "' title='View footnote' class='footnote'>" + n +
"</a>]";
681 spans[i].setAttribute(
"data-note", note);
683 noteholder.innerHTML +=
684 "<div class='footnote' id='_footnote_" + n +
"'>" +
685 "<a href='#_footnoteref_" + n +
"' title='Return to text'>" +
686 n +
"</a>. " + note +
"</div>";
687 var id =spans[i].getAttribute(
"id");
688 if (id != null) refs[
"#"+id] = n;
692 noteholder.parentNode.removeChild(noteholder);
694 // Process footnoterefs.
695 for (i=
0; i
<spans.length; i++) {
696 if (spans[i].className ==
"footnoteref") {
697 var href = spans[i].getElementsByTagName(
"a")[
0].getAttribute(
"href");
698 href = href.match(/#.*/)[
0]; // Because IE return full URL.
701 "[<a href='#_footnote_" + n +
702 "' title='View footnote' class='footnote'>" + n +
"</a>]";
708 install: function(toclevels) {
711 function reinstall() {
712 asciidoc.footnotes();
714 asciidoc.toc(toclevels);
718 function reinstallAndRemoveTimer() {
719 clearInterval(timerId);
723 timerId = setInterval(reinstall,
500);
724 if (document.addEventListener)
725 document.addEventListener(
"DOMContentLoaded", reinstallAndRemoveTimer, false);
727 window.onload = reinstallAndRemoveTimer;
735 <body class=
"manpage">
738 Jim Tcl(n) Manual Page
741 <div class=
"sectionbody">
743 reference manual for the Jim Tcl scripting language
749 <h2 id=
"_synopsis">SYNOPSIS
</h2>
750 <div class=
"sectionbody">
751 <div class=
"literalblock">
752 <div class=
"content">
753 <pre><code>cc
<source
> -ljim
</code></pre>
755 <div class=
"paragraph"><p>or
</p></div>
756 <div class=
"literalblock">
757 <div class=
"content">
758 <pre><code>jimsh [
<scriptfile
>|-]
759 jimsh -e '
<immediate-script
>'
761 jimsh --help
</code></pre>
763 <div class=
"ulist"><div class=
"title">Quick Index
</div><ul>
766 <a href=
"#CommandIndex">Command Reference
</a>
771 <a href=
"#OperatorPrecedence">Operator Precedence
</a>
776 <a href=
"#BuiltinVariables">Builtin Variables
</a>
781 <a href=
"#BackslashSequences">Backslash Sequences
</a>
788 <h2 id=
"_introduction">INTRODUCTION
</h2>
789 <div class=
"sectionbody">
790 <div class=
"paragraph"><p>Jim Tcl is a small footprint reimplementation of the Tcl scripting language.
791 The core language engine is compatible with Tcl
8.5+, while implementing
792 a significant subset of the Tcl
8.6 command set, plus additional features
793 available only in Jim Tcl.
</p></div>
794 <div class=
"paragraph"><p>Some notable differences with Tcl
8.5/
8.6 are:
</p></div>
795 <div class=
"olist arabic"><ol class=
"arabic">
798 Object-based I/O (aio), but with a Tcl-compatibility layer
803 I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
813 Support for references (
<a href=
"#_ref"><strong><code>ref
</code></strong></a>/
<a href=
"#_getref"><strong><code>getref
</code></strong></a>/
<a href=
"#_setref"><strong><code>setref
</code></strong></a>) and garbage collection
818 Builtin dictionary type (
<a href=
"#_dict"><strong><code>dict
</code></strong></a>) with some limitations compared to Tcl
8.6
823 <a href=
"#_env"><strong><code>env
</code></strong></a> command to access environment variables
828 Operating system features:
<a href=
"#cmd_1"><strong><code>os.fork
</code></strong></a>,
<a href=
"#cmd_1"><strong><code>os.uptime
</code></strong></a>,
<a href=
"#_wait"><strong><code>wait
</code></strong></a>,
<a href=
"#_signal"><strong><code>signal
</code></strong></a>,
<a href=
"#_alarm"><strong><code>alarm
</code></strong></a>,
<a href=
"#_sleep"><strong><code>sleep
</code></strong></a>
833 Much better error reporting.
<a href=
"#_info"><strong><code>info
</code></strong></a> <code>stacktrace
</code> as a replacement for
<em>$errorInfo
</em>,
<em>$errorCode
</em>
838 Support for
"static" variables in procedures
843 Threads and coroutines are not supported
848 Command and variable traces are not supported
853 Built-in command line editing
858 Expression shorthand syntax:
<code>$(
…)
</code>
863 Modular build allows many features to be omitted or built as dynamic, loadable modules
868 Highly suitable for use in an embedded environment
873 Support for UDP, IPv6, Unix-Domain sockets in addition to TCP sockets
880 <h2 id=
"_recent_changes">RECENT CHANGES
</h2>
881 <div class=
"sectionbody">
883 <h3 id=
"_changes_between_0_78_and_0_79">Changes between
0.78 and
0.79</h3>
884 <div class=
"olist arabic"><ol class=
"arabic">
887 Add
<a href=
"#_file"><strong><code>file
</code></strong></a> <code>mtimeus
</code> for high resolution file timestamps
892 <a href=
"#_aio"><strong><code>aio
</code></strong></a> now supports datagram Unix-Domain sockets
897 Add support for
<a href=
"#_aio"><strong><code>aio
</code></strong></a> <code>lock -wait
</code>
902 Add
<a href=
"#_signal"><strong><code>signal
</code></strong></a> <code>block
</code> to prevent delivery of signals
907 Add support for
<a href=
"#_file"><strong><code>file
</code></strong></a> <code>split
</code>
912 Add support for
<a href=
"#_json_encode"><strong><code>json::encode
</code></strong></a> and
<a href=
"#_json_decode"><strong><code>json::decode
</code></strong></a>
917 <a href=
"#_aio"><strong><code>aio
</code></strong></a> <code>tty
</code> now allows setting
<code>echo
</code> without full
<code>raw
</code> mode
923 <h3 id=
"_changes_between_0_77_and_0_78">Changes between
0.77 and
0.78</h3>
924 <div class=
"olist arabic"><ol class=
"arabic">
927 Add serial/tty support with
<a href=
"#_aio"><strong><code>aio
</code></strong></a> <code>tty
</code>
932 Add support for
<em>jimsh -
</em>
937 Add hidden
<em>-commands
</em> option to many commands
942 Add scriptable autocompletion support in interactive mode with
<a href=
"#_tcl_autocomplete"><strong><code>tcl::autocomplete
</code></strong></a>
947 Add
<a href=
"#_aio"><strong><code>aio
</code></strong></a> <code>sockopt
</code>
952 Add scriptable autocompletion support with
<a href=
"#_history"><strong><code>history
</code></strong></a> <code>completion
</code>
957 Add support for
<a href=
"#_tree"><strong><code>tree
</code></strong></a> <code>delete
</code>
962 Add support for
<a href=
"#_defer"><strong><code>defer
</code></strong></a> and
<em>$jim::defer
</em>
967 Renamed
<code>os.wait
</code> to
<a href=
"#_wait"><strong><code>wait
</code></strong></a>, now more Tcl-compatible and compatible with
<a href=
"#_exec"><strong><code>exec
</code></strong></a> <code>...
&</code>
972 <a href=
"#_pipe"><strong><code>pipe
</code></strong></a> is now a synonym for
<a href=
"#_socket"><strong><code>socket
</code></strong></a> <code>pipe
</code>
977 Closing a pipe open with
<a href=
"#_open"><strong><code>open
</code></strong></a> <code>|...
</code> now returns Tcl-like status
982 It is now possible to used
<a href=
"#_exec"><strong><code>exec
</code></strong></a> redirection with a pipe opened with
<a href=
"#_open"><strong><code>open
</code></strong></a> <code>|...
</code>
987 Interactive line editing now supports multiline mode if $::history::multiline is set
993 <h3 id=
"_changes_between_0_76_and_0_77">Changes between
0.76 and
0.77</h3>
994 <div class=
"olist arabic"><ol class=
"arabic">
997 Add support for
<a href=
"#_aio"><strong><code>aio
</code></strong></a> <code>sync
</code>
1002 Add SSL and TLS support in aio
1007 Added
<a href=
"#_zlib"><strong><code>zlib
</code></strong></a>
1012 Added support for boolean constants in
<a href=
"#_expr"><strong><code>expr
</code></strong></a>
1017 <a href=
"#_string"><strong><code>string
</code></strong></a> <code>is
</code> now supports
<em>boolean
</em> class
1022 Add support for
<a href=
"#_aio"><strong><code>aio
</code></strong></a> <code>lock
</code> and
<a href=
"#_aio"><strong><code>aio
</code></strong></a> <code>unlock
</code>
1027 Add new
<a href=
"#_interp"><strong><code>interp
</code></strong></a> command
1033 <h3 id=
"_changes_between_0_75_and_0_76">Changes between
0.75 and
0.76</h3>
1034 <div class=
"olist arabic"><ol class=
"arabic">
1037 <a href=
"#_glob"><strong><code>glob
</code></strong></a> now supports the
<code>-tails
</code> option
1042 Add support for
<a href=
"#_string"><strong><code>string
</code></strong></a> <code>cat
</code>
1047 Allow
<a href=
"#_info"><strong><code>info
</code></strong></a> <code>source
</code> to add source info
1053 <h3 id=
"_changes_between_0_74_and_0_75">Changes between
0.74 and
0.75</h3>
1054 <div class=
"olist arabic"><ol class=
"arabic">
1057 <a href=
"#_binary"><strong><code>binary
</code></strong></a>,
<a href=
"#cmd_3"><strong><code>pack
</code></strong></a> and
<a href=
"#cmd_3"><strong><code>unpack
</code></strong></a> now support floating point
1062 <a href=
"#_file"><strong><code>file
</code></strong></a> <code>copy
</code> <code>-force
</code> handles source and target as the same file
1067 <a href=
"#_format"><strong><code>format
</code></strong></a> now supports
<code>%b
</code> for binary conversion
1072 <a href=
"#_lsort"><strong><code>lsort
</code></strong></a> now supports
<code>-unique
</code> and
<code>-real
</code>
1077 Add support for half-close with
<a href=
"#_aio"><strong><code>aio
</code></strong></a> <code>close
</code> <code>?r|w?
</code>
1082 Add
<a href=
"#_socket"><strong><code>socket
</code></strong></a> <code>pair
</code> for a bidirectional pipe
1087 Add
<em>--random-hash
</em> to randomise hash tables for greater security
1092 <a href=
"#_dict"><strong><code>dict
</code></strong></a> now supports
<em>for
</em>,
<em>values
</em>,
<em>incr
</em>,
<em>append
</em>,
<em>lappend
</em>,
<em>update
</em>,
<em>info
</em> and
<em>replace
</em>
1097 <a href=
"#_file"><strong><code>file
</code></strong></a> <code>stat
</code> no longer requires the variable name
1102 Add support for
<a href=
"#_file"><strong><code>file
</code></strong></a> <code>link
</code>
1110 <h2 id=
"_tcl_introduction">TCL INTRODUCTION
</h2>
1111 <div class=
"sectionbody">
1112 <div class=
"paragraph"><p>Tcl stands for
<em>tool command language
</em> and is pronounced
1113 <em><a href=
"http://www.oxforddictionaries.com/definition/american_english/tickle">tickle
</a></em>.
1114 It is actually two things: a language and a library.
</p></div>
1115 <div class=
"paragraph"><p>First, Tcl is a simple textual language, intended primarily for
1116 issuing commands to interactive programs such as text editors,
1117 debuggers, illustrators, and shells. It has a simple syntax and is also
1118 programmable, so Tcl users can write command procedures to provide more
1119 powerful commands than those in the built-in set.
</p></div>
1120 <div class=
"paragraph"><p>Second, Tcl is a library package that can be embedded in application
1121 programs. The Tcl library consists of a parser for the Tcl language,
1122 routines to implement the Tcl built-in commands, and procedures that
1123 allow each application to extend Tcl with additional commands specific
1124 to that application. The application program generates Tcl commands and
1125 passes them to the Tcl parser for execution. Commands may be generated
1126 by reading characters from an input source, or by associating command
1127 strings with elements of the application
’s user interface, such as menu
1128 entries, buttons, or keystrokes.
</p></div>
1129 <div class=
"paragraph"><p>When the Tcl library receives commands it parses them into component
1130 fields and executes built-in commands directly. For commands implemented
1131 by the application, Tcl calls back to the application to execute the
1132 commands. In many cases commands will invoke recursive invocations of the
1133 Tcl interpreter by passing in additional strings to execute (procedures,
1134 looping commands, and conditional commands all work in this way).
</p></div>
1135 <div class=
"paragraph"><p>An application program gains three advantages by using Tcl for its command
1136 language. First, Tcl provides a standard syntax: once users know Tcl,
1137 they will be able to issue commands easily to any Tcl-based application.
1138 Second, Tcl provides programmability. All a Tcl application needs
1139 to do is to implement a few application-specific low-level commands.
1140 Tcl provides many utility commands plus a general programming interface
1141 for building up complex command procedures. By using Tcl, applications
1142 need not re-implement these features.
</p></div>
1143 <div class=
"paragraph"><p>Third, Tcl can be used as a common language for communicating between
1144 applications. Inter-application communication is not built into the
1145 Tcl core described here, but various add-on libraries, such as the Tk
1146 toolkit, allow applications to issue commands to each other. This makes
1147 it possible for applications to work together in much more powerful ways
1148 than was previously possible.
</p></div>
1149 <div class=
"paragraph"><p>Fourth, Jim Tcl includes a command processor,
<code>jimsh
</code>, which can be
1150 used to run standalone Tcl scripts, or to run Tcl commands interactively.
</p></div>
1151 <div class=
"paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
1152 the language syntax and the built-in commands that will be available
1153 in any application based on Tcl. The individual library procedures are
1154 described in more detail in separate manual pages, one per procedure.
</p></div>
1158 <h2 id=
"_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER
</h2>
1159 <div class=
"sectionbody">
1160 <div class=
"paragraph"><p>A simple, but powerful command processor,
<code>jimsh
</code>, is part of Jim Tcl.
1161 It may be invoked in interactive mode as:
</p></div>
1162 <div class=
"literalblock">
1163 <div class=
"content">
1164 <pre><code>jimsh
</code></pre>
1166 <div class=
"paragraph"><p>or to process the Tcl script in a file with:
</p></div>
1167 <div class=
"literalblock">
1168 <div class=
"content">
1169 <pre><code>jimsh filename
</code></pre>
1171 <div class=
"paragraph"><p>or to process the Tcl script from standard input:
</p></div>
1172 <div class=
"literalblock">
1173 <div class=
"content">
1174 <pre><code>jimsh -
</code></pre>
1176 <div class=
"paragraph"><p>It may also be invoked to execute an immediate script with:
</p></div>
1177 <div class=
"literalblock">
1178 <div class=
"content">
1179 <pre><code>jimsh -e
"script"</code></pre>
1182 <h3 id=
"_interactive_mode">Interactive Mode
</h3>
1183 <div class=
"paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
1184 those commands and prints the results.
</p></div>
1185 <div class=
"literalblock">
1186 <div class=
"content">
1188 Welcome to Jim version
0.73, Copyright (c)
2005-
8 Salvatore Sanfilippo
1191 . lsort [info commands p*]
1192 package parray pid popen proc puts pwd
1193 . foreach i {a b c} {
1200 invalid command name
"bad"
1204 <div class=
"paragraph"><p>If
<code>jimsh
</code> is configured with line editing (it is by default) and a VT-
100-compatible
1205 terminal is detected, Emacs-style line editing commands are available, including:
1206 arrow keys,
<code>^W
</code> to erase a word,
<code>^U
</code> to erase the line,
<code>^R
</code> for reverse incremental search
1207 in history. Additionally, the
<code>h
</code> command may be used to display the command history.
</p></div>
1208 <div class=
"paragraph"><p>Command line history is automatically saved and loaded from
<code>~/.jim_history
</code></p></div>
1209 <div class=
"paragraph"><p>In interactive mode,
<code>jimsh
</code> automatically runs the script
<code>~/.jimrc
</code> at startup
1210 if it exists.
</p></div>
1215 <h2 id=
"_interpreters">INTERPRETERS
</h2>
1216 <div class=
"sectionbody">
1217 <div class=
"paragraph"><p>The central data structure in Tcl is an interpreter (C type
<em>Jim_Interp
</em>).
1218 An interpreter consists of a set of command bindings, a set of variable
1219 values, and a few other miscellaneous pieces of state. Each Tcl command
1220 is interpreted in the context of a particular interpreter.
</p></div>
1221 <div class=
"paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
1222 simultaneously, each associated with a different widget or portion of
1223 the application. Interpreters are relatively lightweight structures.
1224 They can be created and deleted quickly, so application programmers should
1225 feel free to use multiple interpreters if that simplifies the application.
</p></div>
1229 <h2 id=
"_data_types">DATA TYPES
</h2>
1230 <div class=
"sectionbody">
1231 <div class=
"paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
1232 to commands, all command results, and all variable values are strings.
</p></div>
1233 <div class=
"paragraph"><p>Where commands require numeric arguments or return numeric results,
1234 the arguments and results are passed as strings. Many commands expect
1235 their string arguments to have certain formats, but this interpretation
1236 is up to the individual commands. For example, arguments often contain
1237 Tcl command strings, which may get executed as part of the commands.
1238 The easiest way to understand the Tcl interpreter is to remember that
1239 everything is just an operation on a string. In many cases Tcl constructs
1240 will look similar to more structured constructs from other languages.
1241 However, the Tcl constructs are not structured at all; they are just
1242 strings of characters, and this gives them a different behaviour than
1243 the structures they may look like.
</p></div>
1244 <div class=
"paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
1245 the interpretation, there are three common forms that strings take:
1246 commands, expressions, and lists. The major sections below discuss
1247 these three forms in more detail.
</p></div>
1251 <h2 id=
"_basic_command_syntax">BASIC COMMAND SYNTAX
</h2>
1252 <div class=
"sectionbody">
1253 <div class=
"paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
1254 and Lisp. However, the interpretation of commands is different
1255 in Tcl than in either of those other two systems.
1256 A Tcl command string consists of one or more commands separated
1257 by newline characters or semi-colons.
1258 Each command consists of a collection of fields separated by
1259 white space (spaces or tabs).
1260 The first field must be the name of a command, and the
1261 additional fields, if any, are arguments that will be passed to
1262 that command. For example, the command:
</p></div>
1263 <div class=
"listingblock">
1264 <div class=
"content">
1265 <pre><code> set a
22</code></pre>
1267 <div class=
"paragraph"><p>has three fields: the first,
<a href=
"#_set"><strong><code>set
</code></strong></a>, is the name of a Tcl command, and
1268 the last two,
<em>a
</em> and
<em>22</em>, will be passed as arguments to
1269 the
<a href=
"#_set"><strong><code>set
</code></strong></a> command. The command name may refer either to a built-in
1270 Tcl command, an application-specific command bound in with the library
1271 procedure
<em>Jim_CreateCommand
</em>, or a command procedure defined with the
1272 <a href=
"#_proc"><strong><code>proc
</code></strong></a> built-in command.
</p></div>
1273 <div class=
"paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1274 interpret those strings in any fashion they wish. The
<a href=
"#_set"><strong><code>set
</code></strong></a> command,
1275 for example, will treat its first argument as the name of a variable
1276 and its second argument as a string value to assign to that variable.
1277 For other commands arguments may be interpreted as integers, lists,
1278 file names, or Tcl commands.
</p></div>
1279 <div class=
"paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1280 However, if the Tcl interpreter cannot locate a command it invokes a
1281 special command named
<a href=
"#_unknown"><strong><code>unknown
</code></strong></a> which attempts to find or create the
1283 <div class=
"paragraph"><p>For example, at many sites
<a href=
"#_unknown"><strong><code>unknown
</code></strong></a> will search through library
1284 directories for the desired command and create it as a Tcl procedure if
1285 it is found. The
<a href=
"#_unknown"><strong><code>unknown
</code></strong></a> command often provides automatic completion
1286 of abbreviated commands, but usually only for commands that were typed
1287 interactively.
</p></div>
1288 <div class=
"paragraph"><p>It
’s probably a bad idea to use abbreviations in command scripts and
1289 other forms that will be re-used over time: changes to the command set
1290 may cause abbreviations to become ambiguous, resulting in scripts that
1291 no longer work.
</p></div>
1295 <h2 id=
"_comments">COMMENTS
</h2>
1296 <div class=
"sectionbody">
1297 <div class=
"paragraph"><p>If the first non-blank character in a command is
<code>#
</code>, then everything
1298 from the
<code>#
</code> up through the next newline character is treated as
1299 a comment and ignored. When comments are embedded inside nested
1300 commands (e.g. fields enclosed in braces) they must have properly-matched
1301 braces (this is necessary because when Tcl parses the top-level command
1302 it doesn
’t yet know that the nested field will be used as a command so
1303 it cannot process the nested comment character as a comment).
</p></div>
1307 <h2 id=
"_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES
</h2>
1308 <div class=
"sectionbody">
1309 <div class=
"paragraph"><p>Normally each argument field ends at the next white space, but
1310 double-quotes may be used to create arguments with embedded space.
</p></div>
1311 <div class=
"paragraph"><p>If an argument field begins with a double-quote, then the argument isn
’t
1312 terminated by white space (including newlines) or a semi-colon (see below
1313 for information on semi-colons); instead it ends at the next double-quote
1314 character. The double-quotes are not included in the resulting argument.
1315 For example, the command
</p></div>
1316 <div class=
"listingblock">
1317 <div class=
"content">
1318 <pre><code> set a
"This is a single argument"</code></pre>
1320 <div class=
"paragraph"><p>will pass two arguments to
<a href=
"#_set"><strong><code>set
</code></strong></a>:
<em>a
</em> and
<em>This is a single argument
</em>.
</p></div>
1321 <div class=
"paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1322 and backslash substitutions still occur, as described below. If the
1323 first character of a command field is not a quote, then quotes receive
1324 no special interpretation in the parsing of that field.
</p></div>
1328 <h2 id=
"_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES
</h2>
1329 <div class=
"sectionbody">
1330 <div class=
"paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1331 to quotes except for two differences. First, they nest; this makes them
1332 easier to use for complicated arguments like nested Tcl command strings.
1333 Second, the substitutions described below for commands, variables, and
1334 backslashes do
<strong>not
</strong> occur in arguments enclosed in braces, so braces
1335 can be used to prevent substitutions where they are undesirable.
</p></div>
1336 <div class=
"paragraph"><p>If an argument field begins with a left brace, then the argument ends
1337 at the matching right brace. Tcl will strip off the outermost layer
1338 of braces and pass the information between the braces to the command
1339 without any further modification. For example, in the command
</p></div>
1340 <div class=
"listingblock">
1341 <div class=
"content">
1342 <pre><code> set a {xyz a {b c d}}
</code></pre>
1344 <div class=
"paragraph"><p>the
<a href=
"#_set"><strong><code>set
</code></strong></a> command will receive two arguments:
<em>a
</em>
1345 and
<em>xyz a {b c d}
</em>.
</p></div>
1346 <div class=
"paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1347 not be on the same line as the starting quote or brace; in this case
1348 the newline will be included in the argument field along with any other
1349 characters up to the matching brace or quote. For example, the
<a href=
"#_eval"><strong><code>eval
</code></strong></a>
1350 command takes one argument, which is a command string;
<a href=
"#_eval"><strong><code>eval
</code></strong></a> invokes
1351 the Tcl interpreter to execute the command string. The command
</p></div>
1352 <div class=
"listingblock">
1353 <div class=
"content">
1359 <div class=
"paragraph"><p>will assign the value
<em>22</em> to
<em>a
</em> and
<em>33</em> to
<em>b
</em>.
</p></div>
1360 <div class=
"paragraph"><p>If the first character of a command field is not a left
1361 brace, then neither left nor right
1362 braces in the field will be treated specially (except as part of
1363 variable substitution; see below).
</p></div>
1367 <h2 id=
"_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS
</h2>
1368 <div class=
"sectionbody">
1369 <div class=
"paragraph"><p>If an open bracket occurs in a field of a command, then command
1370 substitution occurs (except for fields enclosed in braces). All of the
1371 text up to the matching close bracket is treated as a Tcl command and
1372 executed immediately. Then the result of that command is substituted
1373 for the bracketed text. For example, consider the command
</p></div>
1374 <div class=
"listingblock">
1375 <div class=
"content">
1376 <pre><code> set a [set b]
</code></pre>
1378 <div class=
"paragraph"><p>When the
<a href=
"#_set"><strong><code>set
</code></strong></a> command has only a single argument, it is the name of a
1379 variable and
<a href=
"#_set"><strong><code>set
</code></strong></a> returns the contents of that variable. In this case,
1380 if variable
<em>b
</em> has the value
<em>foo
</em>, then the command above is equivalent
1381 to the command
</p></div>
1382 <div class=
"listingblock">
1383 <div class=
"content">
1384 <pre><code> set a foo
</code></pre>
1386 <div class=
"paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1387 <em>b
</em> has the value
<em>foo
</em> and the variable
<em>c
</em> has the value
<em>gorp
</em>,
1388 then the command
</p></div>
1389 <div class=
"listingblock">
1390 <div class=
"content">
1391 <pre><code> set a xyz[set b].[set c]
</code></pre>
1393 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1394 <div class=
"listingblock">
1395 <div class=
"content">
1396 <pre><code> set a xyzfoo.gorp
</code></pre>
1398 <div class=
"paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1399 or semi-colons in the usual fashion. In this case the value of the last
1400 command is used for substitution. For example, the command
</p></div>
1401 <div class=
"listingblock">
1402 <div class=
"content">
1403 <pre><code> set a x[set b
22
1404 expr $b+
2]x
</code></pre>
1406 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1407 <div class=
"listingblock">
1408 <div class=
"content">
1409 <pre><code> set a x24x
</code></pre>
1411 <div class=
"paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1412 between them are not interpreted specially; they are passed through to
1413 the argument verbatim.
</p></div>
1417 <h2 id=
"_variable_substitution_with">VARIABLE SUBSTITUTION WITH $
</h2>
1418 <div class=
"sectionbody">
1419 <div class=
"paragraph"><p>The dollar sign (
<code>$
</code>) may be used as a special shorthand form for
1420 substituting variable values. If
<code>$
</code> appears in an argument that isn
’t
1421 enclosed in braces then variable substitution will occur. The characters
1422 after the
<code>$
</code>, up to the first character that isn
’t a number, letter,
1423 or underscore, are taken as a variable name and the string value of that
1424 variable is substituted for the name.
</p></div>
1425 <div class=
"paragraph"><p>For example, if variable
<em>foo
</em> has the value
<em>test
</em>, then the command
</p></div>
1426 <div class=
"listingblock">
1427 <div class=
"content">
1428 <pre><code> set a $foo.c
</code></pre>
1430 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1431 <div class=
"listingblock">
1432 <div class=
"content">
1433 <pre><code> set a test.c
</code></pre>
1435 <div class=
"paragraph"><p>There are two special forms for variable substitution. If the next
1436 character after the name of the variable is an open parenthesis, then
1437 the variable is assumed to be an array name, and all of the characters
1438 between the open parenthesis and the next close parenthesis are taken as
1439 an index into the array. Command substitutions and variable substitutions
1440 are performed on the information between the parentheses before it is
1441 used as an index.
</p></div>
1442 <div class=
"paragraph"><p>For example, if the variable
<em>x
</em> is an array with one element named
1443 <em>first
</em> and value
<em>87</em> and another element named
<em>14</em> and value
<em>more
</em>,
1444 then the command
</p></div>
1445 <div class=
"listingblock">
1446 <div class=
"content">
1447 <pre><code> set a xyz$x(first)zyx
</code></pre>
1449 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1450 <div class=
"listingblock">
1451 <div class=
"content">
1452 <pre><code> set a xyz87zyx
</code></pre>
1454 <div class=
"paragraph"><p>If the variable
<em>index
</em> has the value
<em>14</em>, then the command
</p></div>
1455 <div class=
"listingblock">
1456 <div class=
"content">
1457 <pre><code> set a xyz$x($index)zyx
</code></pre>
1459 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1460 <div class=
"listingblock">
1461 <div class=
"content">
1462 <pre><code> set a xyzmorezyx
</code></pre>
1464 <div class=
"paragraph"><p>For more information on arrays, see
<a href=
"#_variables_scalars_and_arrays">VARIABLES - SCALARS AND ARRAYS
</a> below.
</p></div>
1465 <div class=
"paragraph"><p>The second special form for variables occurs when the dollar sign is
1466 followed by an open curly brace. In this case the variable name consists
1467 of all the characters up to the next curly brace.
</p></div>
1468 <div class=
"paragraph"><p>Array references are not possible in this form: the name between braces
1469 is assumed to refer to a scalar variable. For example, if variable
1470 <em>foo
</em> has the value
<em>test
</em>, then the command
</p></div>
1471 <div class=
"listingblock">
1472 <div class=
"content">
1473 <pre><code> set a abc${foo}bar
</code></pre>
1475 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1476 <div class=
"listingblock">
1477 <div class=
"content">
1478 <pre><code> set a abctestbar
</code></pre>
1480 <div class=
"paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1481 braces: the dollar sign and variable name are passed through to the
1482 argument verbatim.
</p></div>
1483 <div class=
"paragraph"><p>The dollar sign abbreviation is simply a shorthand form.
<code>$a
</code> is
1484 completely equivalent to
<code>[set a]
</code>; it is provided as a convenience
1485 to reduce typing.
</p></div>
1489 <h2 id=
"_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS
</h2>
1490 <div class=
"sectionbody">
1491 <div class=
"paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1492 newline character). However, semi-colon (
<code>;
</code>) is treated as a command
1493 separator character; multiple commands may be placed on one line by
1494 separating them with a semi-colon. Semi-colons are not treated as
1495 command separators if they appear within curly braces or double-quotes.
</p></div>
1499 <h2 id=
"_backslash_substitution">BACKSLASH SUBSTITUTION
</h2>
1500 <div class=
"sectionbody">
1501 <div class=
"paragraph"><p>Backslashes may be used to insert non-printing characters into command
1502 fields and also to insert special characters like braces and brackets
1503 into fields without them being interpreted specially as described above.
</p></div>
1504 <div class=
"paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1505 listed below. In each case, the backslash
1506 sequence is replaced by the given character:
</p></div>
1507 <div class=
"dlist" id=
"BackslashSequences"><dl>
1508 <dt class=
"hdlist1">
1516 <dt class=
"hdlist1">
1524 <dt class=
"hdlist1">
1532 <dt class=
"hdlist1">
1537 Carriage-return (
0xd).
1540 <dt class=
"hdlist1">
1548 <dt class=
"hdlist1">
1556 <dt class=
"hdlist1">
1564 <dt class=
"hdlist1">
1572 <dt class=
"hdlist1">
1580 <dt class=
"hdlist1">
1588 <dt class=
"hdlist1">
1596 <dt class=
"hdlist1">
1597 <code>\
<space
></code>
1601 Space ( ): doesn
’t terminate argument.
1604 <dt class=
"hdlist1">
1609 Semi-colon: doesn
’t terminate command.
1612 <dt class=
"hdlist1">
1620 <dt class="hdlist1
">
1621 <code>\<newline></code>
1625 Nothing: this joins two lines together
1626 into a single line. This backslash feature is unique in that
1627 it will be applied even when the sequence occurs within braces.
1630 <dt class="hdlist1
">
1635 Backslash (<em>\</em>).
1638 <dt class="hdlist1
">
1643 The digits <code><em>ddd</em></code> (one, two, or three of them) give the octal value of
1644 the character. Note that Jim supports null characters in strings.
1647 <dt class="hdlist1
">
1650 <dt class="hdlist1
">
1651 <code>\u{nnn}</code>
1653 <dt class="hdlist1
">
1654 <code>\Unnnnnnnn</code>
1658 The UTF-8 encoding of the unicode codepoint represented by the hex digits, <code><em>nnnn</em></code>, is inserted.
1659 The <em>u</em> form allows for one to four hex digits.
1660 The <em>U</em> form allows for one to eight hex digits.
1661 The <em>u{nnn}</em> form allows for one to eight hex digits, but makes it easier to insert
1662 characters UTF-8 characters which are followed by a hex digit.
1666 <div class="paragraph
"><p>For example, in the command</p></div>
1667 <div class="listingblock
">
1668 <div class="content
">
1669 <pre><code> set a \{x\[\ yz\141</code></pre>
1671 <div class="paragraph
"><p>the second argument to <a href="#_set
"><strong><code>set</code></strong></a> will be <code>{x[ yza</code>.</p></div>
1672 <div class="paragraph
"><p>If a backslash is followed by something other than one of the options
1673 described above, then the backslash is transmitted to the argument
1674 field without any special processing, and the Tcl scanner continues
1675 normal processing with the next character. For example, in the
1677 <div class="listingblock
">
1678 <div class="content
">
1679 <pre><code> set \*a \\\{foo</code></pre>
1681 <div class="paragraph
"><p>The first argument to <a href="#_set
"><strong><code>set</code></strong></a> will be <code>\*a</code> and the second
1682 argument will be <code>\{foo</code>.</p></div>
1683 <div class="paragraph
"><p>If an argument is enclosed in braces, then backslash sequences inside
1684 the argument are parsed but no substitution occurs (except for
1685 backslash-newline): the backslash
1686 sequence is passed through to the argument as is, without making
1687 any special interpretation of the characters in the backslash sequence.
1688 In particular, backslashed braces are not counted in locating the
1689 matching right brace that terminates the argument.
1692 <div class="listingblock
">
1693 <div class="content
">
1694 <pre><code> set a {\{abc}</code></pre>
1696 <div class="paragraph
"><p>the second argument to <a href="#_set
"><strong><code>set</code></strong></a> will be <code>\{abc</code>.</p></div>
1697 <div class="paragraph
"><p>This backslash mechanism is not sufficient to generate absolutely
1698 any argument structure; it only covers the
1699 most common cases. To produce particularly complicated arguments
1700 it is probably easiest to use the <a href="#_format
"><strong><code>format</code></strong></a> command along with
1701 command substitution.</p></div>
1705 <h2 id="_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</h2>
1706 <div class="sectionbody
">
1707 <div class="paragraph
"><p>Many string and list commands take one or more <em>index</em> parameters which
1708 specify a position in the string relative to the start or end of the string/list.</p></div>
1709 <div class="paragraph
"><p>The index may be one of the following forms:</p></div>
1710 <div class="dlist
"><dl>
1711 <dt class="hdlist1
">
1712 <code>integer</code>
1716 A simple integer, where <em>0</em> refers to the first element of the string
1720 <dt class="hdlist1
">
1721 <code>integer+integer</code> or
1723 <dt class="hdlist1
">
1724 <code>integer-integer</code>
1728 The sum or difference of the two integers. e.g. <code>2+3</code> refers to the 5th element.
1729 This is useful when used with (e.g.) <code>$i+1</code> rather than the more verbose
1730 <code>[expr {$i+1}]</code>
1733 <dt class="hdlist1
">
1738 The last element of the string or list.
1741 <dt class="hdlist1
">
1742 <code>end-integer</code>
1746 The <em>nth-from-last</em> element of the string or list.
1753 <h2 id="_command_summary
">COMMAND SUMMARY</h2>
1754 <div class="sectionbody
">
1755 <div class="olist arabic
"><ol class="arabic
">
1758 A command is just a string.
1763 Within a string commands are separated by newlines or semi-colons
1764 (unless the newline or semi-colon is within braces or brackets
1770 A command consists of fields. The first field is the name of the command.
1771 The other fields are strings that are passed to that command as arguments.
1776 Fields are normally separated by white space.
1781 Double-quotes allow white space and semi-colons to appear within
1783 Command substitution, variable substitution, and backslash substitution
1784 still occur inside quotes.
1789 Braces defer interpretation of special characters.
1790 If a field begins with a left brace, then it consists of everything
1791 between the left brace and the matching right brace. The
1792 braces themselves are not included in the argument.
1793 No further processing is done on the information between the braces
1794 except that backslash-newline sequences are eliminated.
1799 If a field doesn’t begin with a brace then backslash,
1800 variable, and command substitution are done on the field. Only a
1801 single level of processing is done: the results of one substitution
1802 are not scanned again for further substitutions or any other
1803 special treatment. Substitution can
1804 occur on any field of a command, including the command name
1805 as well as the arguments.
1810 If the first non-blank character of a command is a <code>#</code>, everything
1811 from the <code>#</code> up through the next newline is treated as a comment
1819 <h2 id="_expressions
">EXPRESSIONS</h2>
1820 <div class="sectionbody
">
1821 <div class="paragraph
"><p>The second major interpretation applied to strings in Tcl is
1822 as expressions. Several commands, such as <a href="#_expr
"><strong><code>expr</code></strong></a>, <a href="#_for
"><strong><code>for</code></strong></a>,
1823 and <a href="#_if
"><strong><code>if</code></strong></a>, treat one or more of their arguments as expressions
1824 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
1825 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
1826 <div class="paragraph
"><p>The operators permitted in Tcl expressions are a subset of
1827 the operators permitted in C expressions, and they have the
1828 same meaning and precedence as the corresponding C operators.
1829 Expressions almost always yield numeric results
1830 (integer or floating-point values).
1831 For example, the expression</p></div>
1832 <div class="listingblock
">
1833 <div class="content
">
1834 <pre><code> 8.2 + 6</code></pre>
1836 <div class="paragraph
"><p>evaluates to 14.2.</p></div>
1837 <div class="paragraph
"><p>Tcl expressions differ from C expressions in the way that
1838 operands are specified, and in that Tcl expressions support
1839 non-numeric operands and string comparisons.</p></div>
1840 <div class="paragraph
"><p>A Tcl expression consists of a combination of operands, operators,
1841 and parentheses.</p></div>
1842 <div class="paragraph
"><p>White space may be used between the operands and operators and
1843 parentheses; it is ignored by the expression processor.
1844 Where possible, operands are interpreted as integer values.</p></div>
1845 <div class="paragraph
"><p>Integer values may be specified in decimal (the normal case) or in
1846 hexadecimal (if the first two characters of the operand are <em>0x</em>).
1847 Note that Jim Tcl does <strong>not</strong> treat numbers with leading zeros as octal.</p></div>
1848 <div class="paragraph
"><p>If an operand does not have one of the integer formats given
1849 above, then it is treated as a floating-point number if that is
1850 possible. Floating-point numbers may be specified in any of the
1851 ways accepted by an ANSI-compliant C compiler (except that the
1852 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
1853 most installations). For example, all of the
1854 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
1855 <div class="paragraph
"><p>If no numeric interpretation is possible, then an operand is left
1856 as a string (and only a limited set of operators may be applied to
1858 <div class="paragraph
"><p>String constants representing boolean constants
1859 (<code><em>0</em></code>, <code><em>1</em></code>, <code><em>false</em></code>, <code><em>off</em></code>, <code><em>no</em></code>, <code><em>true</em></code>, <code><em>on</em></code>, <code><em>yes</em></code>)
1860 are also recognized and can be used in logical operations.</p></div>
1861 <div class="olist arabic
"><ol class="arabic
">
1864 Operands may be specified in any of the following ways:
1869 As a numeric value, either integer or floating-point.
1874 As one of valid boolean constants
1879 As a Tcl variable, using standard <em>$</em> notation.
1880 The variable’s value will be used as the operand.
1885 As a string enclosed in double-quotes.
1886 The expression parser will perform backslash, variable, and
1887 command substitutions on the information between the quotes,
1888 and use the resulting value as the operand
1893 As a string enclosed in braces.
1894 The characters between the open brace and matching close brace
1895 will be used as the operand without any substitutions.
1900 As a Tcl command enclosed in brackets.
1901 The command will be executed and its result will be used as
1906 <div class="paragraph
"><p>Where substitutions occur above (e.g. inside quoted strings), they
1907 are performed by the expression processor.
1908 However, an additional layer of substitution may already have
1909 been performed by the command parser before the expression
1910 processor was called.</p></div>
1911 <div class="paragraph
"><p>As discussed below, it is usually best to enclose expressions
1912 in braces to prevent the command parser from performing substitutions
1913 on the contents.</p></div>
1914 <div class="paragraph
"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
1915 the value 3 and the variable <em>b</em> has the value 6. Then the expression
1916 on the left side of each of the lines below will evaluate to the value
1917 on the right side of the line:</p></div>
1918 <div class="listingblock
">
1919 <div class="content
">
1920 <pre><code> $a + 3.1 6.1
1923 {word one} < "word $a
" 0</code></pre>
1925 <div class="paragraph
"><p>The valid operators are listed below, grouped in decreasing order
1926 of precedence:</p></div>
1927 <div class="dlist
" id="OperatorPrecedence
"><dl>
1928 <dt class="hdlist1
">
1929 <code>int() double() round() abs(), rand(), srand()</code>
1933 Unary functions (except rand() which takes no arguments)
1935 <div class="ulist
"><ul>
1938 <code><em>int()</em></code> converts the numeric argument to an integer by truncating down.
1943 <code><em>double()</em></code> converts the numeric argument to floating point.
1948 <code><em>round()</em></code> converts the numeric argument to the closest integer value.
1953 <code><em>abs()</em></code> takes the absolute value of the numeric argument.
1958 <code><em>rand()</em></code> returns a pseudo-random floating-point value in the range (0,1).
1963 <code><em>srand()</em></code> takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
1968 <dt class="hdlist1
">
1969 <code>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</code>
1973 Unary math functions.
1974 If Jim is compiled with math support, these functions are available.
1977 <dt class="hdlist1
">
1978 <code>- + ~ !</code>
1982 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
1983 may be applied to string operands, and bit-wise NOT may be
1984 applied only to integers.
1987 <dt class="hdlist1
">
1988 <code>** pow(x,y)</code>
1992 Power. e.g. <em>x<sup>y</sup></em>. If Jim is compiled with math support, supports doubles and
1993 integers. Otherwise supports integers only. (Note that the math-function form
1994 has the same highest precedence)
1997 <dt class="hdlist1
">
2002 Multiply, divide, remainder. None of these operands may be
2003 applied to string operands, and remainder may be applied only
2007 <dt class="hdlist1
">
2012 Add and subtract. Valid for any numeric operands.
2015 <dt class="hdlist1
">
2016 <code><< >> <<< >>></code>
2020 Left and right shift, left and right rotate. Valid for integer operands only.
2023 <dt class="hdlist1
">
2024 <code>< > <= >=</code>
2028 Boolean less, greater, less than or equal, and greater than or equal.
2029 Each operator produces 1 if the condition is true, 0 otherwise.
2030 These operators may be applied to strings as well as numeric operands,
2031 in which case string comparison is used.
2034 <dt class="hdlist1
">
2039 Boolean equal and not equal. Each operator produces a zero/one result.
2040 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
2041 if possible, then floating point types, and finally strings will be compared.
2042 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
2045 <dt class="hdlist1
">
2050 String equal and not equal. Uses the string value directly without
2051 attempting to convert to a number first.
2054 <dt class="hdlist1
">
2059 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
2060 is contained in the right operand (as a list), or 0 otherwise. The result for
2061 <code>{$a ni $list}</code> is equivalent to <code>{!($a in $list)}</code>.
2064 <dt class="hdlist1
">
2069 Bit-wise AND. Valid for integer operands only.
2072 <dt class="hdlist1
">
2077 Bit-wise OR. Valid for integer operands only.
2080 <dt class="hdlist1
">
2085 Bit-wise exclusive OR. Valid for integer operands only.
2088 <dt class="hdlist1
">
2089 <code>&&</code>
2093 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
2094 Valid for numeric operands only (integers or floating-point).
2097 <dt class="hdlist1
">
2102 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
2103 Valid for numeric operands only (integers or floating-point).
2106 <dt class="hdlist1
">
2107 <code>x ? y : z</code>
2111 If-then-else, as in C. If <code><em>x</em></code>
2112 evaluates to non-zero, then the result is the value of <code><em>y</em></code>.
2113 Otherwise the result is the value of <code><em>z</em></code>.
2114 The <code><em>x</em></code> operand must have a numeric value, while <code><em>y</em></code> and <code><em>z</em></code> can
2119 <div class="paragraph
"><p>See the C manual for more details on the results
2120 produced by each operator.
2121 All of the binary operators group left-to-right within the same
2122 precedence level. For example, the expression</p></div>
2123 <div class="listingblock
">
2124 <div class="content
">
2125 <pre><code> 4*2 < 7</code></pre>
2127 <div class="paragraph
"><p>evaluates to 0.</p></div>
2128 <div class="paragraph
"><p>The <code>&&</code>, <code>||</code>, and <code>?:</code> operators have <em>lazy evaluation</em>, just as
2129 in C, which means that operands are not evaluated if they are not
2130 needed to determine the outcome. For example, in</p></div>
2131 <div class="listingblock
">
2132 <div class="content
">
2133 <pre><code> $v ? [a] : [b]</code></pre>
2135 <div class="paragraph
"><p>only one of <code>[a]</code> or <code>[b]</code> will actually be evaluated,
2136 depending on the value of <code>$v</code>.</p></div>
2137 <div class="paragraph
"><p>All internal computations involving integers are done with the C
2138 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
2139 computations involving floating-point are done with the C type
2140 <em>double</em>.</p></div>
2141 <div class="paragraph
"><p>When converting a string to floating-point, exponent overflow is
2142 detected and results in a Tcl error.
2143 For conversion to integer from string, detection of overflow depends
2144 on the behaviour of some routines in the local C library, so it should
2145 be regarded as unreliable.
2146 In any case, overflow and underflow are generally not detected
2147 reliably for intermediate results.</p></div>
2148 <div class="paragraph
"><p>Conversion among internal representations for integer, floating-point,
2149 string operands is done automatically as needed.
2150 For arithmetic computations, integers are used until some
2151 floating-point number is introduced, after which floating-point is used.
2152 For example,</p></div>
2153 <div class="listingblock
">
2154 <div class="content
">
2155 <pre><code> 5 / 4</code></pre>
2157 <div class="paragraph
"><p>yields the result 1, while</p></div>
2158 <div class="listingblock
">
2159 <div class="content
">
2161 5 / ( [string length "abcd
"] + 0.0 )</code></pre>
2163 <div class="paragraph
"><p>both yield the result 1.25.</p></div>
2164 <div class="paragraph
"><p>String values may be used as operands of the comparison operators,
2165 although the expression evaluator tries to do comparisons as integer
2166 or floating-point when it can.
2167 If one of the operands of a comparison is a string and the other
2168 has a numeric value, the numeric operand is converted back to
2169 a string using the C <em>sprintf</em> format specifier
2170 <em>%d</em> for integers and <em>%g</em> for floating-point values.
2171 For example, the expressions</p></div>
2172 <div class="listingblock
">
2173 <div class="content
">
2174 <pre><code> "0x03" > "2"
2175 "0y
" < "0x12"</code></pre>
2177 <div class="paragraph
"><p>both evaluate to 1. The first comparison is done using integer
2178 comparison, and the second is done using string comparison after
2179 the second operand is converted to the string <em>18</em>.</p></div>
2180 <div class="paragraph
"><p>In general it is safest to enclose an expression in braces when
2181 entering it in a command: otherwise, if the expression contains
2182 any white space then the Tcl interpreter will split it
2183 among several arguments. For example, the command</p></div>
2184 <div class="listingblock
">
2185 <div class="content
">
2186 <pre><code> expr $a + $b</code></pre>
2188 <div class="paragraph
"><p>results in three arguments being passed to <a href="#_expr
"><strong><code>expr</code></strong></a>: <code>$a</code>,
2189 +, and <code>$b</code>. In addition, if the expression isn’t in braces
2190 then the Tcl interpreter will perform variable and command substitution
2191 immediately (it will happen in the command parser rather than in
2192 the expression parser). In many cases the expression is being
2193 passed to a command that will evaluate the expression later (or
2194 even many times if, for example, the expression is to be used to
2195 decide when to exit a loop). Usually the desired goal is to re-do
2196 the variable or command substitutions each time the expression is
2197 evaluated, rather than once and for all at the beginning. For example,
2198 the command</p></div>
2199 <div class="listingblock
">
2200 <div class="content
">
2201 <pre><code> for {set i 1} $i<=10 {incr i} {...} ** WRONG **</code></pre>
2203 <div class="paragraph
"><p>is probably intended to iterate over all values of <code>i</code> from 1 to 10.
2204 After each iteration of the body of the loop, <a href="#_for
"><strong><code>for</code></strong></a> will pass
2205 its second argument to the expression evaluator to see whether or not
2206 to continue processing. Unfortunately, in this case the value of <code>i</code>
2207 in the second argument will be substituted once and for all when the
2208 <a href="#_for
"><strong><code>for</code></strong></a> command is parsed. If <code>i</code> was 0 before the <a href="#_for
"><strong><code>for</code></strong></a>
2209 command was invoked then the second argument of <a href="#_for
"><strong><code>for</code></strong></a> will be <code>0<=10</code>
2210 which will always evaluate to 1, even though <code>i</code> eventually
2211 becomes greater than 10. In the above case the loop will never
2212 terminate. Instead, the expression should be placed in braces:</p></div>
2213 <div class="listingblock
">
2214 <div class="content
">
2215 <pre><code> for {set i 1} {$i<=10} {incr i} {...} ** RIGHT **</code></pre>
2217 <div class="paragraph
"><p>This causes the substitution of <em>i</em>
2218 to be delayed; it will be re-done each time the expression is
2219 evaluated, which is the desired result.</p></div>
2223 <h2 id="_lists
">LISTS</h2>
2224 <div class="sectionbody
">
2225 <div class="paragraph
"><p>The third major way that strings are interpreted in Tcl is as lists.
2226 A list is just a string with a list-like structure
2227 consisting of fields separated by white space. For example, the
2229 <div class="listingblock
">
2230 <div class="content
">
2231 <pre><code> Al Sue Anne John</code></pre>
2233 <div class="paragraph
"><p>is a list with four elements or fields.
2234 Lists have the same basic structure as command strings, except
2235 that a newline character in a list is treated as a field separator
2236 just like space or tab. Conventions for braces and quotes
2237 and backslashes are the same for lists as for commands. For example,
2238 the string</p></div>
2239 <div class="listingblock
">
2240 <div class="content
">
2241 <pre><code> a b\ c {d e {f g h}}</code></pre>
2243 <div class="paragraph
"><p>is a list with three elements: <code>a</code>, <code>b c</code>, and <code>d e {f g h}</code>.</p></div>
2244 <div class="paragraph
"><p>Whenever an element is extracted from a list, the same rules about
2245 braces and quotes and backslashes are applied as for commands. Thus in
2246 the example above when the third element is extracted from the list,
2247 the result is</p></div>
2248 <div class="listingblock
">
2249 <div class="content
">
2250 <pre><code> d e {f g h}</code></pre>
2252 <div class="paragraph
"><p>(when the field was extracted, all that happened was to strip off
2253 the outermost layer of braces). Command substitution and
2254 variable substitution are never
2255 made on a list (at least, not by the list-processing commands; the
2256 list can always be passed to the Tcl interpreter for evaluation).</p></div>
2257 <div class="paragraph
"><p>The Tcl commands <a href="#_concat
"><strong><code>concat</code></strong></a>, <a href="#_foreach
"><strong><code>foreach</code></strong></a>, <a href="#_lappend
"><strong><code>lappend</code></strong></a>, <a href="#_lindex
"><strong><code>lindex</code></strong></a>, <a href="#_linsert
"><strong><code>linsert</code></strong></a>,
2258 <a href="#_list
"><strong><code>list</code></strong></a>, <a href="#_llength
"><strong><code>llength</code></strong></a>, <a href="#_lrange
"><strong><code>lrange</code></strong></a>, <a href="#_lreplace
"><strong><code>lreplace</code></strong></a>, <a href="#_lsearch
"><strong><code>lsearch</code></strong></a>, and <a href="#_lsort
"><strong><code>lsort</code></strong></a> allow
2259 you to build lists, extract elements from them, search them, and perform
2260 other list-related functions.</p></div>
2261 <div class="paragraph
"><p>Advanced list commands include <a href="#_lrepeat
"><strong><code>lrepeat</code></strong></a>, <a href="#_lreverse
"><strong><code>lreverse</code></strong></a>, <a href="#_lmap
"><strong><code>lmap</code></strong></a>, <a href="#_lassign
"><strong><code>lassign</code></strong></a>, <a href="#_lset
"><strong><code>lset</code></strong></a>.</p></div>
2265 <h2 id="_list_expansion
">LIST EXPANSION</h2>
2266 <div class="sectionbody
">
2267 <div class="paragraph
"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
2268 arguments. Support for this feature is also available in Jim.</p></div>
2269 <div class="paragraph
"><p>Consider the following attempt to exec a list:</p></div>
2270 <div class="listingblock
">
2271 <div class="content
">
2272 <pre><code> set cmd {ls -l}
2273 exec $cmd</code></pre>
2275 <div class="paragraph
"><p>This will attempt to exec a command named "ls -l
", which will clearly not
2276 work. Typically eval and concat are required to solve this problem, however
2277 it can be solved much more easily with <code>{*}</code>.</p></div>
2278 <div class="listingblock
">
2279 <div class="content
">
2280 <pre><code> exec {*}$cmd</code></pre>
2282 <div class="paragraph
"><p>This will expand the following argument into individual elements and then evaluate
2283 the resulting command.</p></div>
2284 <div class="paragraph
"><p>Note that the official Tcl syntax is <code>{*}</code>, however <code>{expand}</code> is retained
2285 for backward compatibility with experimental versions of this feature.</p></div>
2289 <h2 id="_regular_expressions
">REGULAR EXPRESSIONS</h2>
2290 <div class="sectionbody
">
2291 <div class="paragraph
"><p>Tcl provides two commands that support string matching using regular
2292 expressions, <a href="#_regexp
"><strong><code>regexp</code></strong></a> and <a href="#_regsub
"><strong><code>regsub</code></strong></a>, as well as <a href="#_switch
"><strong><code>switch</code></strong></a> <code>-regexp</code> and
2293 <a href="#_lsearch
"><strong><code>lsearch</code></strong></a> <code>-regexp</code>.</p></div>
2294 <div class="paragraph
"><p>Regular expressions may be implemented one of two ways. Either using the system’s C library
2295 POSIX regular expression support, or using the built-in regular expression engine.
2296 The differences between these are described below.</p></div>
2297 <div class="paragraph
"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<code>ARE</code>).</p></div>
2299 <h3 id="_posix_regular_expressions
">POSIX Regular Expressions</h3>
2300 <div class="paragraph
"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
2301 this support will be used by default. The type of regular expressions supported are
2302 Extended Regular Expressions (<code>ERE</code>) rather than Basic Regular Expressions (<code>BRE</code>).
2303 See REG_EXTENDED in the documentation.</p></div>
2304 <div class="paragraph
"><p>Using the system-supported POSIX regular expressions will typically
2305 make for the smallest code size, but some features such as UTF-8
2306 and <code>\w</code>, <code>\d</code>, <code>\s</code> are not supported, and null characters
2307 in strings are not supported.</p></div>
2308 <div class="paragraph
"><p>See regex(3) and regex(7) for full details.</p></div>
2311 <h3 id="_jim_built_in_regular_expressions
">Jim built-in Regular Expressions</h3>
2312 <div class="paragraph
"><p>The Jim built-in regular expression engine may be selected with <code>./configure --with-jim-regexp</code>
2313 or it will be selected automatically if UTF-8 support is enabled.</p></div>
2314 <div class="paragraph
"><p>This engine supports UTF-8 as well as some <code>ARE</code> features. The differences with both Tcl 7.x/8.x
2315 and POSIX are highlighted below.</p></div>
2316 <div class="olist arabic
"><ol class="arabic
">
2319 UTF-8 strings and patterns are both supported
2324 All Tcl character classes are supported (e.g. <code>[:alnum:]</code>, <code>[:digit:]</code>, <code>[:space:]</code>), but…
2329 Character classes apply to ASCII characters only
2334 Supported shorthand character classes: <code>\w</code> = <code>[:alnum:]</code>, <code>\W</code> = <code><sup>[:alnum:]</code>, <code>\d</code> = <code>[:digit:],</code> <code>\D</code> = <code></sup>[:digit:],</code> <code>\s</code> = <code>[:space:]</code>, + <code>\S</code> = <code>^[:space:]</code>
2339 Supported constraint escapes: <code>\m</code> = <code>\<</code> = start of word, <code>\M</code> = <code>\></code> = end of word
2344 Backslash escapes may be used within regular expressions, such as <code>\n</code> = newline, <code>\uNNNN</code> = unicode
2349 Partially supported constraint escapes: <code>\A</code> = start of string, <code>\Z</code> = end of string
2354 Support for the <code>?</code> non-greedy quantifier. e.g. <code>*?</code>
2359 Support for non-capturing parentheses <code>(?:…)</code>
2364 Jim Tcl considers that both patterns and strings end at a null character (<code>\x00</code>)
2372 <h2 id="_command_results
">COMMAND RESULTS</h2>
2373 <div class="sectionbody
">
2374 <div class="paragraph
"><p>Each command produces two results: a code and a string. The
2375 code indicates whether the command completed successfully or not,
2376 and the string gives additional information. The valid codes are
2377 defined in jim.h, and are:</p></div>
2378 <div class="dlist
"><dl>
2379 <dt class="hdlist1
">
2380 <code>JIM_OK(0)</code>
2384 This is the normal return code, and indicates that the command completed
2385 successfully. The string gives the command’s return value.
2388 <dt class="hdlist1
">
2389 <code>JIM_ERR(1)</code>
2393 Indicates that an error occurred; the string gives a message describing
2397 <dt class="hdlist1
">
2398 <code>JIM_RETURN(2)</code>
2402 Indicates that the <a href="#_return
"><strong><code>return</code></strong></a> command has been invoked, and that the
2403 current procedure (or top-level command or <a href="#_source
"><strong><code>source</code></strong></a> command)
2404 should return immediately. The
2405 string gives the return value for the procedure or command.
2408 <dt class="hdlist1
">
2409 <code>JIM_BREAK(3)</code>
2413 Indicates that the <a href="#_break
"><strong><code>break</code></strong></a> command has been invoked, so the
2414 innermost loop should abort immediately. The string should always
2418 <dt class="hdlist1
">
2419 <code>JIM_CONTINUE(4)</code>
2423 Indicates that the <a href="#_continue
"><strong><code>continue</code></strong></a> command has been invoked, so the
2424 innermost loop should go on to the next iteration. The string
2425 should always be empty.
2428 <dt class="hdlist1
">
2429 <code>JIM_SIGNAL(5)</code>
2433 Indicates that a signal was caught while executing a commands.
2434 The string contains the name of the signal caught.
2435 See the <a href="#_signal
"><strong><code>signal</code></strong></a> and <a href="#_catch
"><strong><code>catch</code></strong></a> commands.
2438 <dt class="hdlist1
">
2439 <code>JIM_EXIT(6)</code>
2443 Indicates that the command called the <a href="#_exit
"><strong><code>exit</code></strong></a> command.
2444 The string contains the exit code.
2448 <div class="paragraph
"><p>Tcl programmers do not normally need to think about return codes,
2449 since <code>JIM_OK</code> is almost always returned. If anything else is returned
2450 by a command, then the Tcl interpreter immediately stops processing
2451 commands and returns to its caller. If there are several nested
2452 invocations of the Tcl interpreter in progress, then each nested
2453 command will usually return the error to its caller, until eventually
2454 the error is reported to the top-level application code. The
2455 application will then display the error message for the user.</p></div>
2456 <div class="paragraph
"><p>In a few cases, some commands will handle certain <a href="#_error
"><strong><code>error</code></strong></a> conditions
2457 themselves and not return them upwards. For example, the <a href="#_for
"><strong><code>for</code></strong></a>
2458 command checks for the <code>JIM_BREAK</code> code; if it occurs, then <a href="#_for
"><strong><code>for</code></strong></a>
2459 stops executing the body of the loop and returns <code>JIM_OK</code> to its
2460 caller. The <a href="#_for
"><strong><code>for</code></strong></a> command also handles <code>JIM_CONTINUE</code> codes and the
2461 procedure interpreter handles <code>JIM_RETURN</code> codes. The <a href="#_catch
"><strong><code>catch</code></strong></a>
2462 command allows Tcl programs to catch errors and handle them without
2463 aborting command interpretation any further.</p></div>
2464 <div class="paragraph
"><p>The <a href="#_info
"><strong><code>info</code></strong></a> <code>returncodes</code> command may be used to programmatically map between
2465 return codes and names.</p></div>
2469 <h2 id="_procedures
">PROCEDURES</h2>
2470 <div class="sectionbody
">
2471 <div class="paragraph
"><p>Tcl allows you to extend the command interface by defining
2472 procedures. A Tcl procedure can be invoked just like any other Tcl
2473 command (it has a name and it receives one or more arguments).
2474 The only difference is that its body isn’t a piece of C code linked
2475 into the program; it is a string containing one or more other
2476 Tcl commands.</p></div>
2477 <div class="paragraph
"><p>The <a href="#_proc
"><strong><code>proc</code></strong></a> command is used to create a new Tcl command procedure:</p></div>
2478 <div class="paragraph
"><p><code><strong>proc</strong> <em>name arglist ?statics? body</em></code></p></div>
2479 <div class="paragraph
"><p>The new command is named <code><em>name</em></code>, and it replaces any existing command
2480 there may have been by that name. Whenever the new command is
2481 invoked, the contents of <code><em>body</em></code> will be executed by the Tcl
2482 interpreter.</p></div>
2483 <div class="paragraph
"><p><code><em>arglist</em></code> specifies the formal arguments to the procedure.
2484 It consists of a list, possibly empty, of the following
2485 argument specifiers:</p></div>
2486 <div class="dlist
"><dl>
2487 <dt class="hdlist1
">
2492 Required Argument - A simple argument name.
2495 <dt class="hdlist1
">
2496 <code>{name default}</code>
2500 Optional Argument - A two-element list consisting of the
2501 argument name, followed by the default value, which will
2502 be used if the corresponding argument is not supplied.
2505 <dt class="hdlist1
">
2506 <code>&name</code>
2510 Reference Argument - The caller is expected to pass the name of
2511 an existing variable. An implicit <code><a href="#_upvar
"><strong><code>upvar</code></strong></a> 1 origname name</code> is done
2512 to make the variable available in the proc scope.
2515 <dt class="hdlist1
">
2516 <code><strong>args</strong></code>
2520 Variable Argument - The special name <code><em>args</em></code>, which is
2521 assigned all remaining arguments (including none) as a list. The
2522 variable argument may only be specified once. Note that
2523 the syntax <code>{args newname}</code> may be used to retain the special
2524 behaviour of <code><em>args</em></code> with a different local name. In this case,
2525 the variable is named <code><em>newname</em></code> rather than <code><em>args</em></code>.
2529 <div class="paragraph
"><p>When the command is invoked, a local variable will be created for each of
2530 the formal arguments to the procedure; its value will be the value
2531 of corresponding argument in the invoking command or the argument’s
2532 default value.</p></div>
2533 <div class="paragraph
"><p>Arguments with default values need not be specified in a procedure
2534 invocation. However, there must be enough actual arguments for all
2535 required arguments, and there must not be any extra actual arguments
2536 (unless the Variable Argument is specified).</p></div>
2537 <div class="paragraph
"><p>Actual arguments are assigned to formal arguments as in left-to-right
2538 order with the following precedence.</p></div>
2539 <div class="olist arabic
"><ol class="arabic
">
2542 Required Arguments (including Reference Arguments)
2556 <div class="paragraph
"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2557 <div class="listingblock
">
2558 <div class="content
">
2559 <pre><code> proc p {{a A} args b {c C} d} {...}</code></pre>
2561 <div class="paragraph
"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2562 The following table shows how various numbers of arguments are assigned.
2563 Values marked as <code>-</code> are assigned the default value.</p></div>
2564 <div class="tableblock
">
2568 cellspacing="0" cellpadding="4">
2577 <th align="left
" valign="top
">Number of arguments</th>
2578 <th align="left
" valign="top
">a</th>
2579 <th align="left
" valign="top
">args</th>
2580 <th align="left
" valign="top
">b</th>
2581 <th align="left
" valign="top
">c</th>
2582 <th align="left
" valign="top
">d</th>
2587 <td align="left
" valign="top
"><p class="table
">2</p></td>
2588 <td align="left
" valign="top
"><p class="table
">-</p></td>
2589 <td align="left
" valign="top
"><p class="table
">-</p></td>
2590 <td align="left
" valign="top
"><p class="table
">1</p></td>
2591 <td align="left
" valign="top
"><p class="table
">-</p></td>
2592 <td align="left
" valign="top
"><p class="table
">2</p></td>
2595 <td align="left
" valign="top
"><p class="table
">3</p></td>
2596 <td align="left
" valign="top
"><p class="table
">1</p></td>
2597 <td align="left
" valign="top
"><p class="table
">-</p></td>
2598 <td align="left
" valign="top
"><p class="table
">2</p></td>
2599 <td align="left
" valign="top
"><p class="table
">-</p></td>
2600 <td align="left
" valign="top
"><p class="table
">3</p></td>
2603 <td align="left
" valign="top
"><p class="table
">4</p></td>
2604 <td align="left
" valign="top
"><p class="table
">1</p></td>
2605 <td align="left
" valign="top
"><p class="table
">-</p></td>
2606 <td align="left
" valign="top
"><p class="table
">2</p></td>
2607 <td align="left
" valign="top
"><p class="table
">3</p></td>
2608 <td align="left
" valign="top
"><p class="table
">4</p></td>
2611 <td align="left
" valign="top
"><p class="table
">5</p></td>
2612 <td align="left
" valign="top
"><p class="table
">1</p></td>
2613 <td align="left
" valign="top
"><p class="table
">2</p></td>
2614 <td align="left
" valign="top
"><p class="table
">3</p></td>
2615 <td align="left
" valign="top
"><p class="table
">4</p></td>
2616 <td align="left
" valign="top
"><p class="table
">5</p></td>
2619 <td align="left
" valign="top
"><p class="table
">6</p></td>
2620 <td align="left
" valign="top
"><p class="table
">1</p></td>
2621 <td align="left
" valign="top
"><p class="table
">2,3</p></td>
2622 <td align="left
" valign="top
"><p class="table
">4</p></td>
2623 <td align="left
" valign="top
"><p class="table
">5</p></td>
2624 <td align="left
" valign="top
"><p class="table
">6</p></td>
2629 <div class="paragraph
"><p>When <code><em>body</em></code> is being executed, variable names normally refer to local
2630 variables, which are created automatically when referenced and deleted
2631 when the procedure returns. One local variable is automatically created
2632 for each of the procedure’s arguments. Global variables can be
2633 accessed by invoking the <a href="#_global
"><strong><code>global</code></strong></a> command or via the <code>::</code> prefix.</p></div>
2635 <h3 id="_new_in_jim
">New in Jim</h3>
2636 <div class="paragraph
"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2637 These variables scoped to the procedure and initialised at procedure definition.
2638 Either from the static variable definition, or from the enclosing scope.</p></div>
2639 <div class="paragraph
"><p>Consider the following example:</p></div>
2640 <div class="listingblock
">
2641 <div class="content
">
2642 <pre><code> . set a 1
2643 . proc a {} {a {b 2}} {
2655 <div class="paragraph
"><p>The static variable <code><em>a</em></code> has no initialiser, so it is initialised from
2656 the enclosing scope with the value 1. (Note that it is an error if there
2657 is no variable with the same name in the enclosing scope). However <code><em>b</em></code>
2658 has an initialiser, so it is initialised to 2.</p></div>
2659 <div class="paragraph
"><p>Unlike a local variable, the value of a static variable is retained across
2660 invocations of the procedure.</p></div>
2661 <div class="paragraph
"><p>See the <a href="#_proc
"><strong><code>proc</code></strong></a> command for information on how to define procedures
2662 and what happens when they are invoked. See also <a href="#_namespaces
">NAMESPACES</a>.</p></div>
2667 <h2 id="_variables_scalars_and_arrays
">VARIABLES - SCALARS AND ARRAYS</h2>
2668 <div class="sectionbody
">
2669 <div class="paragraph
"><p>Tcl allows the definition of variables and the use of their values
2670 either through <em>$</em>-style variable substitution, the <a href="#_set
"><strong><code>set</code></strong></a>
2671 command, or a few other mechanisms.</p></div>
2672 <div class="paragraph
"><p>Variables need not be declared: a new variable will automatically
2673 be created each time a new variable name is used.</p></div>
2674 <div class="paragraph
"><p>Tcl supports two types of variables: scalars and arrays.
2675 A scalar variable has a single value, whereas an array variable
2676 can have any number of elements, each with a name (called
2677 its <em>index</em>) and a value.</p></div>
2678 <div class="paragraph
"><p>Array indexes may be arbitrary strings; they need not be numeric.
2679 Parentheses are used refer to array elements in Tcl commands.
2680 For example, the command</p></div>
2681 <div class="listingblock
">
2682 <div class="content
">
2683 <pre><code> set x(first) 44</code></pre>
2685 <div class="paragraph
"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2686 so that its new value is <em>44</em>.</p></div>
2687 <div class="paragraph
"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2688 that contain multiple concatenated values.
2689 For example, the commands</p></div>
2690 <div class="listingblock
">
2691 <div class="content
">
2692 <pre><code> set a(2,3) 1
2693 set a(3,6) 2</code></pre>
2695 <div class="paragraph
"><p>set the elements of <em>a</em> whose indexes are <em>2,3</em> and <em>3,6</em>.</p></div>
2696 <div class="paragraph
"><p>In general, array elements may be used anywhere in Tcl that scalar
2697 variables may be used.</p></div>
2698 <div class="paragraph
"><p>If an array is defined with a particular name, then there may
2699 not be a scalar variable with the same name.</p></div>
2700 <div class="paragraph
"><p>Similarly, if there is a scalar variable with a particular
2701 name then it is not possible to make array references to the
2703 <div class="paragraph
"><p>To convert a scalar variable to an array or vice versa, remove
2704 the existing variable with the <a href="#_unset
"><strong><code>unset</code></strong></a> command.</p></div>
2705 <div class="paragraph
"><p>The <a href="#_array
"><strong><code>array</code></strong></a> command provides several features for dealing
2706 with arrays, such as querying the names of all the elements of
2707 the array and converting between an array and a list.</p></div>
2708 <div class="paragraph
"><p>Variables may be either global or local. If a variable
2709 name is used when a procedure isn’t being executed, then it
2710 automatically refers to a global variable. Variable names used
2711 within a procedure normally refer to local variables associated with that
2712 invocation of the procedure. Local variables are deleted whenever
2713 a procedure exits. Either <a href="#_global
"><strong><code>global</code></strong></a> command may be used to request
2714 that a name refer to a global variable for the duration of the current
2715 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2716 may be explicitly scoped with the <code>::</code> prefix. For example</p></div>
2717 <div class="listingblock
">
2718 <div class="content
">
2719 <pre><code> . set a 1
2729 <div class="paragraph
"><p>will output:</p></div>
2730 <div class="literalblock
">
2731 <div class="content
">
2732 <pre><code>1 2 3</code></pre>
2737 <h2 id="_arrays_as_lists_in_jim
">ARRAYS AS LISTS IN JIM</h2>
2738 <div class="sectionbody
">
2739 <div class="paragraph
"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2740 number of elements) and an array value. This is similar to the way Tcl
2741 can convert between a string and a list.</p></div>
2742 <div class="paragraph
"><p>For example:</p></div>
2743 <div class="listingblock
">
2744 <div class="content
">
2745 <pre><code> set a {1 one 2 two}
2746 puts $a(2)</code></pre>
2748 <div class="paragraph
"><p>will output:</p></div>
2749 <div class="listingblock
">
2750 <div class="content
">
2751 <pre><code> two</code></pre>
2753 <div class="paragraph
"><p>Thus <a href="#_array
"><strong><code>array</code></strong></a> <code>set</code> is equivalent to <a href="#_set
"><strong><code>set</code></strong></a> when the variable does not
2754 exist or is empty.</p></div>
2755 <div class="paragraph
"><p>The reverse is also true where an array will be converted into
2757 <div class="listingblock
">
2758 <div class="content
">
2759 <pre><code> set a(1) one; set a(2) two
2760 puts $a</code></pre>
2762 <div class="paragraph
"><p>will output:</p></div>
2763 <div class="listingblock
">
2764 <div class="content
">
2765 <pre><code> 1 one 2 two</code></pre>
2770 <h2 id="_dictionary_values
">DICTIONARY VALUES</h2>
2771 <div class="sectionbody
">
2772 <div class="paragraph
"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2773 of this command. Dictionaries provide efficient access to key-value
2774 pairs, just like arrays, but dictionaries are pure values. This
2775 means that you can pass them to a procedure just as a list or a
2776 string. Tcl dictionaries are therefore much more like Tcl lists,
2777 except that they represent a mapping from keys to values, rather
2778 than an ordered sequence.</p></div>
2779 <div class="paragraph
"><p>You can nest dictionaries, so that the value for a particular key
2780 consists of another dictionary. That way you can elegantly build
2781 complicated data structures, such as hierarchical databases. You
2782 can also combine dictionaries with other Tcl data structures. For
2783 instance, you can build a list of dictionaries that themselves
2784 contain lists.</p></div>
2785 <div class="paragraph
"><p>Dictionaries are values that contain an efficient, order-preserving
2786 mapping from arbitrary keys to arbitrary values. Each key in the
2787 dictionary maps to a single value. They have a textual format that
2788 is exactly that of any list with an even number of elements, with
2789 each mapping in the dictionary being represented as two items in
2790 the list. When a command takes a dictionary and produces a new
2791 dictionary based on it (either returning it or writing it back into
2792 the variable that the starting dictionary was read from) the new
2793 dictionary will have the same order of keys, modulo any deleted
2794 keys and with new keys added on to the end. When a string is
2795 interpreted as a dictionary and it would otherwise have duplicate
2796 keys, only the last value for a particular key is used; the others
2797 are ignored, meaning that, "apple banana
" and "apple carrot apple
2798 banana
" are equivalent dictionaries (with different string
2799 representations).</p></div>
2800 <div class="paragraph
"><p>Note that in Jim, arrays are implemented as dictionaries.
2801 Thus automatic conversion between lists and dictionaries applies
2802 as it does for arrays.</p></div>
2803 <div class="listingblock
">
2804 <div class="content
">
2805 <pre><code> . dict set a 1 one
2813 . dict set a 3 T three
2814 1 one 2 two 3 {T three}</code></pre>
2816 <div class="paragraph
"><p>See the <a href="#_dict
"><strong><code>dict</code></strong></a> command for more details.</p></div>
2820 <h2 id="_namespaces
">NAMESPACES</h2>
2821 <div class="sectionbody
">
2822 <div class="paragraph
"><p>Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
2823 including a number of 3rd party components. While there is less need for namespaces
2824 in Jim Tcl (which does not strive to support large applications), it is convenient to
2825 provide a subset of the support for namespaces to easy porting code from Tcl.</p></div>
2826 <div class="paragraph
"><p>Jim Tcl currently supports "light-weight
" namespaces which should be adequate for most
2827 purposes. This feature is currently experimental. See README.namespaces for more information
2828 and the documentation of the <a href="#_namespace
"><strong><code>namespace</code></strong></a> command.</p></div>
2832 <h2 id="_garbage_collection_references_lambda_function
">GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION</h2>
2833 <div class="sectionbody
">
2834 <div class="paragraph
"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
2835 These are described briefly below.</p></div>
2836 <div class="paragraph
"><p>More information may be found at <a href="http://wiki.tcl.tk/
13847">http://wiki.tcl.tk/13847</a></p></div>
2838 <h3 id="_references
">References</h3>
2839 <div class="paragraph
"><p>A reference can be thought of as holding a value with one level of indirection,
2840 where the value may be garbage collected when unreferenced.
2841 Consider the following example:</p></div>
2842 <div class="listingblock
">
2843 <div class="content
">
2844 <pre><code> . set r [ref "One String
" test]
2845 <reference.<test___>.00000000000000000000>
2847 One String</code></pre>
2849 <div class="paragraph
"><p>The operation <a href="#_ref
"><strong><code>ref</code></strong></a> creates a references to the value specified by the
2850 first argument. (The second argument is a "type
" used for documentation purposes).</p></div>
2851 <div class="paragraph
"><p>The operation <a href="#_getref
"><strong><code>getref</code></strong></a> is the dereferencing operation which retrieves the value
2852 stored in the reference.</p></div>
2853 <div class="listingblock
">
2854 <div class="content
">
2855 <pre><code> . setref $r "New String
"
2858 New String</code></pre>
2860 <div class="paragraph
"><p>The operation <a href="#_setref
"><strong><code>setref</code></strong></a> replaces the value stored by the reference. If the old value
2861 is no longer accessible by any reference, it will eventually be automatically be garbage
2862 collected.</p></div>
2865 <h3 id="_garbage_collection
">Garbage Collection</h3>
2866 <div class="paragraph
"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
2867 automatically as necessary.</p></div>
2868 <div class="paragraph
"><p>With the introduction of references, it is possible to create values whose lifetime
2869 transcend their scope. To support this, case, the Jim system will periodically identify
2870 and discard objects which are no longer accessible by any reference.</p></div>
2871 <div class="paragraph
"><p>The <a href="#_collect
"><strong><code>collect</code></strong></a> command may be used to force garbage collection. Consider a reference created
2872 with a finalizer:</p></div>
2873 <div class="listingblock
">
2874 <div class="content
">
2875 <pre><code> . proc f {ref value} { puts "Finaliser called for $ref,$value
" }
2876 . set r [ref "One String
" test f]
2877 <reference.<test___>.00000000000
2882 Finaliser called for <reference.<test___>.00000000000,One String
2885 <div class="paragraph
"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
2886 contained a reference to the value, the garbage collector discarded
2887 the value (after calling the finalizer).</p></div>
2888 <div class="paragraph
"><p>The finalizer for a reference may be examined or changed with the <a href="#_finalize
"><strong><code>finalize</code></strong></a> command</p></div>
2889 <div class="listingblock
">
2890 <div class="content
">
2891 <pre><code> . finalize $r
2898 <h3 id="_lambda_function
">Lambda Function</h3>
2899 <div class="paragraph
"><p>Jim provides a garbage collected <a href="#_lambda
"><strong><code>lambda</code></strong></a> function. This is a procedure
2900 which is able to create an anonymous procedure. Consider:</p></div>
2901 <div class="listingblock
">
2902 <div class="content
">
2903 <pre><code> . set f [lambda {a} {{x 0}} { incr x $a }]
2908 . set f ""</code></pre>
2910 <div class="paragraph
"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
2911 which is incremented by the supplied value and the result returned.</p></div>
2912 <div class="paragraph
"><p>Once the procedure name is no longer accessible, it will automatically be deleted
2913 when the garbage collector runs.</p></div>
2914 <div class="paragraph
"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
2915 <div class="listingblock
">
2916 <div class="content
">
2917 <pre><code> . rename $f ""</code></pre>
2923 <h2 id="_utf_8_and_unicode
">UTF-8 AND UNICODE</h2>
2924 <div class="sectionbody
">
2925 <div class="paragraph
"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
2926 then most string-related commands become UTF-8 aware. These include,
2927 but are not limited to, <a href="#_string
"><strong><code>string</code></strong></a> <code>match</code>, <a href="#_split
"><strong><code>split</code></strong></a>, <a href="#_glob
"><strong><code>glob</code></strong></a>, <a href="#_scan
"><strong><code>scan</code></strong></a> and
2928 <a href="#_format
"><strong><code>format</code></strong></a>.</p></div>
2929 <div class="paragraph
"><p>UTF-8 encoding has many advantages, but one of the complications is that
2930 characters can take a variable number of bytes. Thus the addition of
2931 <a href="#_string
"><strong><code>string</code></strong></a> <code>bytelength</code> which returns the number of bytes in a string,
2932 while <a href="#_string
"><strong><code>string</code></strong></a> <code>length</code> returns the number of characters.</p></div>
2933 <div class="paragraph
"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
2934 and <a href="#_string
"><strong><code>string</code></strong></a> <code>bytelength</code> returns the same value as <a href="#_string
"><strong><code>string</code></strong></a> <code>length</code>.</p></div>
2935 <div class="paragraph
"><p>Note that even if UTF-8 support is not enabled, the <code>\uNNNN</code> and related syntax
2936 is still available to embed UTF-8 sequences.</p></div>
2937 <div class="paragraph
"><p>Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +<em>U+1FFFFF</em>.</p></div>
2939 <h3 id="_string_matching
">String Matching</h3>
2940 <div class="paragraph
"><p>Commands such as <a href="#_string
"><strong><code>string</code></strong></a> <code>match</code>, <a href="#_lsearch
"><strong><code>lsearch</code></strong></a> <code>-glob</code>, <a href="#_array
"><strong><code>array</code></strong></a> <code>names</code> and others use string
2941 pattern matching rules. These commands support UTF-8. For example:</p></div>
2942 <div class="listingblock
">
2943 <div class="content
">
2944 <pre><code> string match a\[\ua0-\ubf\]b "a\u00a3b
"</code></pre>
2948 <h3 id="_format_and_scan
">format and scan</h3>
2949 <div class="paragraph
"><p><code>format %c</code> allows a unicode codepoint to be be encoded. For example, the following will return
2950 a string with two bytes and one character. The same as <code>\ub5</code></p></div>
2951 <div class="listingblock
">
2952 <div class="content
">
2953 <pre><code> format %c 0xb5</code></pre>
2955 <div class="paragraph
"><p><a href="#_format
"><strong><code>format</code></strong></a> respects widths as character widths, not byte widths. For example, the following will
2956 return a string with three characters, not three bytes.</p></div>
2957 <div class="listingblock
">
2958 <div class="content
">
2959 <pre><code> format %.3s \ub5\ub6\ub7\ub8</code></pre>
2961 <div class="paragraph
"><p>Similarly, <code>scan … %c</code> allows a UTF-8 to be decoded to a unicode codepoint. The following will set
2962 <code><em>a</em></code> to 181 (0xb5) and <code><em>b</em></code> to 65 (0x41).</p></div>
2963 <div class="listingblock
">
2964 <div class="content
">
2965 <pre><code> scan \u00b5A %c%c a b</code></pre>
2967 <div class="paragraph
"><p><a href="#_scan
"><strong><code>scan</code></strong></a> <code>%s</code> will also accept a character class, including unicode ranges.</p></div>
2970 <h3 id="_string_classes
">String Classes</h3>
2971 <div class="paragraph
"><p><a href="#_string
"><strong><code>string</code></strong></a> <code>is</code> has <strong>not</strong> been extended to classify UTF-8 characters. Therefore, the following
2972 will return 0, even though the string may be considered to be alphabetic.</p></div>
2973 <div class="listingblock
">
2974 <div class="content
">
2975 <pre><code> string is alpha \ub5Test</code></pre>
2977 <div class="paragraph
"><p>This does not affect the string classes <em>ascii</em>, <em>control</em>, <em>digit</em>, <em>double</em>, <em>integer</em> or <em>xdigit</em>.</p></div>
2980 <h3 id="_case_mapping_and_conversion
">Case Mapping and Conversion</h3>
2981 <div class="paragraph
"><p>Jim provides a simplified unicode case mapping. This means that case conversion
2982 and comparison will not increase or decrease the number of characters in a string.
2983 (Although it may change the number of bytes).</p></div>
2984 <div class="paragraph
"><p><a href="#_string
"><strong><code>string</code></strong></a> <code>toupper</code> will convert any lowercase letters to their uppercase equivalent.
2985 Any character which is not a letter or has no uppercase equivalent is left unchanged.
2986 Similarly for <a href="#_string
"><strong><code>string</code></strong></a> <code>tolower</code> and <a href="#_string
"><strong><code>string</code></strong></a> <code>totitle</code>.</p></div>
2987 <div class="paragraph
"><p>Commands which perform case insensitive matches, such as <a href="#_string
"><strong><code>string</code></strong></a> <code>compare -nocase</code>
2988 and <a href="#_lsearch
"><strong><code>lsearch</code></strong></a> <code>-nocase</code> fold both strings to uppercase before comparison.</p></div>
2991 <h3 id="_invalid_utf_8_sequences
">Invalid UTF-8 Sequences</h3>
2992 <div class="paragraph
"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
2993 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
2994 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
2995 <div class="paragraph
"><p>In these situations, the offending bytes are treated as single characters. For example,
2996 the following returns 2.</p></div>
2997 <div class="listingblock
">
2998 <div class="content
">
2999 <pre><code> string bytelength \xff\xff</code></pre>
3003 <h3 id="_regular_expressions_2
">Regular Expressions</h3>
3004 <div class="paragraph
"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
3005 selected which supports UTF-8 strings and patterns.</p></div>
3006 <div class="paragraph
"><p>See <a href="#_regular_expressions
">REGULAR EXPRESSIONS</a></p></div>
3011 <h2 id="_built_in_commands
">BUILT-IN COMMANDS</h2>
3012 <div class="sectionbody
">
3013 <div class="paragraph
"><p>The Tcl library provides the following built-in commands, which will
3014 be available in any application using Tcl. In addition to these
3015 built-in commands, there may be additional commands defined by each
3016 application, plus commands defined as Tcl procedures.</p></div>
3017 <div class="paragraph
"><p>In the command syntax descriptions below, words in <code><strong>boldface</strong></code> are
3018 literals that you type verbatim to Tcl.</p></div>
3019 <div class="paragraph
"><p>Words in <code><em>italics</em></code> are meta-symbols; they serve as names for any of
3020 a range of values that you can type.</p></div>
3021 <div class="paragraph
"><p>Optional arguments or groups of arguments are indicated by enclosing them
3022 in <code>?question-marks?</code>.</p></div>
3023 <div class="paragraph
"><p>Ellipses (<code>...</code>) indicate that any number of additional
3024 arguments or groups of arguments may appear, in the same format
3025 as the preceding argument(s).</p></div>
3027 <h3 id="CommandIndex
">Command Index</h3>
3028 <div class="tableblock
">
3032 cellspacing="0" cellpadding="4">
3043 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_2
"><strong><code>after</code></strong></a></p></td>
3044 <td align="left
" valign="top
"><p class="table
"><a href="#_aio
"><strong><code>aio</code></strong></a></p></td>
3045 <td align="left
" valign="top
"><p class="table
"><a href="#_alarm
"><strong><code>alarm</code></strong></a></p></td>
3046 <td align="left
" valign="top
"><p class="table
"><a href="#_alias
"><strong><code>alias</code></strong></a></p></td>
3047 <td align="left
" valign="top
"><p class="table
"><a href="#_append
"><strong><code>append</code></strong></a></p></td>
3048 <td align="left
" valign="top
"><p class="table
"><a href="#_apply
"><strong><code>apply</code></strong></a></p></td>
3049 <td align="left
" valign="top
"><p class="table
"><a href="#_array
"><strong><code>array</code></strong></a></p></td>
3050 <td align="left
" valign="top
"><p class="table
"><a href="#_binary
"><strong><code>binary</code></strong></a></p></td>
3053 <td align="left
" valign="top
"><p class="table
"><a href="#_break
"><strong><code>break</code></strong></a></p></td>
3054 <td align="left
" valign="top
"><p class="table
"><a href="#_case
"><strong><code>case</code></strong></a></p></td>
3055 <td align="left
" valign="top
"><p class="table
"><a href="#_catch
"><strong><code>catch</code></strong></a></p></td>
3056 <td align="left
" valign="top
"><p class="table
"><a href="#_cd
"><strong><code>cd</code></strong></a></p></td>
3057 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_4
"><strong><code>class</code></strong></a></p></td>
3058 <td align="left
" valign="top
"><p class="table
"><a href="#_clock
"><strong><code>clock</code></strong></a></p></td>
3059 <td align="left
" valign="top
"><p class="table
"><a href="#_close
"><strong><code>close</code></strong></a></p></td>
3060 <td align="left
" valign="top
"><p class="table
"><a href="#_collect
"><strong><code>collect</code></strong></a></p></td>
3063 <td align="left
" valign="top
"><p class="table
"><a href="#_concat
"><strong><code>concat</code></strong></a></p></td>
3064 <td align="left
" valign="top
"><p class="table
"><a href="#_continue
"><strong><code>continue</code></strong></a></p></td>
3065 <td align="left
" valign="top
"><p class="table
"><a href="#_curry
"><strong><code>curry</code></strong></a></p></td>
3066 <td align="left
" valign="top
"><p class="table
"><a href="#_defer
"><strong><code>defer</code></strong></a></p></td>
3067 <td align="left
" valign="top
"><p class="table
"><a href="#_dict
"><strong><code>dict</code></strong></a></p></td>
3068 <td align="left
" valign="top
"><p class="table
"><a href="#_env
"><strong><code>env</code></strong></a></p></td>
3069 <td align="left
" valign="top
"><p class="table
"><a href="#_eof
"><strong><code>eof</code></strong></a></p></td>
3070 <td align="left
" valign="top
"><p class="table
"><a href="#_error
"><strong><code>error</code></strong></a></p></td>
3073 <td align="left
" valign="top
"><p class="table
"><a href="#_eval
"><strong><code>eval</code></strong></a></p></td>
3074 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_2
"><strong><code>eventloop</code></strong></a></p></td>
3075 <td align="left
" valign="top
"><p class="table
"><a href="#_exec
"><strong><code>exec</code></strong></a></p></td>
3076 <td align="left
" valign="top
"><p class="table
"><a href="#_exists
"><strong><code>exists</code></strong></a></p></td>
3077 <td align="left
" valign="top
"><p class="table
"><a href="#_exit
"><strong><code>exit</code></strong></a></p></td>
3078 <td align="left
" valign="top
"><p class="table
"><a href="#_expr
"><strong><code>expr</code></strong></a></p></td>
3079 <td align="left
" valign="top
"><p class="table
"><a href="#_fconfigure
"><strong><code>fconfigure</code></strong></a></p></td>
3080 <td align="left
" valign="top
"><p class="table
"><a href="#_file
"><strong><code>file</code></strong></a></p></td>
3083 <td align="left
" valign="top
"><p class="table
"><a href="#_finalize
"><strong><code>finalize</code></strong></a></p></td>
3084 <td align="left
" valign="top
"><p class="table
"><a href="#_flush
"><strong><code>flush</code></strong></a></p></td>
3085 <td align="left
" valign="top
"><p class="table
"><a href="#_for
"><strong><code>for</code></strong></a></p></td>
3086 <td align="left
" valign="top
"><p class="table
"><a href="#_foreach
"><strong><code>foreach</code></strong></a></p></td>
3087 <td align="left
" valign="top
"><p class="table
"><a href="#_format
"><strong><code>format</code></strong></a></p></td>
3088 <td align="left
" valign="top
"><p class="table
"><a href="#_getref
"><strong><code>getref</code></strong></a></p></td>
3089 <td align="left
" valign="top
"><p class="table
"><a href="#_gets
"><strong><code>gets</code></strong></a></p></td>
3090 <td align="left
" valign="top
"><p class="table
"><a href="#_glob
"><strong><code>glob</code></strong></a></p></td>
3093 <td align="left
" valign="top
"><p class="table
"><a href="#_global
"><strong><code>global</code></strong></a></p></td>
3094 <td align="left
" valign="top
"><p class="table
"><a href="#_history
"><strong><code>history</code></strong></a></p></td>
3095 <td align="left
" valign="top
"><p class="table
"><a href="#_if
"><strong><code>if</code></strong></a></p></td>
3096 <td align="left
" valign="top
"><p class="table
"><a href="#_incr
"><strong><code>incr</code></strong></a></p></td>
3097 <td align="left
" valign="top
"><p class="table
"><a href="#_info
"><strong><code>info</code></strong></a></p></td>
3098 <td align="left
" valign="top
"><p class="table
"><a href="#_interp
"><strong><code>interp</code></strong></a></p></td>
3099 <td align="left
" valign="top
"><p class="table
"><a href="#_join
"><strong><code>join</code></strong></a></p></td>
3100 <td align="left
" valign="top
"><p class="table
"><a href="#_json_decode
"><strong><code>json::decode</code></strong></a></p></td>
3103 <td align="left
" valign="top
"><p class="table
"><a href="#_json_encode
"><strong><code>json::encode</code></strong></a></p></td>
3104 <td align="left
" valign="top
"><p class="table
"><a href="#_kill
"><strong><code>kill</code></strong></a></p></td>
3105 <td align="left
" valign="top
"><p class="table
"><a href="#_lambda
"><strong><code>lambda</code></strong></a></p></td>
3106 <td align="left
" valign="top
"><p class="table
"><a href="#_lappend
"><strong><code>lappend</code></strong></a></p></td>
3107 <td align="left
" valign="top
"><p class="table
"><a href="#_lassign
"><strong><code>lassign</code></strong></a></p></td>
3108 <td align="left
" valign="top
"><p class="table
"><a href="#_lindex
"><strong><code>lindex</code></strong></a></p></td>
3109 <td align="left
" valign="top
"><p class="table
"><a href="#_linsert
"><strong><code>linsert</code></strong></a></p></td>
3110 <td align="left
" valign="top
"><p class="table
"><a href="#_list
"><strong><code>list</code></strong></a></p></td>
3113 <td align="left
" valign="top
"><p class="table
"><a href="#_llength
"><strong><code>llength</code></strong></a></p></td>
3114 <td align="left
" valign="top
"><p class="table
"><a href="#_lmap
"><strong><code>lmap</code></strong></a></p></td>
3115 <td align="left
" valign="top
"><p class="table
"><a href="#_load
"><strong><code>load</code></strong></a></p></td>
3116 <td align="left
" valign="top
"><p class="table
"><a href="#_local
"><strong><code>local</code></strong></a></p></td>
3117 <td align="left
" valign="top
"><p class="table
"><a href="#_loop
"><strong><code>loop</code></strong></a></p></td>
3118 <td align="left
" valign="top
"><p class="table
"><a href="#_lrange
"><strong><code>lrange</code></strong></a></p></td>
3119 <td align="left
" valign="top
"><p class="table
"><a href="#_lrepeat
"><strong><code>lrepeat</code></strong></a></p></td>
3120 <td align="left
" valign="top
"><p class="table
"><a href="#_lreplace
"><strong><code>lreplace</code></strong></a></p></td>
3123 <td align="left
" valign="top
"><p class="table
"><a href="#_lreverse
"><strong><code>lreverse</code></strong></a></p></td>
3124 <td align="left
" valign="top
"><p class="table
"><a href="#_lsearch
"><strong><code>lsearch</code></strong></a></p></td>
3125 <td align="left
" valign="top
"><p class="table
"><a href="#_lset
"><strong><code>lset</code></strong></a></p></td>
3126 <td align="left
" valign="top
"><p class="table
"><a href="#_lsort
"><strong><code>lsort</code></strong></a></p></td>
3127 <td align="left
" valign="top
"><p class="table
"><a href="#_namespace
"><strong><code>namespace</code></strong></a></p></td>
3128 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_4
"><strong><code>oo</code></strong></a></p></td>
3129 <td align="left
" valign="top
"><p class="table
"><a href="#_open
"><strong><code>open</code></strong></a></p></td>
3130 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><code>os.fork</code></strong></a></p></td>
3133 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><code>os.gethostname</code></strong></a></p></td>
3134 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><code>os.getids</code></strong></a></p></td>
3135 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><code>os.uptime</code></strong></a></p></td>
3136 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_3
"><strong><code>pack</code></strong></a></p></td>
3137 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_3
"><strong><code>pack</code></strong></a></p></td>
3138 <td align="left
" valign="top
"><p class="table
"><a href="#_package
"><strong><code>package</code></strong></a></p></td>
3139 <td align="left
" valign="top
"><p class="table
"><a href="#_pid
"><strong><code>pid</code></strong></a></p></td>
3140 <td align="left
" valign="top
"><p class="table
"><a href="#_pipe
"><strong><code>pipe</code></strong></a></p></td>
3143 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><code>posix</code></strong></a></p></td>
3144 <td align="left
" valign="top
"><p class="table
"><a href="#_proc
"><strong><code>proc</code></strong></a></p></td>
3145 <td align="left
" valign="top
"><p class="table
"><a href="#_puts
"><strong><code>puts</code></strong></a></p></td>
3146 <td align="left
" valign="top
"><p class="table
"><a href="#_pwd
"><strong><code>pwd</code></strong></a></p></td>
3147 <td align="left
" valign="top
"><p class="table
"><a href="#_rand
"><strong><code>rand</code></strong></a></p></td>
3148 <td align="left
" valign="top
"><p class="table
"><a href="#_range
"><strong><code>range</code></strong></a></p></td>
3149 <td align="left
" valign="top
"><p class="table
"><a href="#_read
"><strong><code>read</code></strong></a></p></td>
3150 <td align="left
" valign="top
"><p class="table
"><a href="#_ref
"><strong><code>ref</code></strong></a></p></td>
3153 <td align="left
" valign="top
"><p class="table
"><a href="#_regexp
"><strong><code>regexp</code></strong></a></p></td>
3154 <td align="left
" valign="top
"><p class="table
"><a href="#_regsub
"><strong><code>regsub</code></strong></a></p></td>
3155 <td align="left
" valign="top
"><p class="table
"><a href="#_rename
"><strong><code>rename</code></strong></a></p></td>
3156 <td align="left
" valign="top
"><p class="table
"><a href="#_return
"><strong><code>return</code></strong></a></p></td>
3157 <td align="left
" valign="top
"><p class="table
"><a href="#_scan
"><strong><code>scan</code></strong></a></p></td>
3158 <td align="left
" valign="top
"><p class="table
"><a href="#_seek
"><strong><code>seek</code></strong></a></p></td>
3159 <td align="left
" valign="top
"><p class="table
"><a href="#_set
"><strong><code>set</code></strong></a></p></td>
3160 <td align="left
" valign="top
"><p class="table
"><a href="#_setref
"><strong><code>setref</code></strong></a></p></td>
3163 <td align="left
" valign="top
"><p class="table
"><a href="#_signal
"><strong><code>signal</code></strong></a></p></td>
3164 <td align="left
" valign="top
"><p class="table
"><a href="#_sleep
"><strong><code>sleep</code></strong></a></p></td>
3165 <td align="left
" valign="top
"><p class="table
"><a href="#_socket
"><strong><code>socket</code></strong></a></p></td>
3166 <td align="left
" valign="top
"><p class="table
"><a href="#_source
"><strong><code>source</code></strong></a></p></td>
3167 <td align="left
" valign="top
"><p class="table
"><a href="#_split
"><strong><code>split</code></strong></a></p></td>
3168 <td align="left
" valign="top
"><p class="table
"><a href="#_stackdump
"><strong><code>stackdump</code></strong></a></p></td>
3169 <td align="left
" valign="top
"><p class="table
"><a href="#_stacktrace
"><strong><code>stacktrace</code></strong></a></p></td>
3170 <td align="left
" valign="top
"><p class="table
"><a href="#_string
"><strong><code>string</code></strong></a></p></td>
3173 <td align="left
" valign="top
"><p class="table
"><a href="#_subst
"><strong><code>subst</code></strong></a></p></td>
3174 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_4
"><strong><code>super</code></strong></a></p></td>
3175 <td align="left
" valign="top
"><p class="table
"><a href="#_switch
"><strong><code>switch</code></strong></a></p></td>
3176 <td align="left
" valign="top
"><p class="table
"><a href="#_syslog
"><strong><code>syslog</code></strong></a></p></td>
3177 <td align="left
" valign="top
"><p class="table
"><a href="#_tailcall
"><strong><code>tailcall</code></strong></a></p></td>
3178 <td align="left
" valign="top
"><p class="table
"><a href="#_tcl_autocomplete
"><strong><code>tcl::autocomplete</code></strong></a></p></td>
3179 <td align="left
" valign="top
"><p class="table
"><a href="#_tcl_prefix
"><strong><code>tcl::prefix</code></strong></a></p></td>
3180 <td align="left
" valign="top
"><p class="table
"><a href="#_tell
"><strong><code>tell</code></strong></a></p></td>
3183 <td align="left
" valign="top
"><p class="table
"><a href="#_throw
"><strong><code>throw</code></strong></a></p></td>
3184 <td align="left
" valign="top
"><p class="table
"><a href="#_time
"><strong><code>time</code></strong></a></p></td>
3185 <td align="left
" valign="top
"><p class="table
"><a href="#_tree
"><strong><code>tree</code></strong></a></p></td>
3186 <td align="left
" valign="top
"><p class="table
"><a href="#_try
"><strong><code>try</code></strong></a></p></td>
3187 <td align="left
" valign="top
"><p class="table
"><a href="#_unknown
"><strong><code>unknown</code></strong></a></p></td>
3188 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_3
"><strong><code>unpack</code></strong></a></p></td>
3189 <td align="left
" valign="top
"><p class="table
"><a href="#_unset
"><strong><code>unset</code></strong></a></p></td>
3190 <td align="left
" valign="top
"><p class="table
"><a href="#_upcall
"><strong><code>upcall</code></strong></a></p></td>
3193 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_2
"><strong><code>update</code></strong></a></p></td>
3194 <td align="left
" valign="top
"><p class="table
"><a href="#_uplevel
"><strong><code>uplevel</code></strong></a></p></td>
3195 <td align="left
" valign="top
"><p class="table
"><a href="#_upvar
"><strong><code>upvar</code></strong></a></p></td>
3196 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_2
"><strong><code>vwait</code></strong></a></p></td>
3197 <td align="left
" valign="top
"><p class="table
"><a href="#_wait
"><strong><code>wait</code></strong></a></p></td>
3198 <td align="left
" valign="top
"><p class="table
"><a href="#_while
"><strong><code>while</code></strong></a></p></td>
3199 <td align="left
" valign="top
"><p class="table
"><a href="#_zlib
"><strong><code>zlib</code></strong></a></p></td>
3200 <td align="left
" valign="top
"><p class="table
"></p></td>
3207 <h3 id="_alarm
">alarm</h3>
3208 <div class="paragraph
"><p><code><strong>alarm</strong> <em>seconds</em></code></p></div>
3209 <div class="paragraph
"><p>Delivers the <code>SIGALRM</code> signal to the process after the given
3210 number of seconds. If the platform supports <em>ualarm(3)</em> then
3211 the argument may be a floating point value. Otherwise it must
3212 be an integer.</p></div>
3213 <div class="paragraph
"><p>Note that unless a signal handler for <code>SIGALRM</code> has been installed
3214 (see <a href="#_signal
"><strong><code>signal</code></strong></a>), the process will exit on this signal.</p></div>
3217 <h3 id="_alias
">alias</h3>
3218 <div class="paragraph
"><p><code><strong>alias</strong> <em>name args...</em></code></p></div>
3219 <div class="paragraph
"><p>Creates a single word alias (command) for one or more words. For example,
3220 the following creates an alias for the command <a href="#_info
"><strong><code>info</code></strong></a> <code>exists</code>.</p></div>
3221 <div class="listingblock
">
3222 <div class="content
">
3223 <pre><code> alias e info exists
3228 <div class="paragraph
"><p><a href="#_alias
"><strong><code>alias</code></strong></a> returns <code><em>name</em></code>, allowing it to be used with <a href="#_local
"><strong><code>local</code></strong></a>.</p></div>
3229 <div class="paragraph
"><p>See also <a href="#_proc
"><strong><code>proc</code></strong></a>, <a href="#_curry
"><strong><code>curry</code></strong></a>, <a href="#_lambda
"><strong><code>lambda</code></strong></a>, <a href="#_local
"><strong><code>local</code></strong></a>, <a href="#_info
"><strong><code>info</code></strong></a> <code>alias</code>, <a href="#_exists
"><strong><code>exists</code></strong></a> <code>-alias</code></p></div>
3232 <h3 id="_append
">append</h3>
3233 <div class="paragraph
"><p><code><strong>append</strong> <em>varName value ?value value …?</em></code></p></div>
3234 <div class="paragraph
"><p>Append all of the <code><em>value</em></code> arguments to the current value
3235 of variable <code><em>varName</em></code>. If <code><em>varName</em></code> doesn’t exist,
3236 it is given a value equal to the concatenation of all the
3237 <code><em>value</em></code> arguments.</p></div>
3238 <div class="paragraph
"><p>This command provides an efficient way to build up long
3239 variables incrementally.
3240 For example, "<a href=
"#_append"><strong><code>append
</code></strong></a> <code>a $b
</code>" is much more efficient than
3241 "<a href=
"#_set"><strong><code>set
</code></strong></a> <code>a $a$b
</code>" if <code>$a</code> is long.</p></div>
3244 <h3 id="_apply
">apply</h3>
3245 <div class="paragraph
"><p><code><strong>apply</strong> <em>lambdaExpr ?arg1 arg2 ...?</em></code></p></div>
3246 <div class="paragraph
"><p>The command <a href="#_apply
"><strong><code>apply</code></strong></a> provides for anonymous procedure calls,
3247 similar to <a href="#_lambda
"><strong><code>lambda</code></strong></a>, but without command name being created, even temporarily.</p></div>
3248 <div class="paragraph
"><p>The function <code><em>lambdaExpr</em></code> is a two element list <code>{args body}</code>
3249 or a three element list <code>{args body namespace}</code>. The first element
3250 args specifies the formal arguments, in the same form as the <a href="#_proc
"><strong><code>proc</code></strong></a> and <a href="#_lambda
"><strong><code>lambda</code></strong></a> commands.</p></div>
3253 <h3 id="_array
">array</h3>
3254 <div class="paragraph
"><p><code><strong>array</strong> <em>option arrayName ?arg...?</em></code></p></div>
3255 <div class="paragraph
"><p>This command performs one of several operations on the
3256 variable given by <code><em>arrayName</em></code>.</p></div>
3257 <div class="paragraph
"><p>Note that in general, if the named array does not exist, the <code><em>array</em></code> command behaves
3258 as though the array exists but is empty.</p></div>
3259 <div class="paragraph
"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3260 command. The legal <code><em>options</em></code> (which may be abbreviated) are:</p></div>
3261 <div class="dlist
"><dl>
3262 <dt class="hdlist1
">
3263 <code><strong>array exists</strong> <em>arrayName</em></code>
3267 Returns 1 if arrayName is an array variable, 0 if there is
3268 no variable by that name.
3271 <dt class="hdlist1
">
3272 <code><strong>array get</strong> <em>arrayName ?pattern?</em></code>
3276 Returns a list containing pairs of elements. The first
3277 element in each pair is the name of an element in arrayName
3278 and the second element of each pair is the value of the
3279 array element. The order of the pairs is undefined. If
3280 pattern is not specified, then all of the elements of the
3281 array are included in the result. If pattern is specified,
3282 then only those elements whose names match pattern (using
3283 the matching rules of string match) are included. If arrayName
3284 isn’t the name of an array variable, or if the array contains
3285 no elements, then an empty list is returned.
3288 <dt class="hdlist1
">
3289 <code><strong>array names</strong> <em>arrayName ?pattern?</em></code>
3293 Returns a list containing the names of all of the elements
3294 in the array that match pattern. If pattern is omitted then
3295 the command returns all of the element names in the array.
3296 If pattern is specified, then only those elements whose
3297 names match pattern (using the matching rules of string
3298 match) are included. If there are no (matching) elements
3299 in the array, or if arrayName isn’t the name of an array
3300 variable, then an empty string is returned.
3303 <dt class="hdlist1
">
3304 <code><strong>array set</strong> <em>arrayName list</em></code>
3308 Sets the values of one or more elements in arrayName. list
3309 must have a form like that returned by array get, consisting
3310 of an even number of elements. Each odd-numbered element
3311 in list is treated as an element name within arrayName, and
3312 the following element in list is used as a new value for
3313 that array element. If the variable arrayName does not
3314 already exist and list is empty, arrayName is created with
3315 an empty array value.
3318 <dt class="hdlist1
">
3319 <code><strong>array size</strong> <em>arrayName</em></code>
3323 Returns the number of elements in the array. If arrayName
3324 isn’t the name of an array then 0 is returned.
3327 <dt class="hdlist1
">
3328 <code><strong>array unset</strong> <em>arrayName ?pattern?</em></code>
3332 Unsets all of the elements in the array that match pattern
3333 (using the matching rules of string match). If arrayName
3334 isn’t the name of an array variable or there are no matching
3335 elements in the array, no error will be raised. If pattern
3336 is omitted and arrayName is an array variable, then the
3337 command unsets the entire array. The command always returns
3344 <h3 id="_break
">break</h3>
3345 <div class="paragraph
"><p><code><strong>break</strong></code></p></div>
3346 <div class="paragraph
"><p>This command may be invoked only inside the body of a loop command
3347 such as <a href="#_for
"><strong><code>for</code></strong></a> or <a href="#_foreach
"><strong><code>foreach</code></strong></a> or <a href="#_while
"><strong><code>while</code></strong></a>. It returns a <code>JIM_BREAK</code> code
3348 to signal the innermost containing loop command to return immediately.</p></div>
3351 <h3 id="_case
">case</h3>
3352 <div class="paragraph
"><p>The obsolete <em><code><strong>case</strong></code></em> command has been removed from Jim Tcl since v0.75.
3353 Use <a href="#_switch
"><strong><code>switch</code></strong></a> instead.</p></div>
3356 <h3 id="_catch
">catch</h3>
3357 <div class="paragraph
"><p><code><strong>catch</strong> ?-?no?<em>code ...</em>? ?--? <em>command ?resultVarName? ?optionsVarName?</em></code></p></div>
3358 <div class="paragraph
"><p>The <a href="#_catch
"><strong><code>catch</code></strong></a> command may be used to prevent errors from aborting
3359 command interpretation. <a href="#_catch
"><strong><code>catch</code></strong></a> evaluates <code><em>command</em></code>, and returns a
3360 <code>JIM_OK</code> code, regardless of any errors that might occur while
3361 executing <code><em>command</em></code> (with the possible exception of <code>JIM_SIGNAL</code> -
3362 see below).</p></div>
3363 <div class="paragraph
"><p>The return value from <a href="#_catch
"><strong><code>catch</code></strong></a> is a decimal string giving the code
3364 returned by the Tcl interpreter after executing <code><em>command</em></code>. This
3365 will be <em>0</em> (<code>JIM_OK</code>) if there were no errors in <code><em>command</em></code>; otherwise
3366 it will have a non-zero value corresponding to one of the exceptional
3367 return codes (see jim.h for the definitions of code values, or the
3368 <a href="#_info
"><strong><code>info</code></strong></a> <code>returncodes</code> command).</p></div>
3369 <div class="paragraph
"><p>If the <code><em>resultVarName</em></code> argument is given, then it gives the name
3370 of a variable; <a href="#_catch
"><strong><code>catch</code></strong></a> will set the value of the variable to the
3371 string returned from <code><em>command</em></code> (either a result or an error message).</p></div>
3372 <div class="paragraph
"><p>If the <code><em>optionsVarName</em></code> argument is given, then it gives the name
3373 of a variable; <a href="#_catch
"><strong><code>catch</code></strong></a> will set the value of the variable to a
3374 dictionary. For any return code other than <code>JIM_RETURN</code>, the value
3375 for the key <code>-code</code> will be set to the return code. For <code>JIM_RETURN</code>
3376 it will be set to the code given in <a href="#_return
"><strong><code>return</code></strong></a> <code>-code</code>. Additionally,
3377 for the return code <code>JIM_ERR</code>, the value of the key <code>-errorinfo</code>
3378 will contain the current stack trace (the same result as <a href="#_info
"><strong><code>info</code></strong></a> <code>stacktrace</code>),
3379 the value of the key <code>-errorcode</code> will contain the
3380 same value as the global variable $::errorCode, and the value of
3381 the key <code>-level</code> will be the current return level (see <a href="#_return
"><strong><code>return</code></strong></a> <code>-level</code>).
3382 This can be useful to rethrow an error:</p></div>
3383 <div class="listingblock
">
3384 <div class="content
">
3385 <pre><code> if {[catch {...} msg opts]} {
3386 ...maybe do something with the error...
3388 return {*}$opts $msg
3391 <div class="paragraph
"><p>Normally <a href="#_catch
"><strong><code>catch</code></strong></a> will <code><em>not</em></code> catch any of the codes <code>JIM_EXIT</code>, <code>JIM_EVAL</code> or <code>JIM_SIGNAL</code>.
3392 The set of codes which will be caught may be modified by specifying the one more codes before
3393 <code><em>command</em></code>.</p></div>
3394 <div class="paragraph
"><p>e.g. To catch <code>JIM_EXIT</code> but not <code>JIM_BREAK</code> or <code>JIM_CONTINUE</code></p></div>
3395 <div class="listingblock
">
3396 <div class="content
">
3397 <pre><code> catch -exit -nobreak -nocontinue -- { ... }</code></pre>
3399 <div class="paragraph
"><p>The use of <code>--</code> is optional. It signifies that no more return code options follow.</p></div>
3400 <div class="paragraph
"><p>Note that if a signal marked as <a href="#_signal
"><strong><code>signal</code></strong></a> <code>handle</code> is caught with <a href="#_catch
"><strong><code>catch</code></strong></a> <code>-signal</code>, the return value
3401 (stored in <code><em>resultVarName</em></code>) is name of the signal caught.</p></div>
3404 <h3 id="_cd
">cd</h3>
3405 <div class="paragraph
"><p><code><strong>cd</strong> <em>dirName</em></code></p></div>
3406 <div class="paragraph
"><p>Change the current working directory to <code><em>dirName</em></code>.</p></div>
3407 <div class="paragraph
"><p>Returns an empty string.</p></div>
3408 <div class="paragraph
"><p>This command can potentially be disruptive to an application, so it may
3409 be removed in some applications.</p></div>
3412 <h3 id="_clock
">clock</h3>
3413 <div class="dlist
"><dl>
3414 <dt class="hdlist1
">
3415 <code><strong>clock seconds</strong></code>
3419 Returns the current time as seconds since the epoch.
3422 <dt class="hdlist1
">
3423 <code><strong>clock clicks</strong></code>
3427 Returns the current time in "clicks
", a system-dependent, high-resolution time.
3430 <dt class="hdlist1
">
3431 <code><strong>clock microseconds</strong></code>
3435 Returns the current time in microseconds.
3438 <dt class="hdlist1
">
3439 <code><strong>clock milliseconds</strong></code>
3443 Returns the current time in milliseconds.
3446 <dt class="hdlist1
">
3447 <code><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em> ?<strong>-gmt</strong> <em>boolean?</em></code>
3451 Format the given time (seconds since the epoch) according to the given
3452 format. See strftime(3) for supported formats.
3453 If no format is supplied, "%c
" is used.
3456 <dt class="hdlist1
">
3461 If <code><em>boolean</em></code> is true, processing is performed in UTC.
3462 If <code><em>boolean</em></code> is false (the default), processing is performeed in the local time zone.
3465 <dt class="hdlist1
">
3466 <code><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em> ?<strong>-gmt</strong> <em>boolean?</em></code>
3470 Scan the given time string using the given format string.
3471 See strptime(3) for supported formats.
3472 See <a href="#_clock
"><strong><code>clock</code></strong></a> <code>format</code> for the handling of <em>-gmt</em>.
3478 <h3 id="_close
">close</h3>
3479 <div class="paragraph
"><p><code><strong>close</strong> <em>fileId</em></code></p></div>
3480 <div class="paragraph
"><p><code><em>fileId</em> <strong>close</strong></code></p></div>
3481 <div class="paragraph
"><p>Closes the file given by <code><em>fileId</em></code>.
3482 <code><em>fileId</em></code> must be the return value from a previous invocation
3483 of the <a href="#_open
"><strong><code>open</code></strong></a> command; after this command, it should not be
3484 used anymore.</p></div>
3487 <h3 id="_collect
">collect</h3>
3488 <div class="paragraph
"><p><code><strong>collect</strong></code></p></div>
3489 <div class="paragraph
"><p>Normally reference garbage collection is automatically performed periodically.
3490 However it may be run immediately with the <a href="#_collect
"><strong><code>collect</code></strong></a> command.</p></div>
3491 <div class="paragraph
"><p>See <a href="#_garbage_collection_references_lambda_function
">GARBAGE COLLECTION</a> for more detail.</p></div>
3494 <h3 id="_concat
">concat</h3>
3495 <div class="paragraph
"><p><code><strong>concat</strong> <em>arg ?arg ...?</em></code></p></div>
3496 <div class="paragraph
"><p>This command treats each argument as a list and concatenates them
3497 into a single list. It permits any number of arguments. For example,
3498 the command</p></div>
3499 <div class="listingblock
">
3500 <div class="content
">
3501 <pre><code> concat a b {c d e} {f {g h}}</code></pre>
3503 <div class="paragraph
"><p>will return</p></div>
3504 <div class="listingblock
">
3505 <div class="content
">
3506 <pre><code> a b c d e f {g h}</code></pre>
3508 <div class="paragraph
"><p>as its result.</p></div>
3511 <h3 id="_continue
">continue</h3>
3512 <div class="paragraph
"><p><code><strong>continue</strong></code></p></div>
3513 <div class="paragraph
"><p>This command may be invoked only inside the body of a loop command such
3514 as <a href="#_for
"><strong><code>for</code></strong></a> or <a href="#_foreach
"><strong><code>foreach</code></strong></a> or <a href="#_while
"><strong><code>while</code></strong></a>. It returns a <code>JIM_CONTINUE</code> code to
3515 signal the innermost containing loop command to skip the remainder of
3516 the loop’s body but continue with the next iteration of the loop.</p></div>
3519 <h3 id="_curry
">curry</h3>
3520 <div class="paragraph
"><p><code><strong>alias</strong> <em>args...</em></code></p></div>
3521 <div class="paragraph
"><p>Similar to <a href="#_alias
"><strong><code>alias</code></strong></a> except it creates an anonymous procedure (lambda) instead of
3522 a named procedure.</p></div>
3523 <div class="paragraph
"><p>the following creates a local, unnamed alias for the command <a href="#_info
"><strong><code>info</code></strong></a> <code>exists</code>.</p></div>
3524 <div class="listingblock
">
3525 <div class="content
">
3526 <pre><code> set e [local curry info exists]
3531 <div class="paragraph
"><p><a href="#_curry
"><strong><code>curry</code></strong></a> returns the name of the procedure.</p></div>
3532 <div class="paragraph
"><p>See also <a href="#_proc
"><strong><code>proc</code></strong></a>, <a href="#_alias
"><strong><code>alias</code></strong></a>, <a href="#_lambda
"><strong><code>lambda</code></strong></a>, <a href="#_local
"><strong><code>local</code></strong></a>.</p></div>
3535 <h3 id="_dict
">dict</h3>
3536 <div class="paragraph
"><p><code><strong>dict</strong> <em>option ?arg...?</em></code></p></div>
3537 <div class="paragraph
"><p>Performs one of several operations on dictionary values.</p></div>
3538 <div class="paragraph
"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3539 command. The legal <code><em>options</em></code> are:</p></div>
3540 <div class="dlist
"><dl>
3541 <dt class="hdlist1
">
3542 <code><strong>dict create</strong> <em>?key value ...?</em></code>
3546 Create and return a new dictionary value that contains each of
3547 the key/value mappings listed as arguments (keys and values
3548 alternating, with each key being followed by its associated
3552 <dt class="hdlist1
">
3553 <code><strong>dict exists</strong> <em>dictionary key ?key ...?</em></code>
3557 Returns a boolean value indicating whether the given key (or path
3558 of keys through a set of nested dictionaries) exists in the given
3559 dictionary value. This returns a true value exactly when <a href="#_dict
"><strong><code>dict</code></strong></a> <code>get</code>
3560 on that path will succeed.
3563 <dt class="hdlist1
">
3564 <code><strong>dict get</strong> <em>dictionary ?key ...?</em></code>
3568 Given a dictionary value (first argument) and a key (second argument),
3569 this will retrieve the value for that key. Where several keys are
3570 supplied, the behaviour of the command shall be as if the result
3571 of "<a href=
"#_dict"><strong><code>dict
</code></strong></a> <code>get $dictVal $key
</code>" was passed as the first argument to
3572 dict get with the remaining arguments as second (and possibly
3573 subsequent) arguments. This facilitates lookups in nested dictionaries.
3574 If no keys are provided, dict would return a list containing pairs
3575 of elements in a manner similar to array get. That is, the first
3576 element of each pair would be the key and the second element would
3577 be the value for that key. It is an error to attempt to retrieve
3578 a value for a key that is not present in the dictionary.
3581 <dt class="hdlist1
">
3582 <code><strong>dict keys</strong> <em>dictionary ?pattern?</em></code>
3586 Returns a list of the keys in the dictionary.
3587 If pattern is specified, then only those keys whose
3588 names match <code><em>pattern</em></code> (using the matching rules of string
3589 match) are included.
3592 <dt class="hdlist1
">
3593 <code><strong>dict merge</strong> ?<em>dictionary ...</em>?</code>
3597 Return a dictionary that contains the contents of each of the
3598 <code><em>dictionary</em></code> arguments. Where two (or more) dictionaries
3599 contain a mapping for the same key, the resulting dictionary
3600 maps that key to the value according to the last dictionary on
3601 the command line containing a mapping for that key.
3604 <dt class="hdlist1
">
3605 <code><strong>dict set</strong> <em>dictionaryName key ?key ...? value</em></code>
3609 This operation takes the <code><em>name</em></code> of a variable containing a dictionary
3610 value and places an updated dictionary value in that variable
3611 containing a mapping from the given key to the given value. When
3612 multiple keys are present, this operation creates or updates a chain
3613 of nested dictionaries.
3616 <dt class="hdlist1
">
3617 <code><strong>dict size</strong> <em>dictionary</em></code>
3621 Return the number of key/value mappings in the given dictionary value.
3624 <dt class="hdlist1
">
3625 <code><strong>dict unset</strong> <em>dictionaryName key ?key ...? value</em></code>
3629 This operation (the companion to <a href="#_dict
"><strong><code>dict</code></strong></a> <code>set</code>) takes the name of a
3630 variable containing a dictionary value and places an updated
3631 dictionary value in that variable that does not contain a mapping
3632 for the given key. Where multiple keys are present, this describes
3633 a path through nested dictionaries to the mapping to remove. At
3634 least one key must be specified, but the last key on the key-path
3635 need not exist. All other components on the path must exist.
3638 <dt class="hdlist1
">
3639 <code><strong>dict with</strong> <em>dictionaryName key ?key ...? script</em></code>
3643 Execute the Tcl script in <code><em>script</em></code> with the value for each
3644 key in <code><em>dictionaryName</em></code> mapped to a variable with the same
3645 name. Where one or more keys are given, these indicate a chain
3646 of nested dictionaries, with the innermost dictionary being the
3647 one opened out for the execution of body. Making <code><em>dictionaryName</em></code>
3648 unreadable will make the updates to the dictionary be discarded,
3649 and this also happens if the contents of <code><em>dictionaryName</em></code> are
3650 adjusted so that the chain of dictionaries no longer exists.
3651 The result of <a href="#_dict
"><strong><code>dict</code></strong></a> <code>with</code> is (unless some kind of error occurs)
3652 the result of the evaluation of body.
3655 <dt class="hdlist1
">
3660 The variables are mapped in the scope enclosing the <a href="#_dict
"><strong><code>dict</code></strong></a> <code>with</code>;
3661 it is recommended that this command only be used in a local
3662 scope (procedure). Because of this, the variables set by
3663 <a href="#_dict
"><strong><code>dict</code></strong></a> <code>with</code> will continue to exist after the command finishes (unless
3664 explicitly unset). Note that changes to the contents of <code><em>dictionaryName</em></code>
3665 only happen when <code><em>script</em></code> terminates.
3669 <div class="paragraph
"><p><code><strong>dict for, values, incr, append, lappend, update, info, replace</strong></code> to be documented…</p></div>
3672 <h3 id="_env
">env</h3>
3673 <div class="paragraph
"><p><code><strong>env</strong> <em>?name? ?default?</em></code></p></div>
3674 <div class="paragraph
"><p>If <code><em>name</em></code> is supplied, returns the value of <code><em>name</em></code> from the initial
3675 environment (see getenv(3)). An error is returned if <code><em>name</em></code> does not
3676 exist in the environment, unless <code><em>default</em></code> is supplied - in which case
3677 that value is returned instead.</p></div>
3678 <div class="paragraph
"><p>If no arguments are supplied, returns a list of all environment variables
3679 and their values as <code>{name value ...}</code></p></div>
3680 <div class="paragraph
"><p>See also the global variable <code>::env</code></p></div>
3683 <h3 id="_eof
">eof</h3>
3684 <div class="paragraph
"><p><code><strong>eof</strong> <em>fileId</em></code></p></div>
3685 <div class="paragraph
"><p><code><em>fileId</em> <strong>eof</strong></code></p></div>
3686 <div class="paragraph
"><p>Returns 1 if an end-of-file condition has occurred on <code><em>fileId</em></code>,
3687 0 otherwise.</p></div>
3688 <div class="paragraph
"><p><code><em>fileId</em></code> must have been the return value from a previous call to <a href="#_open
"><strong><code>open</code></strong></a>,
3689 or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one of the
3690 standard I/O channels.</p></div>
3693 <h3 id="_error
">error</h3>
3694 <div class="paragraph
"><p><code><strong>error</strong> <em>message ?stacktrace?</em></code></p></div>
3695 <div class="paragraph
"><p>Returns a <code>JIM_ERR</code> code, which causes command interpretation to be
3696 unwound. <code><em>message</em></code> is a string that is returned to the application
3697 to indicate what went wrong.</p></div>
3698 <div class="paragraph
"><p>If the <code><em>stacktrace</em></code> argument is provided and is non-empty,
3699 it is used to initialize the stacktrace.</p></div>
3700 <div class="paragraph
"><p>This feature is most useful in conjunction with the <a href="#_catch
"><strong><code>catch</code></strong></a> command:
3701 if a caught error cannot be handled successfully, <code><em>stacktrace</em></code> can be used
3702 to return a stack trace reflecting the original point of occurrence
3703 of the error:</p></div>
3704 <div class="listingblock
">
3705 <div class="content
">
3706 <pre><code> catch {...} errMsg
3708 error $errMsg [info stacktrace]</code></pre>
3710 <div class="paragraph
"><p>See also <code>errorInfo</code>, <a href="#_info
"><strong><code>info</code></strong></a> <code>stacktrace</code>, <a href="#_catch
"><strong><code>catch</code></strong></a> and <a href="#_return
"><strong><code>return</code></strong></a></p></div>
3713 <h3 id="_errorinfo
">errorInfo</h3>
3714 <div class="paragraph
"><p><code><strong>errorInfo</strong> <em>error ?stacktrace?</em></code></p></div>
3715 <div class="paragraph
"><p>Returns a human-readable representation of the given error message and stack trace.
3716 Typical usage is:</p></div>
3717 <div class="listingblock
">
3718 <div class="content
">
3719 <pre><code> if {[catch {...} error]} {
3720 puts stderr [errorInfo $error [info stacktrace]]
3724 <div class="paragraph
"><p>See also <a href="#_error
"><strong><code>error</code></strong></a>.</p></div>
3727 <h3 id="_eval
">eval</h3>
3728 <div class="paragraph
"><p><code><strong>eval</strong> <em>arg ?arg...?</em></code></p></div>
3729 <div class="paragraph
"><p><a href="#_eval
"><strong><code>eval</code></strong></a> takes one or more arguments, which together comprise a Tcl
3730 command (or collection of Tcl commands separated by newlines in the
3731 usual way). <a href="#_eval
"><strong><code>eval</code></strong></a> concatenates all its arguments in the same
3732 fashion as the <a href="#_concat
"><strong><code>concat</code></strong></a> command, passes the concatenated string to the
3733 Tcl interpreter recursively, and returns the result of that
3734 evaluation (or any error generated by it).</p></div>
3737 <h3 id="_exec
">exec</h3>
3738 <div class="paragraph
"><p><code><strong>exec</strong> <em>arg ?arg...?</em></code></p></div>
3739 <div class="paragraph
"><p>This command treats its arguments as the specification
3740 of one or more UNIX commands to execute as subprocesses.
3741 The commands take the form of a standard shell pipeline;
3742 <code>|</code> arguments separate commands in the
3743 pipeline and cause standard output of the preceding command
3744 to be piped into standard input of the next command (or <code>|&</code> for
3745 both standard output and standard error).</p></div>
3746 <div class="paragraph
"><p>Under normal conditions the result of the <a href="#_exec
"><strong><code>exec</code></strong></a> command
3747 consists of the standard output produced by the last command
3748 in the pipeline followed by the standard error output.</p></div>
3749 <div class="paragraph
"><p>If any of the commands writes to its standard error file,
3750 then this will be included in the result after the standard output
3751 of the last command.</p></div>
3752 <div class="paragraph
"><p>Note that unlike Tcl, data written to standard error does not cause
3753 <a href="#_exec
"><strong><code>exec</code></strong></a> to return an error.</p></div>
3754 <div class="paragraph
"><p>If any of the commands in the pipeline exit abnormally or
3755 are killed or suspended, then <a href="#_exec
"><strong><code>exec</code></strong></a> will return an error.
3756 If no standard error output was produced, or is redirected,
3757 the error message will include the normal result, as above,
3758 followed by error messages describing the abnormal terminations.</p></div>
3759 <div class="paragraph
"><p>If any standard error output was produced, these abnormal termination
3760 messages are suppressed.</p></div>
3761 <div class="paragraph
"><p>If the last character of the result or error message
3762 is a newline then that character is deleted from the result
3763 or error message for consistency with normal
3764 Tcl return values.</p></div>
3765 <div class="paragraph
"><p>An <code><em>arg</em></code> may have one of the following special forms:</p></div>
3766 <div class="dlist
"><dl>
3767 <dt class="hdlist1
">
3768 <code>>filename</code>
3772 The standard output of the last command in the pipeline
3773 is redirected to the file. In this situation <a href="#_exec
"><strong><code>exec</code></strong></a>
3774 will normally return an empty string.
3777 <dt class="hdlist1
">
3778 <code>>>filename</code>
3782 As above, but append to the file.
3785 <dt class="hdlist1
">
3786 <code>>@fileId</code>
3790 The standard output of the last command in the pipeline is
3791 redirected to the given (writable) file descriptor (e.g. stdout,
3792 stderr, or the result of <a href="#_open
"><strong><code>open</code></strong></a>). In this situation <a href="#_exec
"><strong><code>exec</code></strong></a>
3793 will normally return an empty string.
3796 <dt class="hdlist1
">
3797 <code>2>filename</code>
3801 The standard error of the last command in the pipeline
3802 is redirected to the file.
3805 <dt class="hdlist1
">
3806 <code>2>>filename</code>
3810 As above, but append to the file.
3813 <dt class="hdlist1
">
3814 <code>2>@fileId</code>
3818 The standard error of the last command in the pipeline is
3819 redirected to the given (writable) file descriptor.
3822 <dt class="hdlist1
">
3823 <code>2>@1</code>
3827 The standard error of the last command in the pipeline is
3828 redirected to the same file descriptor as the standard output.
3831 <dt class="hdlist1
">
3832 <code>>&filename</code>
3836 Both the standard output and standard error of the last command
3837 in the pipeline is redirected to the file.
3840 <dt class="hdlist1
">
3841 <code>>>&filename</code>
3845 As above, but append to the file.
3848 <dt class="hdlist1
">
3849 <code><filename</code>
3853 The standard input of the first command in the pipeline
3854 is taken from the file.
3857 <dt class="hdlist1
">
3858 <code><<string</code>
3862 The standard input of the first command is taken as the
3863 given immediate value.
3866 <dt class="hdlist1
">
3867 <code><@fileId</code>
3871 The standard input of the first command in the pipeline
3872 is taken from the given (readable) file descriptor.
3876 <div class="paragraph
"><p>If there is no redirection of standard input, standard error
3877 or standard output, these are connected to the corresponding
3878 input or output of the application.</p></div>
3879 <div class="paragraph
"><p>If the last <code><em>arg</em></code> is <code>&</code> then the command will be
3880 executed in background.
3881 In this case the standard output from the last command
3882 in the pipeline will
3883 go to the application’s standard output unless
3884 redirected in the command, and error output from all
3885 the commands in the pipeline will go to the application’s
3886 standard error file. The return value of exec in this case
3887 is a list of process ids (pids) in the pipeline.</p></div>
3888 <div class="paragraph
"><p>Each <code><em>arg</em></code> becomes one word for a command, except for
3889 <code>|</code>, <code><</code>, <code><<</code>, <code>></code>, and <code>&</code> arguments, and the
3890 arguments that follow <code><</code>, <code><<</code>, and <code>></code>.</p></div>
3891 <div class="paragraph
"><p>The first word in each command is taken as the command name;
3892 the directories in the PATH environment variable are searched for
3893 an executable by the given name.</p></div>
3894 <div class="paragraph
"><p>No <a href="#_glob
"><strong><code>glob</code></strong></a> expansion or other shell-like substitutions
3895 are performed on the arguments to commands.</p></div>
3896 <div class="paragraph
"><p>If the command fails, the global $::errorCode (and the -errorcode
3897 option in <a href="#_catch
"><strong><code>catch</code></strong></a>) will be set to a list, as follows:</p></div>
3898 <div class="dlist
"><dl>
3899 <dt class="hdlist1
">
3900 <code><strong>CHILDKILLED</strong> <em>pid sigName msg</em></code>
3904 This format is used when a child process has been killed
3905 because of a signal. The pid element will be the process’s
3906 identifier (in decimal). The sigName element will be the
3907 symbolic name of the signal that caused the process to
3908 terminate; it will be one of the names from the include
3909 file signal.h, such as SIGPIPE. The msg element will be a
3910 short human-readable message describing the signal, such
3911 as "write on pipe with no readers
" for SIGPIPE.
3914 <dt class="hdlist1
">
3915 <code><strong>CHILDSUSP</strong> <em>pid sigName msg</em></code>
3919 This format is used when a child process has been suspended
3920 because of a signal. The pid element will be the process’s
3921 identifier, in decimal. The sigName element will be the
3922 symbolic name of the signal that caused the process to
3923 suspend; this will be one of the names from the include
3924 file signal.h, such as SIGTTIN. The msg element will be a
3925 short human-readable message describing the signal, such
3926 as "background tty read
" for SIGTTIN.
3929 <dt class="hdlist1
">
3930 <code><strong>CHILDSTATUS</strong> <em>pid code</em></code>
3934 This format is used when a child process has exited with a
3935 non-zero exit status. The pid element will be the process’s
3936 identifier (in decimal) and the code element will be the
3937 exit code returned by the process (also in decimal).
3941 <div class="paragraph
"><p>The environment for the executed command is set from $::env (unless
3942 this variable is unset, in which case the original environment is used).</p></div>
3945 <h3 id="_exists
">exists</h3>
3946 <div class="paragraph
"><p><code><strong>exists ?-var|-proc|-command|-alias?</strong> <em>name</em></code></p></div>
3947 <div class="paragraph
"><p>Checks the existence of the given variable, procedure, command
3948 or alias respectively and returns 1 if it exists or 0 if not. This command
3949 provides a more simplified/convenient version of <a href="#_info
"><strong><code>info</code></strong></a> <code>exists</code>,
3950 <a href="#_info
"><strong><code>info</code></strong></a> <code>procs</code> and <a href="#_info
"><strong><code>info</code></strong></a> <code>commands</code>.</p></div>
3951 <div class="paragraph
"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
3954 <h3 id="_exit
">exit</h3>
3955 <div class="paragraph
"><p><code><strong>exit</strong> <em>?returnCode?</em></code></p></div>
3956 <div class="paragraph
"><p>Terminate the process, returning <code><em>returnCode</em></code> to the
3957 parent as the exit status.</p></div>
3958 <div class="paragraph
"><p>If <code><em>returnCode</em></code> isn’t specified then it defaults
3960 <div class="paragraph
"><p>Note that exit can be caught with <a href="#_catch
"><strong><code>catch</code></strong></a>.</p></div>
3963 <h3 id="_expr
">expr</h3>
3964 <div class="paragraph
"><p><code><strong>expr</strong> <em>arg</em></code></p></div>
3965 <div class="paragraph
"><p>Calls the expression processor to evaluate <code><em>arg</em></code>, and returns
3966 the result as a string. See the section <a href="#_expressions
">EXPRESSIONS</a> above.</p></div>
3967 <div class="paragraph
"><p>Note that Jim supports a shorthand syntax for <a href="#_expr
"><strong><code>expr</code></strong></a> as <code>$(...)</code>
3968 The following two are identical.</p></div>
3969 <div class="listingblock
">
3970 <div class="content
">
3971 <pre><code> set x [expr {3 * 2 + 1}]
3972 set x $(3 * 2 + 1)</code></pre>
3976 <h3 id="_file
">file</h3>
3977 <div class="paragraph
"><p><code><strong>file</strong> <em>option name ?arg...?</em></code></p></div>
3978 <div class="paragraph
"><p>Operate on a file or a file name. <code><em>name</em></code> is the name of a file.</p></div>
3979 <div class="paragraph
"><p><code><em>option</em></code> indicates what to do with the file name. Any unique
3980 abbreviation for <code><em>option</em></code> is acceptable. The valid options are:</p></div>
3981 <div class="dlist
"><dl>
3982 <dt class="hdlist1
">
3983 <code><strong>file atime</strong> <em>name</em></code>
3987 Return a decimal string giving the time at which file <code><em>name</em></code>
3988 was last accessed. The time is measured in the standard UNIX
3989 fashion as seconds from a fixed starting time (often January 1, 1970).
3990 If the file doesn’t exist or its access time cannot be queried then an
3994 <dt class="hdlist1
">
3995 <code><strong>file copy ?-force?</strong> <em>source target</em></code>
3999 Copies file <code><em>source</em></code> to file <code><em>target</em></code>. The source file must exist.
4000 The target file must not exist, unless <code>-force</code> is specified.
4003 <dt class="hdlist1
">
4004 <code><strong>file delete ?-force? ?--?</strong> <em>name...</em></code>
4008 Deletes file or directory <code><em>name</em></code>. If the file or directory doesn’t exist, nothing happens.
4009 If it can’t be deleted, an error is generated. Non-empty directories will not be deleted
4010 unless the <code>-force</code> options is given. In this case no errors will be generated, even
4011 if the file/directory can’t be deleted. Use <code><em>--</em></code> if there is any possibility of
4012 the first name being <code><em>-force</em></code>.
4015 <dt class="hdlist1
">
4016 <code><strong>file dirname</strong> <em>name</em></code>
4020 Return all of the characters in <code><em>name</em></code> up to but not including
4021 the last slash character. If there are no slashes in <code><em>name</em></code>
4022 then return <code>.</code> (a single dot). If the last slash in <code><em>name</em></code> is its first
4023 character, then return <code>/</code>.
4026 <dt class="hdlist1
">
4027 <code><strong>file executable</strong> <em>name</em></code>
4031 Return <em>1</em> if file <code><em>name</em></code> is executable by
4032 the current user, <em>0</em> otherwise.
4035 <dt class="hdlist1
">
4036 <code><strong>file exists</strong> <em>name</em></code>
4040 Return <em>1</em> if file <code><em>name</em></code> exists and the current user has
4041 search privileges for the directories leading to it, <em>0</em> otherwise.
4044 <dt class="hdlist1
">
4045 <code><strong>file extension</strong> <em>name</em></code>
4049 Return all of the characters in <code><em>name</em></code> after and including the
4050 last dot in <code><em>name</em></code>. If there is no dot in <code><em>name</em></code> then return
4054 <dt class="hdlist1
">
4055 <code><strong>file isdirectory</strong> <em>name</em></code>
4059 Return <em>1</em> if file <code><em>name</em></code> is a directory,
4060 <em>0</em> otherwise.
4063 <dt class="hdlist1
">
4064 <code><strong>file isfile</strong> <em>name</em></code>
4068 Return <em>1</em> if file <code><em>name</em></code> is a regular file,
4069 <em>0</em> otherwise.
4072 <dt class="hdlist1
">
4073 <code><strong>file join</strong> <em>arg...</em></code>
4077 Joins multiple path components. Note that if any components is
4078 an absolute path, the preceding components are ignored.
4079 Thus <code>"<a href=
"#_file"><strong><code>file
</code></strong></a> join /tmp /root
"</code> returns <code>"/root
"</code>.
4082 <dt class="hdlist1
">
4083 <code><strong>file link</strong> ?<strong>-hard|-symbolic</strong>? <em>newname target</em></code>
4087 Creates a hard link (default) or symbolic link from <code><em>newname</em></code> to <code><em>target</em></code>.
4088 Note that the sense of this command is the opposite of <a href="#_file
"><strong><code>file</code></strong></a> <code>rename</code> and <a href="#_file
"><strong><code>file</code></strong></a> <code>copy</code>
4089 and also of <code>ln</code>, but this is compatible with Tcl.
4090 An error is returned if <code><em>target</em></code> doesn’t exist or <code><em>newname</em></code> already exists.
4093 <dt class="hdlist1
">
4094 <code><strong>file lstat</strong> <em>name varName</em></code>
4098 Same as <em>stat</em> option (see below) except uses the <code><em>lstat</em></code>
4099 kernel call instead of <code><em>stat</em></code>. This means that if <code><em>name</em></code>
4100 refers to a symbolic link the information returned in <code><em>varName</em></code>
4101 is for the link rather than the file it refers to. On systems that
4102 don’t support symbolic links this option behaves exactly the same
4103 as the <em>stat</em> option.
4106 <dt class="hdlist1
">
4107 <code><strong>file mkdir</strong> <em>dir1 ?dir2...?</em></code>
4111 Creates each directory specified. For each pathname <code><em>dir</em></code> specified,
4112 this command will create all non-existing parent directories
4113 as well as <code><em>dir</em></code> itself. If an existing directory is specified,
4114 then no action is taken and no error is returned. Trying to
4115 overwrite an existing file with a directory will result in an
4116 error. Arguments are processed in the order specified, halting
4117 at the first error, if any.
4120 <dt class="hdlist1
">
4121 <code><strong>file mtime</strong> <em>name ?time?</em></code>
4125 Return a decimal string giving the time at which file <code><em>name</em></code>
4126 was last modified. The time is measured in the standard UNIX
4127 fashion as seconds from a fixed starting time (often January 1, 1970).
4128 If the file doesn’t exist or its modified time cannot be queried then an
4129 error is generated. If <code><em>time</em></code> is given, sets the modification time
4130 of the file to the given value.
4133 <dt class="hdlist1
">
4134 <code><strong>file mtimeus</strong> <em>name ?time_us?</em></code>
4138 As for <a href="#_file
"><strong><code>file</code></strong></a> <code>mtime</code> except the time value is in microseconds
4139 since the epoch (see also <a href="#_clock
"><strong><code>clock</code></strong></a> <code>microseconds</code>).
4140 Note that some platforms and some filesystems don’t support high
4141 resolution timestamps for files.
4144 <dt class="hdlist1
">
4145 <code><strong>file normalize</strong> <em>name</em></code>
4149 Return the normalized path of <code><em>name</em></code>. See <em>realpath(3)</em>.
4152 <dt class="hdlist1
">
4153 <code><strong>file owned</strong> <em>name</em></code>
4157 Return <em>1</em> if file <code><em>name</em></code> is owned by the current user,
4158 <em>0</em> otherwise.
4161 <dt class="hdlist1
">
4162 <code><strong>file readable</strong> <em>name</em></code>
4166 Return <em>1</em> if file <code><em>name</em></code> is readable by
4167 the current user, <em>0</em> otherwise.
4170 <dt class="hdlist1
">
4171 <code><strong>file readlink</strong> <em>name</em></code>
4175 Returns the value of the symbolic link given by <code><em>name</em></code> (i.e. the
4176 name of the file it points to). If
4177 <code><em>name</em></code> isn’t a symbolic link or its value cannot be read, then
4178 an error is returned. On systems that don’t support symbolic links
4179 this option is undefined.
4182 <dt class="hdlist1
">
4183 <code><strong>file rename</strong> ?<strong>-force</strong>? <em>oldname</em> <em>newname</em></code>
4187 Renames the file from the old name to the new name.
4188 If <code><em>newname</em></code> already exists, an error is returned unless <code><em>-force</em></code> is
4192 <dt class="hdlist1
">
4193 <code><strong>file rootname</strong> <em>name</em></code>
4197 Return all of the characters in <code><em>name</em></code> up to but not including
4198 the last <em>.</em> character in the name. If <code><em>name</em></code> doesn’t contain
4199 a dot, then return <code><em>name</em></code>.
4202 <dt class="hdlist1
">
4203 <code><strong>file split</strong> <em>name</em></code>
4207 Returns a list whose elements are the path components in <code><em>name</em></code>.
4208 The first element of the list will have the same path type as
4209 <code><em>name</em></code>. All other elements will be relative. Path separators
4213 <dt class="hdlist1
">
4214 <code><strong>file stat</strong> <em>name ?varName?</em></code>
4218 Invoke the <em>stat</em> kernel call on <code><em>name</em></code>, and return the result
4219 as a dictionary with the following keys: <em>atime</em>,
4220 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
4221 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>, <em>mtimeus</em> (if supported - see <a href="#_file
"><strong><code>file</code></strong></a> <code>mtimeus</code>)
4222 Each element except <em>type</em> is a decimal string with the value of
4223 the corresponding field from the <em>stat</em> return structure; see the
4224 manual entry for <em>stat</em> for details on the meanings of the values.
4225 The <em>type</em> element gives the type of the file in the same form
4226 returned by the command <a href="#_file
"><strong><code>file</code></strong></a> <code>type</code>.
4227 If <code><em>varName</em></code> is specified, it is taken to be the name of an array
4228 variable and the values are also stored into the array.
4231 <dt class="hdlist1
">
4232 <code><strong>file tail</strong> <em>name</em></code>
4236 Return all of the characters in <code><em>name</em></code> after the last slash.
4237 If <code><em>name</em></code> contains no slashes then return <code><em>name</em></code>.
4240 <dt class="hdlist1
">
4241 <code><strong>file tempfile</strong> <em>?template?</em></code>
4245 Creates and returns the name of a unique temporary file. If <code><em>template</em></code> is omitted, a
4246 default template will be used to place the file in /tmp. See <em>mkstemp(3)</em> for
4247 the format of the template and security concerns.
4250 <dt class="hdlist1
">
4251 <code><strong>file type</strong> <em>name</em></code>
4255 Returns a string giving the type of file <code><em>name</em></code>, which will be
4256 one of <code>file</code>, <code>directory</code>, <code>characterSpecial</code>,
4257 <code>blockSpecial</code>, <code>fifo</code>, <code>link</code>, or <code>socket</code>.
4260 <dt class="hdlist1
">
4261 <code><strong>file writable</strong> <em>name</em></code>
4265 Return <em>1</em> if file <code><em>name</em></code> is writable by
4266 the current user, <em>0</em> otherwise.
4270 <div class="paragraph
"><p>The <a href="#_file
"><strong><code>file</code></strong></a> commands that return 0/1 results are often used in
4271 conditional or looping commands, for example:</p></div>
4272 <div class="listingblock
">
4273 <div class="content
">
4274 <pre><code> if {![file exists foo]} {
4275 error {bad file name}
4282 <h3 id="_finalize
">finalize</h3>
4283 <div class="paragraph
"><p><code><strong>finalize</strong> <em>reference ?command?</em></code></p></div>
4284 <div class="paragraph
"><p>If <code><em>command</em></code> is omitted, returns the finalizer command for the given reference.</p></div>
4285 <div class="paragraph
"><p>Otherwise, sets a new finalizer command for the given reference. <code><em>command</em></code> may be
4286 the empty string to remove the current finalizer.</p></div>
4287 <div class="paragraph
"><p>The reference must be a valid reference create with the <a href="#_ref
"><strong><code>ref</code></strong></a>
4289 <div class="paragraph
"><p>See <a href="#_garbage_collection_references_lambda_function
">GARBAGE COLLECTION</a> for more detail.</p></div>
4292 <h3 id="_flush
">flush</h3>
4293 <div class="paragraph
"><p><code><strong>flush</strong> <em>fileId</em></code></p></div>
4294 <div class="paragraph
"><p><code><em>fileId</em> <strong>flush</strong></code></p></div>
4295 <div class="paragraph
"><p>Flushes any output that has been buffered for <code><em>fileId</em></code>. <code><em>fileId</em></code> must
4296 have been the return value from a previous call to <a href="#_open
"><strong><code>open</code></strong></a>, or it may be
4297 <code>stdout</code> or <code>stderr</code> to access one of the standard I/O streams; it must
4298 refer to a file that was opened for writing. This command returns an
4299 empty string.</p></div>
4302 <h3 id="_for
">for</h3>
4303 <div class="paragraph
"><p><code><strong>for</strong> <em>start test next body</em></code></p></div>
4304 <div class="paragraph
"><p><a href="#_for
"><strong><code>for</code></strong></a> is a looping command, similar in structure to the C <a href="#_for
"><strong><code>for</code></strong></a> statement.
4305 The <code><em>start</em></code>, <code><em>next</em></code>, and <code><em>body</em></code> arguments must be Tcl command strings,
4306 and <code><em>test</em></code> is an expression string.</p></div>
4307 <div class="paragraph
"><p>The <a href="#_for
"><strong><code>for</code></strong></a> command first invokes the Tcl interpreter to execute <code><em>start</em></code>.
4308 Then it repeatedly evaluates <code><em>test</em></code> as an expression; if the result is
4309 non-zero it invokes the Tcl interpreter on <code><em>body</em></code>, then invokes the Tcl
4310 interpreter on <code><em>next</em></code>, then repeats the loop. The command terminates
4311 when <code><em>test</em></code> evaluates to 0.</p></div>
4312 <div class="paragraph
"><p>If a <a href="#_continue
"><strong><code>continue</code></strong></a> command is invoked within <code><em>body</em></code> then any remaining
4313 commands in the current execution of <code><em>body</em></code> are skipped; processing
4314 continues by invoking the Tcl interpreter on <code><em>next</em></code>, then evaluating
4315 <code><em>test</em></code>, and so on.</p></div>
4316 <div class="paragraph
"><p>If a <a href="#_break
"><strong><code>break</code></strong></a> command is invoked within <code><em>body</em></code> or <code><em>next</em></code>, then the <a href="#_for
"><strong><code>for</code></strong></a>
4317 command will return immediately.</p></div>
4318 <div class="paragraph
"><p>The operation of <a href="#_break
"><strong><code>break</code></strong></a> and <a href="#_continue
"><strong><code>continue</code></strong></a> are similar to the corresponding
4319 statements in C.</p></div>
4320 <div class="paragraph
"><p><a href="#_for
"><strong><code>for</code></strong></a> returns an empty string.</p></div>
4323 <h3 id="_foreach
">foreach</h3>
4324 <div class="paragraph
"><p><code><strong>foreach</strong> <em>varName list body</em></code></p></div>
4325 <div class="paragraph
"><p><code><strong>foreach</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
4326 <div class="paragraph
"><p>In this command, <code><em>varName</em></code> is the name of a variable, <code><em>list</em></code>
4327 is a list of values to assign to <code><em>varName</em></code>, and <code><em>body</em></code> is a
4328 collection of Tcl commands.</p></div>
4329 <div class="paragraph
"><p>For each field in <code><em>list</em></code> (in order from left to right), <a href="#_foreach
"><strong><code>foreach</code></strong></a> assigns
4330 the contents of the field to <code><em>varName</em></code> (as if the <a href="#_lindex
"><strong><code>lindex</code></strong></a> command
4331 had been used to extract the field), then calls the Tcl interpreter to
4332 execute <code><em>body</em></code>.</p></div>
4333 <div class="paragraph
"><p>If instead of being a simple name, <code><em>varList</em></code> is used, multiple assignments
4334 are made each time through the loop, one for each element of <code><em>varList</em></code>.</p></div>
4335 <div class="paragraph
"><p>For example, if there are two elements in <code><em>varList</em></code> and six elements in
4336 the list, the loop will be executed three times.</p></div>
4337 <div class="paragraph
"><p>If the length of the list doesn’t evenly divide by the number of elements
4338 in <code><em>varList</em></code>, the value of the remaining variables in the last iteration
4339 of the loop are undefined.</p></div>
4340 <div class="paragraph
"><p>The <a href="#_break
"><strong><code>break</code></strong></a> and <a href="#_continue
"><strong><code>continue</code></strong></a> statements may be invoked inside <code><em>body</em></code>,
4341 with the same effect as in the <a href="#_for
"><strong><code>for</code></strong></a> command.</p></div>
4342 <div class="paragraph
"><p><a href="#_foreach
"><strong><code>foreach</code></strong></a> returns an empty string.</p></div>
4345 <h3 id="_format
">format</h3>
4346 <div class="paragraph
"><p><code><strong>format</strong> <em>formatString ?arg ...?</em></code></p></div>
4347 <div class="paragraph
"><p>This command generates a formatted string in the same way as the
4348 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
4349 implementation). <code><em>formatString</em></code> indicates how to format
4350 the result, using <code>%</code> fields as in <em>sprintf</em>, and the additional
4351 arguments, if any, provide values to be substituted into the result.</p></div>
4352 <div class="paragraph
"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
4353 man page for details. Each <code><em>arg</em></code> must match the expected type
4354 from the <code>%</code> field in <code><em>formatString</em></code>; the <a href="#_format
"><strong><code>format</code></strong></a> command
4355 converts each argument to the correct type (floating, integer, etc.)
4356 before passing it to <em>sprintf</em> for formatting.</p></div>
4357 <div class="paragraph
"><p>The only unusual conversion is for <code>%c</code>; in this case the argument
4358 must be a decimal string, which will then be converted to the corresponding
4359 ASCII (or UTF-8) character value.</p></div>
4360 <div class="paragraph
"><p>In addition, Jim Tcl provides basic support for conversion to binary with <code>%b</code>.</p></div>
4361 <div class="paragraph
"><p><a href="#_format
"><strong><code>format</code></strong></a> does backslash substitution on its <code><em>formatString</em></code>
4362 argument, so backslash sequences in <code><em>formatString</em></code> will be handled
4363 correctly even if the argument is in braces.</p></div>
4364 <div class="paragraph
"><p>The return value from <a href="#_format
"><strong><code>format</code></strong></a> is the formatted string.</p></div>
4367 <h3 id="_getref
">getref</h3>
4368 <div class="paragraph
"><p><code><strong>getref</strong> <em>reference</em></code></p></div>
4369 <div class="paragraph
"><p>Returns the string associated with <code><em>reference</em></code>. The reference must
4370 be a valid reference create with the <a href="#_ref
"><strong><code>ref</code></strong></a> command.</p></div>
4371 <div class="paragraph
"><p>See <a href="#_garbage_collection_references_lambda_function
">GARBAGE COLLECTION</a> for more detail.</p></div>
4374 <h3 id="_gets
">gets</h3>
4375 <div class="paragraph
"><p><code><strong>gets</strong> <em>fileId ?varName?</em></code></p></div>
4376 <div class="paragraph
"><p><code><em>fileId</em> <strong>gets</strong> <em>?varName?</em></code></p></div>
4377 <div class="paragraph
"><p>Reads the next line from the file given by <code><em>fileId</em></code> and discards
4378 the terminating newline character.</p></div>
4379 <div class="paragraph
"><p>If <code><em>varName</em></code> is specified, then the line is placed in the variable
4380 by that name and the return value is a count of the number of characters
4381 read (not including the newline).</p></div>
4382 <div class="paragraph
"><p>If the end of the file is reached before reading
4383 any characters then -1 is returned and <code><em>varName</em></code> is set to an
4384 empty string.</p></div>
4385 <div class="paragraph
"><p>If <code><em>varName</em></code> is not specified then the return value will be
4386 the line (minus the newline character) or an empty string if
4387 the end of the file is reached before reading any characters.</p></div>
4388 <div class="paragraph
"><p>An empty string will also be returned if a line contains no characters
4389 except the newline, so <a href="#_eof
"><strong><code>eof</code></strong></a> may have to be used to determine
4390 what really happened.</p></div>
4391 <div class="paragraph
"><p>If the last character in the file is not a newline character, then
4392 <a href="#_gets
"><strong><code>gets</code></strong></a> behaves as if there were an additional newline character
4393 at the end of the file.</p></div>
4394 <div class="paragraph
"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous
4395 call to <a href="#_open
"><strong><code>open</code></strong></a>; it must refer to a file that was opened
4396 for reading.</p></div>
4399 <h3 id="_glob
">glob</h3>
4400 <div class="paragraph
"><p><code><strong>glob</strong> ?<strong>-nocomplain</strong>? ?<strong>-directory</strong> <em>dir</em>? ?<strong>-tails</strong>? ?<strong>--</strong>? <em>pattern ?pattern ...?</em></code></p></div>
4401 <div class="paragraph
"><p>This command performs filename globbing, using csh rules. The returned
4402 value from <a href="#_glob
"><strong><code>glob</code></strong></a> is the list of expanded filenames.</p></div>
4403 <div class="paragraph
"><p>If <code>-nocomplain</code> is specified as the first argument then an empty
4404 list may be returned; otherwise an error is returned if the expanded
4405 list is empty. The <code>-nocomplain</code> argument must be provided
4406 exactly: an abbreviation will not be accepted.</p></div>
4407 <div class="paragraph
"><p>If <code>-directory</code> is given, the <code><em>dir</em></code> is understood to contain a
4408 directory name to search in. This allows globbing inside directories
4409 whose names may contain glob-sensitive characters. The returned names
4410 include the directory name unless <code><em>-tails</em></code> is specified.</p></div>
4411 <div class="paragraph
"><p>If <code><em>-tails</em></code> is specified, along with <code>-directory</code>, the returned names
4412 are relative to the given directory.</p></div>
4415 <h3 id="_global
">global</h3>
4416 <div class="paragraph
"><p><code><strong>global</strong> <em>varName ?varName ...?</em></code></p></div>
4417 <div class="paragraph
"><p>This command is ignored unless a Tcl procedure is being interpreted.
4418 If so, then it declares each given <code><em>varName</em></code> to be a global variable
4419 rather than a local one. For the duration of the current procedure
4420 (and only while executing in the current procedure), any reference to
4421 <code><em>varName</em></code> will be bound to a global variable instead
4422 of a local one.</p></div>
4423 <div class="paragraph
"><p>An alternative to using <a href="#_global
"><strong><code>global</code></strong></a> is to use the <code>::</code> prefix
4424 to explicitly name a variable in the global scope.</p></div>
4427 <h3 id="_if
">if</h3>
4428 <div class="paragraph
"><p><code><strong>if</strong> <em>expr1</em> ?<strong>then</strong>? <em>body1</em> <strong>elseif</strong> <em>expr2</em> ?<strong>then</strong>? <em>body2</em> <strong>elseif</strong> ... ?<strong>else</strong>? ?<em>bodyN</em>?</code></p></div>
4429 <div class="paragraph
"><p>The <a href="#_if
"><strong><code>if</code></strong></a> command evaluates <code><em>expr1</em></code> as an expression (in the same way
4430 that <a href="#_expr
"><strong><code>expr</code></strong></a> evaluates its argument). The value of the expression must
4431 be numeric; if it is non-zero then <code><em>body1</em></code> is executed by passing it to
4432 the Tcl interpreter.</p></div>
4433 <div class="paragraph
"><p>Otherwise <code><em>expr2</em></code> is evaluated as an expression and if it is non-zero
4434 then <code><em>body2</em></code> is executed, and so on.</p></div>
4435 <div class="paragraph
"><p>If none of the expressions evaluates to non-zero then <code><em>bodyN</em></code> is executed.</p></div>
4436 <div class="paragraph
"><p>The <code>then</code> and <code>else</code> arguments are optional "noise words
" to make the
4437 command easier to read.</p></div>
4438 <div class="paragraph
"><p>There may be any number of <code>elseif</code> clauses, including zero. <code><em>bodyN</em></code>
4439 may also be omitted as long as <code>else</code> is omitted too.</p></div>
4440 <div class="paragraph
"><p>The return value from the command is the result of the body script that
4441 was executed, or an empty string if none of the expressions was non-zero
4442 and there was no <code><em>bodyN</em></code>.</p></div>
4445 <h3 id="_incr
">incr</h3>
4446 <div class="paragraph
"><p><code><strong>incr</strong> <em>varName ?increment?</em></code></p></div>
4447 <div class="paragraph
"><p>Increment the value stored in the variable whose name is <code><em>varName</em></code>.
4448 The value of the variable must be integral.</p></div>
4449 <div class="paragraph
"><p>If <code><em>increment</em></code> is supplied then its value (which must be an
4450 integer) is added to the value of variable <code><em>varName</em></code>; otherwise
4451 1 is added to <code><em>varName</em></code>.</p></div>
4452 <div class="paragraph
"><p>The new value is stored as a decimal string in variable <code><em>varName</em></code>
4453 and also returned as result.</p></div>
4454 <div class="paragraph
"><p>If the variable does not exist, the variable is implicitly created
4455 and set to <code>0</code> first.</p></div>
4458 <h3 id="_info
">info</h3>
4459 <div class="dlist
"><dl>
4460 <dt class="hdlist1
">
4461 <code><strong>info</strong> <em>option ?arg...?</em></code>
4465 Provide information about various internals to the Tcl interpreter.
4466 The legal <code><em>option</em></code>'s (which may be abbreviated) are:
4469 <dt class="hdlist1
">
4470 <code><strong>info args</strong> <em>procname</em></code>
4474 Returns a list containing the names of the arguments to procedure
4475 <code><em>procname</em></code>, in order. <code><em>procname</em></code> must be the name of a
4476 Tcl command procedure.
4479 <dt class="hdlist1
">
4480 <code><strong>info alias</strong> <em>command</em></code>
4484 <code><em>command</em></code> must be an alias created with <a href="#_alias
"><strong><code>alias</code></strong></a>. In which case the target
4485 command and arguments, as passed to <a href="#_alias
"><strong><code>alias</code></strong></a> are returned. See <a href="#_exists
"><strong><code>exists</code></strong></a> <code>-alias</code>
4488 <dt class="hdlist1
">
4489 <code><strong>info body</strong> <em>procname</em></code>
4493 Returns the body of procedure <code><em>procname</em></code>. <code><em>procname</em></code> must be
4494 the name of a Tcl command procedure.
4497 <dt class="hdlist1
">
4498 <code><strong>info channels</strong></code>
4502 Returns a list of all open file handles from <a href="#_open
"><strong><code>open</code></strong></a> or <a href="#_socket
"><strong><code>socket</code></strong></a>
4505 <dt class="hdlist1
">
4506 <code><strong>info commands</strong> ?<em>pattern</em>?</code>
4510 If <code><em>pattern</em></code> isn’t specified, returns a list of names of all the
4511 Tcl commands, including both the built-in commands written in C and
4512 the command procedures defined using the <a href="#_proc
"><strong><code>proc</code></strong></a> command.
4513 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4514 are returned. Matching is determined using the same rules as for
4515 <a href="#_string
"><strong><code>string</code></strong></a> <code>match</code>.
4518 <dt class="hdlist1
">
4519 <code><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</code>
4523 Returns 1 if <code><em>command</em></code> is a complete Tcl command in the sense of
4524 having no unclosed quotes, braces, brackets or array element names,
4525 If the command doesn’t appear to be complete then 0 is returned.
4526 This command is typically used in line-oriented input environments
4527 to allow users to type in commands that span multiple lines; if the
4528 command isn’t complete, the script can delay evaluating it until additional
4529 lines have been typed to complete the command. If <code><em>varName</em></code> is specified, the
4530 missing character is stored in the variable with that name.
4533 <dt class="hdlist1
">
4534 <code><strong>info exists</strong> <em>varName</em></code>
4538 Returns <em>1</em> if the variable named <code><em>varName</em></code> exists in the
4539 current context (either as a global or local variable), returns <em>0</em>
4543 <dt class="hdlist1
">
4544 <code><strong>info frame</strong> ?<em>number</em>?</code>
4548 If <code><em>number</em></code> is not specified, this command returns a number
4549 which is the same result as <a href="#_info
"><strong><code>info</code></strong></a> <code>level</code> - the current stack frame level.
4550 If <code><em>number</em></code> is specified, then the result is a list consisting of the procedure,
4551 filename and line number for the procedure call at level <code><em>number</em></code> on the stack.
4552 If <code><em>number</em></code> is positive then it selects a particular stack level (1 refers
4553 to the top-most active procedure, 2 to the procedure it called, and
4554 so on); otherwise it gives a level relative to the current level
4555 (0 refers to the current procedure, -1 to its caller, and so on).
4556 The level has an identical meaning to <a href="#_info
"><strong><code>info</code></strong></a> <code>level</code>.
4559 <dt class="hdlist1
">
4560 <code><strong>info globals</strong> ?<em>pattern</em>?</code>
4564 If <code><em>pattern</em></code> isn’t specified, returns a list of all the names
4565 of currently-defined global variables.
4566 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4567 are returned. Matching is determined using the same rules as for
4568 <a href="#_string
"><strong><code>string</code></strong></a> <code>match</code>.
4571 <dt class="hdlist1
">
4572 <code><strong>info hostname</strong></code>
4576 An alias for <a href="#cmd_1
"><strong><code>os.gethostname</code></strong></a> for compatibility with Tcl 6.x
4579 <dt class="hdlist1
">
4580 <code><strong>info level</strong> ?<em>number</em>?</code>
4584 If <code><em>number</em></code> is not specified, this command returns a number
4585 giving the stack level of the invoking procedure, or 0 if the
4586 command is invoked at top-level. If <code><em>number</em></code> is specified,
4587 then the result is a list consisting of the name and arguments for the
4588 procedure call at level <code><em>number</em></code> on the stack. If <code><em>number</em></code>
4589 is positive then it selects a particular stack level (1 refers
4590 to the top-most active procedure, 2 to the procedure it called, and
4591 so on); otherwise it gives a level relative to the current level
4592 (0 refers to the current procedure, -1 to its caller, and so on).
4593 See the <a href="#_uplevel
"><strong><code>uplevel</code></strong></a> command for more information on what stack
4597 <dt class="hdlist1
">
4598 <code><strong>info locals</strong> ?<em>pattern</em>?</code>
4602 If <code><em>pattern</em></code> isn’t specified, returns a list of all the names
4603 of currently-defined local variables, including arguments to the
4604 current procedure, if any. Variables defined with the <a href="#_global
"><strong><code>global</code></strong></a>
4605 and <a href="#_upvar
"><strong><code>upvar</code></strong></a> commands will not be returned. If <code><em>pattern</em></code> is
4606 specified, only those names matching <code><em>pattern</em></code> are returned.
4607 Matching is determined using the same rules as for <a href="#_string
"><strong><code>string</code></strong></a> <code>match</code>.
4610 <dt class="hdlist1
">
4611 <code><strong>info nameofexecutable</strong></code>
4615 Returns the name of the binary file from which the application
4616 was invoked. A full path will be returned, unless the path
4617 can’t be determined, in which case the empty string will be returned.
4620 <dt class="hdlist1
">
4621 <code><strong>info procs</strong> ?<em>pattern</em>?</code>
4625 If <code><em>pattern</em></code> isn’t specified, returns a list of all the
4626 names of Tcl command procedures.
4627 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4628 are returned. Matching is determined using the same rules as for
4629 <a href="#_string
"><strong><code>string</code></strong></a> <code>match</code>.
4632 <dt class="hdlist1
">
4633 <code><strong>info references</strong></code>
4637 Returns a list of all references which have not yet been garbage
4641 <dt class="hdlist1
">
4642 <code><strong>info returncodes</strong> ?<em>code</em>?</code>
4646 Returns a list representing the mapping of standard return codes
4647 to names. e.g. <code>{0 ok 1 error 2 return ...}</code>. If a code is given,
4648 instead returns the name for the given code.
4651 <dt class="hdlist1
">
4652 <code><strong>info script</strong></code>
4656 If a Tcl script file is currently being evaluated (i.e. there is a
4657 call to <em>Jim_EvalFile</em> active or there is an active invocation
4658 of the <a href="#_source
"><strong><code>source</code></strong></a> command), then this command returns the name
4659 of the innermost file being processed. Otherwise the command returns an
4663 <dt class="hdlist1
">
4664 <code><strong>info source</strong> <em>script ?filename line?</em></code>
4668 With a single argument, returns the original source location of the given script as a list of
4669 <code>{filename linenumber}</code>. If the source location can’t be determined, the
4670 list <code>{{} 0}</code> is returned. If <code><em>filename</em></code> and <code><em>line</em></code> are given, returns a copy
4671 of <code><em>script</em></code> with the associate source information. This can be useful to produce
4672 useful messages from <a href="#_eval
"><strong><code>eval</code></strong></a>, etc. if the original source information may be lost.
4675 <dt class="hdlist1
">
4676 <code><strong>info stacktrace</strong></code>
4680 After an error is caught with <a href="#_catch
"><strong><code>catch</code></strong></a>, returns the stack trace as a list
4681 of <code>{procedure filename line ...}</code>.
4684 <dt class="hdlist1
">
4685 <code><strong>info statics</strong> <em>procname</em></code>
4689 Returns a dictionary of the static variables of procedure
4690 <code><em>procname</em></code>. <code><em>procname</em></code> must be the name of a Tcl command
4691 procedure. An empty dictionary is returned if the procedure has
4692 no static variables.
4695 <dt class="hdlist1
">
4696 <code><strong>info version</strong></code>
4700 Returns the version number for this version of Jim in the form <code><strong>x.yy</strong></code>.
4703 <dt class="hdlist1
">
4704 <code><strong>info vars</strong> ?<em>pattern</em>?</code>
4708 If <code><em>pattern</em></code> isn’t specified,
4709 returns a list of all the names of currently-visible variables, including
4710 both locals and currently-visible globals.
4711 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4712 are returned. Matching is determined using the same rules as for
4713 <a href="#_string
"><strong><code>string</code></strong></a> <code>match</code>.
4719 <h3 id="_join
">join</h3>
4720 <div class="paragraph
"><p><code><strong>join</strong> <em>list ?joinString?</em></code></p></div>
4721 <div class="paragraph
"><p>The <code><em>list</em></code> argument must be a valid Tcl list. This command returns the
4722 string formed by joining all of the elements of <code><em>list</em></code> together with
4723 <code><em>joinString</em></code> separating each adjacent pair of elements.</p></div>
4724 <div class="paragraph
"><p>The <code><em>joinString</em></code> argument defaults to a space character.</p></div>
4727 <h3 id="_kill
">kill</h3>
4728 <div class="paragraph
"><p><code><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></code></p></div>
4729 <div class="paragraph
"><p>Sends the given signal to the process identified by <code><em>pid</em></code>.</p></div>
4730 <div class="paragraph
"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4731 <div class="ulist
"><ul>
4739 <code>SIGTERM</code>
4758 <div class="paragraph
"><p>The signal name may be in either upper or lower case.</p></div>
4759 <div class="paragraph
"><p>The special signal name <code>-0</code> simply checks that a signal <code><em>could</em></code> be sent.</p></div>
4760 <div class="paragraph
"><p>If no signal is specified, SIGTERM is used.</p></div>
4761 <div class="paragraph
"><p>An error is raised if the signal could not be delivered.</p></div>
4764 <h3 id="_lambda
">lambda</h3>
4765 <div class="paragraph
"><p><code><strong>lambda</strong> <em>args ?statics? body</em></code></p></div>
4766 <div class="paragraph
"><p>The <a href="#_lambda
"><strong><code>lambda</code></strong></a> command is identical to <a href="#_proc
"><strong><code>proc</code></strong></a>, except rather than
4767 creating a named procedure, it creates an anonymous procedure and returns
4768 the name of the procedure.</p></div>
4769 <div class="paragraph
"><p>See <a href="#_proc
"><strong><code>proc</code></strong></a> and <a href="#_garbage_collection_references_lambda_function
">GARBAGE COLLECTION</a> for more detail.</p></div>
4772 <h3 id="_lappend
">lappend</h3>
4773 <div class="paragraph
"><p><code><strong>lappend</strong> <em>varName value ?value value ...?</em></code></p></div>
4774 <div class="paragraph
"><p>Treat the variable given by <code><em>varName</em></code> as a list and append each of
4775 the <code><em>value</em></code> arguments to that list as a separate element, with spaces
4776 between elements.</p></div>
4777 <div class="paragraph
"><p>If <code><em>varName</em></code> doesn’t exist, it is created as a list with elements given
4778 by the <code><em>value</em></code> arguments. <a href="#_lappend
"><strong><code>lappend</code></strong></a> is similar to <a href="#_append
"><strong><code>append</code></strong></a> except that
4779 each <code><em>value</em></code> is appended as a list element rather than raw text.</p></div>
4780 <div class="paragraph
"><p>This command provides a relatively efficient way to build up large lists.
4781 For example,</p></div>
4782 <div class="listingblock
">
4783 <div class="content
">
4784 <pre><code> lappend a $b</code></pre>
4786 <div class="paragraph
"><p>is much more efficient than</p></div>
4787 <div class="listingblock
">
4788 <div class="content
">
4789 <pre><code> set a [concat $a [list $b]]</code></pre>
4791 <div class="paragraph
"><p>when <code>$a</code> is long.</p></div>
4794 <h3 id="_lassign
">lassign</h3>
4795 <div class="paragraph
"><p><code><strong>lassign</strong> <em>list varName ?varName ...?</em></code></p></div>
4796 <div class="paragraph
"><p>This command treats the value <code><em>list</em></code> as a list and assigns successive elements from that list to
4797 the variables given by the <code><em>varName</em></code> arguments in order. If there are more variable names than
4798 list elements, the remaining variables are set to the empty string. If there are more list elements
4799 than variables, a list of unassigned elements is returned.</p></div>
4800 <div class="listingblock
">
4801 <div class="content
">
4802 <pre><code> . lassign {1 2 3} a b; puts a=$a,b=$b
4804 a=1,b=2</code></pre>
4808 <h3 id="_local
">local</h3>
4809 <div class="paragraph
"><p><code><strong>local</strong> <em>cmd ?arg...?</em></code></p></div>
4810 <div class="paragraph
"><p>First, <a href="#_local
"><strong><code>local</code></strong></a> evaluates <code><em>cmd</em></code> with the given arguments. The return value must
4811 be the name of an existing command, which is marked as having local scope.
4812 This means that when the current procedure exits, the specified
4813 command is deleted. This can be useful with <a href="#_lambda
"><strong><code>lambda</code></strong></a>, local procedures or
4814 to automatically close a filehandle.</p></div>
4815 <div class="paragraph
"><p>In addition, if a command already exists with the same name,
4816 the existing command will be kept rather than deleted, and may be called
4817 via <a href="#_upcall
"><strong><code>upcall</code></strong></a>. The previous command will be restored when the current
4818 procedure exits. See <a href="#_upcall
"><strong><code>upcall</code></strong></a> for more details.</p></div>
4819 <div class="paragraph
"><p>In this example, a local procedure is created. Note that the procedure
4820 continues to have global scope while it is active.</p></div>
4821 <div class="listingblock
">
4822 <div class="content
">
4823 <pre><code> proc outer {} {
4824 # proc ... returns "inner
" which is marked local
4825 local proc inner {} {
4826 # will be deleted when 'outer' exits
4833 <div class="paragraph
"><p>In this example, the lambda is deleted at the end of the procedure rather
4834 than waiting until garbage collection.</p></div>
4835 <div class="listingblock
">
4836 <div class="content
">
4837 <pre><code> proc outer {} {
4838 set x [lambda inner {args} {
4839 # will be deleted when 'outer' exits
4841 # Use 'function' here which simply returns $x
4850 <h3 id="_loop
">loop</h3>
4851 <div class="paragraph
"><p><code><strong>loop</strong> <em>var first limit ?incr? body</em></code></p></div>
4852 <div class="paragraph
"><p>Similar to <a href="#_for
"><strong><code>for</code></strong></a> except simpler and possibly more efficient.
4853 With a positive increment, equivalent to:</p></div>
4854 <div class="listingblock
">
4855 <div class="content
">
4856 <pre><code> for {set var $first} {$var < $limit} {incr var $incr} $body</code></pre>
4858 <div class="paragraph
"><p>If <code><em>incr</em></code> is not specified, 1 is used.
4859 Note that setting the loop variable inside the loop does not
4860 affect the loop count.</p></div>
4863 <h3 id="_lindex
">lindex</h3>
4864 <div class="paragraph
"><p><code><strong>lindex</strong> <em>list ?index …?</em></code></p></div>
4865 <div class="paragraph
"><p>Treats <code><em>list</em></code> as a Tcl list and returns element <code><em>index</em></code> from it
4866 (0 refers to the first element of the list).
4867 See <a href="#_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</a> for all allowed forms for <code><em>index</em></code>.</p></div>
4868 <div class="paragraph
"><p>In extracting the element, <code><em>lindex</em></code> observes the same rules concerning
4869 braces and quotes and backslashes as the Tcl command interpreter; however,
4870 variable substitution and command substitution do not occur.</p></div>
4871 <div class="paragraph
"><p>If no index values are given, simply returns <code><em>list</em></code></p></div>
4872 <div class="paragraph
"><p>If <code><em>index</em></code> is negative or greater than or equal to the number of elements
4873 in <code><em>list</em></code>, then an empty string is returned.</p></div>
4874 <div class="paragraph
"><p>If additional index arguments are supplied, then each argument is
4875 used in turn to select an element from the previous indexing
4876 operation, allowing the script to select elements from sublists.</p></div>
4879 <h3 id="_linsert
">linsert</h3>
4880 <div class="paragraph
"><p><code><strong>linsert</strong> <em>list index element ?element element ...?</em></code></p></div>
4881 <div class="paragraph
"><p>This command produces a new list from <code><em>list</em></code> by inserting all
4882 of the <code><em>element</em></code> arguments just before the element <code><em>index</em></code>
4883 of <code><em>list</em></code>. Each <code><em>element</em></code> argument will become
4884 a separate element of the new list. If <code><em>index</em></code> is less than
4885 or equal to zero, then the new elements are inserted at the
4886 beginning of the list. If <code><em>index</em></code> is greater than or equal
4887 to the number of elements in the list, then the new elements are
4888 appended to the list.</p></div>
4889 <div class="paragraph
"><p>See <a href="#_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</a> for all allowed forms for <code><em>index</em></code>.</p></div>
4892 <h3 id="_list
">list</h3>
4893 <div class="paragraph
"><p><code><strong>list</strong> <em>arg ?arg ...?</em></code></p></div>
4894 <div class="paragraph
"><p>This command returns a list comprised of all the arguments, <code><em>arg</em></code>. Braces
4895 and backslashes get added as necessary, so that the <a href="#_lindex
"><strong><code>lindex</code></strong></a> command
4896 may be used on the result to re-extract the original arguments, and also
4897 so that <a href="#_eval
"><strong><code>eval</code></strong></a> may be used to execute the resulting list, with
4898 <code><em>arg1</em></code> comprising the command’s name and the other args comprising
4899 its arguments. <a href="#_list
"><strong><code>list</code></strong></a> produces slightly different results than
4900 <a href="#_concat
"><strong><code>concat</code></strong></a>: <a href="#_concat
"><strong><code>concat</code></strong></a> removes one level of grouping before forming
4901 the list, while <a href="#_list
"><strong><code>list</code></strong></a> works directly from the original arguments.
4902 For example, the command</p></div>
4903 <div class="listingblock
">
4904 <div class="content
">
4905 <pre><code> list a b {c d e} {f {g h}}</code></pre>
4907 <div class="paragraph
"><p>will return</p></div>
4908 <div class="listingblock
">
4909 <div class="content
">
4910 <pre><code> a b {c d e} {f {g h}}</code></pre>
4912 <div class="paragraph
"><p>while <a href="#_concat
"><strong><code>concat</code></strong></a> with the same arguments will return</p></div>
4913 <div class="listingblock
">
4914 <div class="content
">
4915 <pre><code> a b c d e f {g h}</code></pre>
4919 <h3 id="_llength
">llength</h3>
4920 <div class="paragraph
"><p><code><strong>llength</strong> <em>list</em></code></p></div>
4921 <div class="paragraph
"><p>Treats <code><em>list</em></code> as a list and returns a decimal string giving
4922 the number of elements in it.</p></div>
4925 <h3 id="_lset
">lset</h3>
4926 <div class="paragraph
"><p><code><strong>lset</strong> <em>varName ?index ..? newValue</em></code></p></div>
4927 <div class="paragraph
"><p>Sets an element in a list.</p></div>
4928 <div class="paragraph
"><p>The <a href="#_lset
"><strong><code>lset</code></strong></a> command accepts a parameter, <code><em>varName</em></code>, which it interprets
4929 as the name of a variable containing a Tcl list. It also accepts
4930 zero or more indices into the list. Finally, it accepts a new value
4931 for an element of varName. If no indices are presented, the command
4932 takes the form:</p></div>
4933 <div class="listingblock
">
4934 <div class="content
">
4935 <pre><code> lset varName newValue</code></pre>
4937 <div class="paragraph
"><p>In this case, newValue replaces the old value of the variable
4939 <div class="paragraph
"><p>When presented with a single index, the <a href="#_lset
"><strong><code>lset</code></strong></a> command
4940 treats the content of the varName variable as a Tcl list. It addresses
4941 the index’th element in it (0 refers to the first element of the
4942 list). When interpreting the list, <a href="#_lset
"><strong><code>lset</code></strong></a> observes the same rules
4943 concerning braces and quotes and backslashes as the Tcl command
4944 interpreter; however, variable substitution and command substitution
4945 do not occur. The command constructs a new list in which the
4946 designated element is replaced with newValue. This new list is
4947 stored in the variable varName, and is also the return value from
4948 the <a href="#_lset
"><strong><code>lset</code></strong></a> command.</p></div>
4949 <div class="paragraph
"><p>If index is negative or greater than or equal to the number of
4950 elements in $varName, then an error occurs.</p></div>
4951 <div class="paragraph
"><p>See <a href="#_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</a> for all allowed forms for <code><em>index</em></code>.</p></div>
4952 <div class="paragraph
"><p>If additional index arguments are supplied, then each argument is
4953 used in turn to address an element within a sublist designated by
4954 the previous indexing operation, allowing the script to alter
4955 elements in sublists. The command,</p></div>
4956 <div class="listingblock
">
4957 <div class="content
">
4958 <pre><code> lset a 1 2 newValue</code></pre>
4960 <div class="paragraph
"><p>replaces element 2 of sublist 1 with <code><em>newValue</em></code>.</p></div>
4961 <div class="paragraph
"><p>The integer appearing in each index argument must be greater than
4962 or equal to zero. The integer appearing in each index argument must
4963 be strictly less than the length of the corresponding list. In other
4964 words, the <a href="#_lset
"><strong><code>lset</code></strong></a> command cannot change the size of a list. If an
4965 index is outside the permitted range, an error is reported.</p></div>
4968 <h3 id="_lmap
">lmap</h3>
4969 <div class="paragraph
"><p><code><strong>lmap</strong> <em>varName list body</em></code></p></div>
4970 <div class="paragraph
"><p><code><strong>lmap</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
4971 <div class="paragraph
"><p><a href="#_lmap
"><strong><code>lmap</code></strong></a> is a "collecting
" <a href="#_foreach
"><strong><code>foreach</code></strong></a> which returns a list of its results.</p></div>
4972 <div class="paragraph
"><p>For example:</p></div>
4973 <div class="listingblock
">
4974 <div class="content
">
4975 <pre><code> . lmap i {1 2 3 4 5} {expr $i*$i}
4977 . lmap a {1 2 3} b {A B C} {list $a $b}
4978 {1 A} {2 B} {3 C}</code></pre>
4980 <div class="paragraph
"><p>If the body invokes <a href="#_continue
"><strong><code>continue</code></strong></a>, no value is added for this iteration.
4981 If the body invokes <a href="#_break
"><strong><code>break</code></strong></a>, the loop ends and no more values are added.</p></div>
4984 <h3 id="_load
">load</h3>
4985 <div class="paragraph
"><p><code><strong>load</strong> <em>filename</em></code></p></div>
4986 <div class="paragraph
"><p>Loads the dynamic extension, <code><em>filename</em></code>. Generally the filename should have
4987 the extension <code>.so</code>. The initialisation function for the module must be based
4988 on the name of the file. For example loading <code>hwaccess.so</code> will invoke
4989 the initialisation function, <code>Jim_hwaccessInit</code>. Normally the <a href="#_load
"><strong><code>load</code></strong></a> command
4990 should not be used directly. Instead it is invoked automatically by <a href="#_package
"><strong><code>package</code></strong></a> <code>require</code>.</p></div>
4993 <h3 id="_lrange
">lrange</h3>
4994 <div class="paragraph
"><p><code><strong>lrange</strong> <em>list first last</em></code></p></div>
4995 <div class="paragraph
"><p><code><em>list</em></code> must be a valid Tcl list. This command will return a new
4996 list consisting of elements <code><em>first</em></code> through <code><em>last</em></code>, inclusive.</p></div>
4997 <div class="paragraph
"><p>See <a href="#_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</a> for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.</p></div>
4998 <div class="paragraph
"><p>If <code><em>last</em></code> is greater than or equal to the number of elements
4999 in the list, then it is treated as if it were <code>end</code>.</p></div>
5000 <div class="paragraph
"><p>If <code><em>first</em></code> is greater than <code><em>last</em></code> then an empty string
5001 is returned.</p></div>
5002 <div class="paragraph
"><p>Note: <code>"<a href=
"#_lrange"><strong><code>lrange
</code></strong></a> <em>list first first
</em>"</code> does not always produce the
5003 same result as <code>"<a href=
"#_lindex"><strong><code>lindex
</code></strong></a> <em>list first
</em>"</code> (although it often does
5004 for simple fields that aren’t enclosed in braces); it does, however,
5005 produce exactly the same results as <code>"<a href=
"#_list"><strong><code>list
</code></strong></a> [
<a href=
"#_lindex"><strong><code>lindex
</code></strong></a> <em>list first
</em>]
"</code></p></div>
5008 <h3 id="_lreplace
">lreplace</h3>
5009 <div class="paragraph
"><p><code><strong>lreplace</strong> <em>list first last ?element element ...?</em></code></p></div>
5010 <div class="paragraph
"><p>Returns a new list formed by replacing one or more elements of
5011 <code><em>list</em></code> with the <code><em>element</em></code> arguments.</p></div>
5012 <div class="paragraph
"><p><code><em>first</em></code> gives the index in <code><em>list</em></code> of the first element
5013 to be replaced.</p></div>
5014 <div class="paragraph
"><p>If <code><em>first</em></code> is less than zero then it refers to the first
5015 element of <code><em>list</em></code>; the element indicated by <code><em>first</em></code>
5016 must exist in the list.</p></div>
5017 <div class="paragraph
"><p><code><em>last</em></code> gives the index in <code><em>list</em></code> of the last element
5018 to be replaced; it must be greater than or equal to <code><em>first</em></code>.</p></div>
5019 <div class="paragraph
"><p>See <a href="#_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</a> for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.</p></div>
5020 <div class="paragraph
"><p>The <code><em>element</em></code> arguments specify zero or more new arguments to
5021 be added to the list in place of those that were deleted.</p></div>
5022 <div class="paragraph
"><p>Each <code><em>element</em></code> argument will become a separate element of
5024 <div class="paragraph
"><p>If no <code><em>element</em></code> arguments are specified, then the elements
5025 between <code><em>first</em></code> and <code><em>last</em></code> are simply deleted.</p></div>
5028 <h3 id="_lrepeat
">lrepeat</h3>
5029 <div class="paragraph
"><p><code><strong>lrepeat</strong> <em>number element1 ?element2 ...?</em></code></p></div>
5030 <div class="paragraph
"><p>Build a list by repeating elements <code><em>number</em></code> times (which must be
5031 a positive integer).</p></div>
5032 <div class="listingblock
">
5033 <div class="content
">
5034 <pre><code> . lrepeat 3 a b
5035 a b a b a b</code></pre>
5039 <h3 id="_lreverse
">lreverse</h3>
5040 <div class="paragraph
"><p><code><strong>lreverse</strong> <em>list</em></code></p></div>
5041 <div class="paragraph
"><p>Returns the list in reverse order.</p></div>
5042 <div class="listingblock
">
5043 <div class="content
">
5044 <pre><code> . lreverse {1 2 3}
5049 <h3 id="_lsearch
">lsearch</h3>
5050 <div class="paragraph
"><p><code><strong>lsearch</strong> <em>?options? list pattern</em></code></p></div>
5051 <div class="paragraph
"><p>This command searches the elements <code><em>list</em></code> to see if one of them matches <code><em>pattern</em></code>. If so, the
5052 command returns the index of the first matching element (unless the options <code>-all</code>, <code>-inline</code> or <code>-bool</code> are
5053 specified.) If not, the command returns -1. The option arguments indicates how the elements of
5054 the list are to be matched against pattern and must have one of the values below:</p></div>
5055 <div class="paragraph
"><p><strong>Note</strong> that this command is different from Tcl in that default match type is <code>-exact</code> rather than <code>-glob</code>.</p></div>
5056 <div class="dlist
"><dl>
5057 <dt class="hdlist1
">
5058 <code><strong>-exact</strong></code>
5062 <code><em>pattern</em></code> is a literal string that is compared for exact equality against each list element.
5063 This is the default.
5066 <dt class="hdlist1
">
5067 <code><strong>-glob</strong></code>
5071 <code><em>pattern</em></code> is a glob-style pattern which is matched against each list element using the same
5072 rules as the string match command.
5075 <dt class="hdlist1
">
5076 <code><strong>-regexp</strong></code>
5080 <code><em>pattern</em></code> is treated as a regular expression and matched against each list element using
5081 the rules described by <a href="#_regexp
"><strong><code>regexp</code></strong></a>.
5084 <dt class="hdlist1
">
5085 <code><strong>-command</strong> <em>cmdname</em></code>
5089 <code><em>cmdname</em></code> is a command which is used to match the pattern against each element of the
5090 list. It is invoked as <code><em>cmdname</em> ?<strong>-nocase</strong>? <em>pattern listvalue</em></code> and should return 1
5091 for a match, or 0 for no match.
5094 <dt class="hdlist1
">
5095 <code><strong>-all</strong></code>
5099 Changes the result to be the list of all matching indices (or all matching values if
5100 <code>-inline</code> is specified as well). If indices are returned, the indices will be in numeric
5101 order. If values are returned, the order of the values will be the order of those values
5102 within the input list.
5105 <dt class="hdlist1
">
5106 <code><strong>-inline</strong></code>
5110 The matching value is returned instead of its index (or an empty string if no value
5111 matches). If <code>-all</code> is also specified, then the result of the command is the list of all
5112 values that matched. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5115 <dt class="hdlist1
">
5116 <code><strong>-bool</strong></code>
5120 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <code>-all</code> is also specified,
5121 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
5122 the corresponding element matches. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5125 <dt class="hdlist1
">
5126 <code><strong>-not</strong></code>
5130 This negates the sense of the match, returning the index (or value
5131 if <code>-inline</code> is specified) of the first non-matching value in the
5132 list. If <code>-bool</code> is also specified, the <em>0</em> will be returned if a
5133 match is found, or <em>1</em> otherwise. If <code>-all</code> is also specified,
5134 non-matches will be returned rather than matches.
5137 <dt class="hdlist1
">
5138 <code><strong>-nocase</strong></code>
5142 Causes comparisons to be handled in a case-insensitive manner.
5148 <h3 id="_lsort
">lsort</h3>
5149 <div class="paragraph
"><p><code><strong>lsort</strong> ?<strong>-index</strong> <em>listindex</em>? ?<strong>-nocase|-integer|-real|-command</strong> <em>cmdname</em>? ?<strong>-unique</strong>? ?<strong>-decreasing</strong>|<strong>-increasing</strong>? <em>list</em></code></p></div>
5150 <div class="paragraph
"><p>Sort the elements of <code><em>list</em></code>, returning a new list in sorted order.
5151 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.</p></div>
5152 <div class="paragraph
"><p>If <code>-nocase</code> is specified, comparisons are case-insensitive.</p></div>
5153 <div class="paragraph
"><p>If <code>-integer</code> is specified, numeric sorting is used.</p></div>
5154 <div class="paragraph
"><p>If <code>-real</code> is specified, floating point number sorting is used.</p></div>
5155 <div class="paragraph
"><p>If <code>-command <em>cmdname</em></code> is specified, <code><em>cmdname</em></code> is treated as a command
5156 name. For each comparison, <code><em>cmdname $value1 $value2</code></em> is called which
5157 should compare the values and return an integer less than, equal
5158 to, or greater than zero if the <code><em>$value1</em></code> is to be considered less
5159 than, equal to, or greater than <code><em>$value2</em></code>, respectively.</p></div>
5160 <div class="paragraph
"><p>If <code>-decreasing</code> is specified, the resulting list is in the opposite
5161 order to what it would be otherwise. <code>-increasing</code> is the default.</p></div>
5162 <div class="paragraph
"><p>If <code>-unique</code> is specified, then only the last set of duplicate elements found in the list will be retained.
5163 Note that duplicates are determined relative to the comparison used in the sort. Thus if <code>-index 0</code> is used,
5164 <code>{1 a}</code> and <code>{1 b}</code> would be considered duplicates and only the second element, <code>{1 b}</code>, would be retained.</p></div>
5165 <div class="paragraph
"><p>If <code>-index <em>listindex</em></code> is specified, each element of the list is treated as a list and
5166 the given index is extracted from the list for comparison. The list index may
5167 be any valid list index, such as <code>1</code>, <code>end</code> or <code>end-2</code>.</p></div>
5170 <h3 id="_defer
">defer</h3>
5171 <div class="paragraph
"><p><code><strong>defer</strong> <em>script</em></code></p></div>
5172 <div class="paragraph
"><p>This command is a simple helper command to add a script to the <em><code>$jim::defer</code></em> variable
5173 that will run when the current proc or interpreter exits. For example:</p></div>
5174 <div class="listingblock
">
5175 <div class="content
">
5176 <pre><code> . proc a {} { defer {puts "Leaving a
"}; puts "Exit
" }
5179 Leaving a</code></pre>
5181 <div class="paragraph
"><p>If the <em><code>$jim::defer</code></em> variable exists, it is treated as a list of scripts to run
5182 when the proc or interpreter exits.</p></div>
5185 <h3 id="_open
">open</h3>
5186 <div class="paragraph
"><p><code><strong>open</strong> <em>fileName ?access?</em></code></p></div>
5187 <div class="paragraph
"><p><code><strong>open</strong> <em>|command-pipeline ?access?</em></code></p></div>
5188 <div class="paragraph
"><p>Opens a file and returns an identifier
5189 that may be used in future invocations
5190 of commands like <a href="#_read
"><strong><code>read</code></strong></a>, <a href="#_puts
"><strong><code>puts</code></strong></a>, and <a href="#_close
"><strong><code>close</code></strong></a>.
5191 <code><em>fileName</em></code> gives the name of the file to open.</p></div>
5192 <div class="paragraph
"><p>The <code><em>access</em></code> argument indicates the way in which the file is to be accessed.
5193 It may have any of the following values:</p></div>
5194 <div class="dlist
"><dl>
5195 <dt class="hdlist1
">
5200 Open the file for reading only; the file must already exist.
5203 <dt class="hdlist1
">
5208 Open the file for both reading and writing; the file must
5212 <dt class="hdlist1
">
5217 Open the file for writing only. Truncate it if it exists. If it doesn’t
5218 exist, create a new file.
5221 <dt class="hdlist1
">
5226 Open the file for reading and writing. Truncate it if it exists.
5227 If it doesn’t exist, create a new file.
5230 <dt class="hdlist1
">
5235 Open the file for writing only. The file must already exist, and the file
5236 is positioned so that new data is appended to the file.
5239 <dt class="hdlist1
">
5244 Open the file for reading and writing. If the file doesn’t
5245 exist, create a new empty file. Set the initial access position
5246 to the end of the file.
5250 <div class="paragraph
"><p><code><em>access</em></code> defaults to <em>r</em>.</p></div>
5251 <div class="paragraph
"><p>If a file is opened for both reading and writing, then <a href="#_seek
"><strong><code>seek</code></strong></a>
5252 must be invoked between a read and a write, or vice versa.</p></div>
5253 <div class="paragraph
"><p>If the first character of <code><em>fileName</em></code> is "|
" then the remaining
5254 characters of <code><em>fileName</em></code> are treated as a list of arguments that
5255 describe a command pipeline to invoke, in the same style as the
5256 arguments for exec. In this case, the channel identifier returned
5257 by open may be used to write to the command’s input pipe or read
5258 from its output pipe, depending on the value of <code><em>access</em></code>. If write-only
5259 access is used (e.g. <code><em>access</em></code> is <em>w</em>), then standard output for the
5260 pipeline is directed to the current standard output unless overridden
5261 by the command. If read-only access is used (e.g. <code><em>access</em></code> is r),
5262 standard input for the pipeline is taken from the current standard
5263 input unless overridden by the command.</p></div>
5264 <div class="paragraph
"><p>The <a href="#_pid
"><strong><code>pid</code></strong></a> command may be used to return the process ids of the commands
5265 forming the command pipeline.</p></div>
5266 <div class="paragraph
"><p>See also <a href="#_socket
"><strong><code>socket</code></strong></a>, <a href="#_pid
"><strong><code>pid</code></strong></a>, <a href="#_exec
"><strong><code>exec</code></strong></a></p></div>
5269 <h3 id="_package
">package</h3>
5270 <div class="paragraph
"><p><code><strong>package provide</strong> <em>name ?version?</em></code></p></div>
5271 <div class="paragraph
"><p>Indicates that the current script provides the package named <code><em>name</em></code>.
5272 If no version is specified, <em>1.0</em> is used.</p></div>
5273 <div class="paragraph
"><p>Any script which provides a package may include this statement
5274 as the first statement, although it is not required.</p></div>
5275 <div class="paragraph
"><p><code><strong>package require</strong> <em>name ?version?</em>*</code></p></div>
5276 <div class="paragraph
"><p>Searches for the package with the given <code><em>name</em></code> by examining each path
5277 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
5278 or <em>$path/$name.tcl</em> as a script package.</p></div>
5279 <div class="paragraph
"><p>The first such file which is found is considered to provide the package.
5280 (The version number is ignored).</p></div>
5281 <div class="paragraph
"><p>If <em>$name.so</em> exists, it is loaded with the <a href="#_load
"><strong><code>load</code></strong></a> command,
5282 otherwise if <em>$name.tcl</em> exists it is loaded with the <a href="#_source
"><strong><code>source</code></strong></a> command.</p></div>
5283 <div class="paragraph
"><p>If <a href="#_load
"><strong><code>load</code></strong></a> or <a href="#_source
"><strong><code>source</code></strong></a> fails, <a href="#_package
"><strong><code>package</code></strong></a> <code>require</code> will fail immediately.
5284 No further attempt will be made to locate the file.</p></div>
5287 <h3 id="_pid
">pid</h3>
5288 <div class="paragraph
"><p><code><strong>pid</strong></code></p></div>
5289 <div class="paragraph
"><p><code><strong>pid</strong> <em>fileId</em></code></p></div>
5290 <div class="paragraph
"><p>The first form returns the process identifier of the current process.</p></div>
5291 <div class="paragraph
"><p>The second form accepts a handle returned by <a href="#_open
"><strong><code>open</code></strong></a> and returns a list
5292 of the process ids forming the pipeline in the same form as <a href="#_exec
"><strong><code>exec</code></strong></a> <code>... &</code>.
5293 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
5294 the empty string is returned instead.</p></div>
5295 <div class="paragraph
"><p>See also <a href="#_open
"><strong><code>open</code></strong></a>, <a href="#_exec
"><strong><code>exec</code></strong></a></p></div>
5298 <h3 id="_proc
">proc</h3>
5299 <div class="paragraph
"><p><code><strong>proc</strong> <em>name args ?statics? body</em></code></p></div>
5300 <div class="paragraph
"><p>The <a href="#_proc
"><strong><code>proc</code></strong></a> command creates a new Tcl command procedure, <code><em>name</em></code>.
5301 When the new command is invoked, the contents of <code><em>body</em></code> will be executed.
5302 Tcl interpreter. <code><em>args</em></code> specifies the formal arguments to the procedure.
5303 If specified, <code><em>statics</em></code>, declares static variables which are bound to the
5304 procedure.</p></div>
5305 <div class="paragraph
"><p>See <<_procedures,PROCEDURES> for detailed information about Tcl procedures.</p></div>
5306 <div class="paragraph
"><p>The <a href="#_proc
"><strong><code>proc</code></strong></a> command returns <code><em>name</em></code> (which is useful with <a href="#_local
"><strong><code>local</code></strong></a>).</p></div>
5307 <div class="paragraph
"><p>When a procedure is invoked, the procedure’s return value is the
5308 value specified in a <a href="#_return
"><strong><code>return</code></strong></a> command. If the procedure doesn’t
5309 execute an explicit <a href="#_return
"><strong><code>return</code></strong></a>, then its return value is the value
5310 of the last command executed in the procedure’s body.</p></div>
5311 <div class="paragraph
"><p>If an error occurs while executing the procedure body, then the
5312 procedure-as-a-whole will return that same error.</p></div>
5315 <h3 id="_puts
">puts</h3>
5316 <div class="paragraph
"><p><code><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></code></p></div>
5317 <div class="paragraph
"><p><code><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></code></p></div>
5318 <div class="paragraph
"><p>Writes the characters given by <code><em>string</em></code> to the file given
5319 by <code><em>fileId</em></code>. <code><em>fileId</em></code> must have been the return
5320 value from a previous call to <a href="#_open
"><strong><code>open</code></strong></a>, or it may be
5321 <code>stdout</code> or <code>stderr</code> to refer to one of the standard I/O
5322 channels; it must refer to a file that was opened for
5324 <div class="paragraph
"><p>In the first form, if no <code><em>fileId</em></code> is specified then it defaults to <code>stdout</code>.
5325 <a href="#_puts
"><strong><code>puts</code></strong></a> normally outputs a newline character after <code><em>string</em></code>,
5326 but this feature may be suppressed by specifying the <code>-nonewline</code>
5328 <div class="paragraph
"><p>Output to files is buffered internally by Tcl; the <a href="#_flush
"><strong><code>flush</code></strong></a>
5329 command may be used to force buffered characters to be output.</p></div>
5332 <h3 id="_pipe
">pipe</h3>
5333 <div class="paragraph
"><p>Creates a pair of <a href="#_aio
"><strong><code>aio</code></strong></a> channels and returns the handles as a list: <code>{read write}</code></p></div>
5334 <div class="listingblock
">
5335 <div class="content
">
5336 <pre><code> lassign [pipe] r w
5338 # Must close $w after exec
5339 exec ps >@$w &
5342 $r readable ...</code></pre>
5346 <h3 id="_pwd
">pwd</h3>
5347 <div class="paragraph
"><p><code><strong>pwd</strong></code></p></div>
5348 <div class="paragraph
"><p>Returns the path name of the current working directory.</p></div>
5351 <h3 id="_rand
">rand</h3>
5352 <div class="paragraph
"><p><code><strong>rand</strong> <em>?min? ?max?</em></code></p></div>
5353 <div class="paragraph
"><p>Returns a random integer between <code><em>min</em></code> (defaults to 0) and <code><em>max</em></code>
5354 (defaults to the maximum integer).</p></div>
5355 <div class="paragraph
"><p>If only one argument is given, it is interpreted as <code><em>max</em></code>.</p></div>
5358 <h3 id="_range
">range</h3>
5359 <div class="paragraph
"><p><code><strong>range</strong> <em>?start? end ?step?</em></code></p></div>
5360 <div class="paragraph
"><p>Returns a list of integers starting at <code><em>start</em></code> (defaults to 0)
5361 and ranging up to but not including <code><em>end</em></code> in steps of <code><em>step</em></code> defaults to 1).</p></div>
5362 <div class="listingblock
">
5363 <div class="content
">
5364 <pre><code> . range 5
5375 <h3 id="_read
">read</h3>
5376 <div class="paragraph
"><p><code><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></code></p></div>
5377 <div class="paragraph
"><p><code><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</code></p></div>
5378 <div class="paragraph
"><p><code><strong>read</strong> <em>fileId numBytes</em></code></p></div>
5379 <div class="paragraph
"><p><code><em>fileId</em> <strong>read</strong> <em>numBytes</em></code></p></div>
5380 <div class="paragraph
"><p>In the first form, all of the remaining bytes are read from the file
5381 given by <code><em>fileId</em></code>; they are returned as the result of the command.
5382 If the <code>-nonewline</code> switch is specified then the last
5383 character of the file is discarded if it is a newline.</p></div>
5384 <div class="paragraph
"><p>In the second form, the extra argument specifies how many bytes to read;
5385 exactly this many bytes will be read and returned, unless there are fewer than
5386 <code><em>numBytes</em></code> bytes left in the file; in this case, all the remaining
5387 bytes are returned.</p></div>
5388 <div class="paragraph
"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous call
5389 to <a href="#_open
"><strong><code>open</code></strong></a>; it must refer to a file that was opened for reading.</p></div>
5392 <h3 id="_regexp
">regexp</h3>
5393 <div class="paragraph
"><p><code><strong>regexp ?-nocase? ?-line? ?-indices? ?-start</strong> <em>offset</em>? <strong>?-all? ?-inline? ?--?</strong> <em>exp string ?matchVar? ?subMatchVar subMatchVar ...?</em></code></p></div>
5394 <div class="paragraph
"><p>Determines whether the regular expression <code><em>exp</em></code> matches part or
5395 all of <code><em>string</em></code> and returns 1 if it does, 0 if it doesn’t.</p></div>
5396 <div class="paragraph
"><p>See <a href="#_regular_expressions
">REGULAR EXPRESSIONS</a> above for complete information on the
5397 syntax of <code><em>exp</em></code> and how it is matched against <code><em>string</em></code>.</p></div>
5398 <div class="paragraph
"><p>If additional arguments are specified after <code><em>string</em></code> then they
5399 are treated as the names of variables to use to return
5400 information about which part(s) of <code><em>string</em></code> matched <code><em>exp</em></code>.
5401 <code><em>matchVar</em></code> will be set to the range of <code><em>string</em></code> that
5402 matched all of <code><em>exp</em></code>. The first <code><em>subMatchVar</em></code> will contain
5403 the characters in <code><em>string</em></code> that matched the leftmost parenthesized
5404 subexpression within <code><em>exp</em></code>, the next <code><em>subMatchVar</em></code> will
5405 contain the characters that matched the next parenthesized
5406 subexpression to the right in <code><em>exp</em></code>, and so on.</p></div>
5407 <div class="paragraph
"><p>Normally, <code><em>matchVar</em></code> and the each <code><em>subMatchVar</em></code> are set to hold the
5408 matching characters from <a href="#_string
"><strong><code>string</code></strong></a>, however see <code>-indices</code> and
5409 <code>-inline</code> below.</p></div>
5410 <div class="paragraph
"><p>If there are more values for <code><em>subMatchVar</em></code> than parenthesized subexpressions
5411 within <code><em>exp</em></code>, or if a particular subexpression in <code><em>exp</em></code> doesn’t
5412 match the string (e.g. because it was in a portion of the expression
5413 that wasn’t matched), then the corresponding <code><em>subMatchVar</em></code> will be
5414 set to <code>"-
1 -
1"</code> if <code>-indices</code> has been specified or to an empty
5415 string otherwise.</p></div>
5416 <div class="paragraph
"><p>The following switches modify the behaviour of <code><em>regexp</em></code></p></div>
5417 <div class="dlist
"><dl>
5418 <dt class="hdlist1
">
5419 <code><strong>-nocase</strong></code>
5423 Causes upper-case and lower-case characters to be treated as
5424 identical during the matching process.
5427 <dt class="hdlist1
">
5428 <code><strong>-line</strong></code>
5432 Use newline-sensitive matching. By default, newline
5433 is a completely ordinary character with no special meaning in
5434 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5435 and <code>.</code> never match newline, an <code></sup></code> anchor matches the null
5436 string after any newline in the string in addition to its normal
5437 function, and the <code>$</code> anchor matches the null string before any
5438 newline in the string in addition to its normal function.
5441 <dt class="hdlist1
">
5442 <code><strong>-indices</strong></code>
5446 Changes what is stored in the subMatchVars. Instead of
5447 storing the matching characters from string, each variable
5448 will contain a list of two decimal strings giving the indices
5449 in string of the first and last characters in the matching
5450 range of characters.
5453 <dt class="hdlist1
">
5454 <code><strong>-start</strong> <em>offset</em></code>
5458 Specifies a character index offset into the string at which to start
5459 matching the regular expression. If <code>-indices</code> is
5460 specified, the indices will be indexed starting from the
5461 absolute beginning of the input string. <code><em>offset</em></code> will be
5462 constrained to the bounds of the input string.
5465 <dt class="hdlist1
">
5466 <code><strong>-all</strong></code>
5470 Causes the regular expression to be matched as many times as possible
5471 in the string, returning the total number of matches found. If this
5472 is specified with match variables, they will contain information
5473 for the last match only.
5476 <dt class="hdlist1
">
5477 <code><strong>-inline</strong></code>
5481 Causes the command to return, as a list, the data that would otherwise
5482 be placed in match variables. When using <code>-inline</code>, match variables
5483 may not be specified. If used with <code>-all</code>, the list will be concatenated
5484 at each iteration, such that a flat list is always returned. For
5485 each match iteration, the command will append the overall match
5486 data, plus one element for each subexpression in the regular
5490 <dt class="hdlist1
">
5491 <code><strong>--</strong></code>
5495 Marks the end of switches. The argument following this one will be
5496 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5502 <h3 id="_regsub
">regsub</h3>
5503 <div class="paragraph
"><p><code><strong>regsub ?-nocase? ?-all? ?-line? ?-start</strong> <em>offset</em>? ?<strong>--</strong>? <em>exp string subSpec ?varName?</em></code></p></div>
5504 <div class="paragraph
"><p>This command matches the regular expression <code><em>exp</em></code> against
5505 <code><em>string</em></code> using the rules described in REGULAR EXPRESSIONS
5507 <div class="paragraph
"><p>If <code><em>varName</em></code> is specified, the commands stores <code><em>string</em></code> to <code><em>varName</em></code>
5508 with the substitutions detailed below, and returns the number of
5509 substitutions made (normally 1 unless <code>-all</code> is specified).
5510 This is 0 if there were no matches.</p></div>
5511 <div class="paragraph
"><p>If <code><em>varName</em></code> is not specified, the substituted string will be returned
5513 <div class="paragraph
"><p>When copying <code><em>string</em></code>, the portion of <code><em>string</em></code> that
5514 matched <code><em>exp</em></code> is replaced with <code><em>subSpec</em></code>.
5515 If <code><em>subSpec</em></code> contains a <code>&</code> or <code>\0</code>, then it is replaced
5516 in the substitution with the portion of <code><em>string</em></code> that
5517 matched <code><em>exp</em></code>.</p></div>
5518 <div class="paragraph
"><p>If <code><em>subSpec</em></code> contains a <code>\n</code>, where <code><em>n</em></code> is a digit
5519 between 1 and 9, then it is replaced in the substitution with
5520 the portion of <code><em>string</em></code> that matched the <code><em>n</em></code>'-th
5521 parenthesized subexpression of <code><em>exp</em></code>.
5522 Additional backslashes may be used in <code><em>subSpec</em></code> to prevent special
5523 interpretation of <code>&</code> or <code>\0</code> or <code>\n</code> or
5524 backslash.</p></div>
5525 <div class="paragraph
"><p>The use of backslashes in <code><em>subSpec</em></code> tends to interact badly
5526 with the Tcl parser’s use of backslashes, so it’s generally
5527 safest to enclose <code><em>subSpec</em></code> in braces if it includes
5528 backslashes.</p></div>
5529 <div class="paragraph
"><p>The following switches modify the behaviour of <code><em>regsub</em></code></p></div>
5530 <div class="dlist
"><dl>
5531 <dt class="hdlist1
">
5532 <code><strong>-nocase</strong></code>
5536 Upper-case characters in <code><em>string</em></code> are converted to lower-case
5537 before matching against <code><em>exp</em></code>; however, substitutions
5538 specified by <code><em>subSpec</em></code> use the original unconverted form
5539 of <code><em>string</em></code>.
5542 <dt class="hdlist1
">
5543 <code><strong>-all</strong></code>
5547 All ranges in <code><em>string</em></code> that match <code><em>exp</em></code> are found and substitution
5548 is performed for each of these ranges, rather than only the
5549 first. The <code>&</code> and <code>\n</code> sequences are handled for
5550 each substitution using the information from the corresponding
5554 <dt class="hdlist1
">
5555 <code><strong>-line</strong></code>
5559 Use newline-sensitive matching. By default, newline
5560 is a completely ordinary character with no special meaning in
5561 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5562 and <code>.</code> never match newline, an <code></sup></code> anchor matches the null
5563 string after any newline in the string in addition to its normal
5564 function, and the <code>$</code> anchor matches the null string before any
5565 newline in the string in addition to its normal function.
5568 <dt class="hdlist1
">
5569 <code><strong>-start</strong> <em>offset</em></code>
5573 Specifies a character index offset into the string at which to
5574 start matching the regular expression. <code><em>offset</em></code> will be
5575 constrained to the bounds of the input string.
5578 <dt class="hdlist1
">
5579 <code><strong>--</strong></code>
5583 Marks the end of switches. The argument following this one will be
5584 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5590 <h3 id="_ref
">ref</h3>
5591 <div class="paragraph
"><p><code><strong>ref</strong> <em>string tag ?finalizer?</em></code></p></div>
5592 <div class="paragraph
"><p>Create a new reference containing <code><em>string</em></code> of type <code><em>tag</em></code>.
5593 If <code><em>finalizer</em></code> is specified, it is a command which will be invoked
5594 when the a garbage collection cycle runs and this reference is
5595 no longer accessible.</p></div>
5596 <div class="paragraph
"><p>The finalizer is invoked as:</p></div>
5597 <div class="listingblock
">
5598 <div class="content
">
5599 <pre><code> finalizer reference string</code></pre>
5601 <div class="paragraph
"><p>See <a href="#_garbage_collection_references_lambda_function
">GARBAGE COLLECTION</a> for more detail.</p></div>
5604 <h3 id="_rename
">rename</h3>
5605 <div class="paragraph
"><p><code><strong>rename</strong> <em>oldName newName</em></code></p></div>
5606 <div class="paragraph
"><p>Rename the command that used to be called <code><em>oldName</em></code> so that it
5607 is now called <code><em>newName</em></code>. If <code><em>newName</em></code> is an empty string
5608 (e.g. {}) then <code><em>oldName</em></code> is deleted. The <a href="#_rename
"><strong><code>rename</code></strong></a> command
5609 returns an empty string as result.</p></div>
5612 <h3 id="_return
">return</h3>
5613 <div class="paragraph
"><p><code><strong>return</strong> ?<strong>-code</strong> <em>code</em>? ?<strong>-errorinfo</strong> <em>stacktrace</em>? ?<strong>-errorcode</strong> <em>errorcode</em>? ?<strong>-level</strong> <em>n</em>? ?<em>value</em>?</code></p></div>
5614 <div class="paragraph
"><p>Return immediately from the current procedure (or top-level command
5615 or <a href="#_source
"><strong><code>source</code></strong></a> command), with <code><em>value</em></code> as the return value. If <code><em>value</em></code>
5616 is not specified, an empty string will be returned as result.</p></div>
5617 <div class="paragraph
"><p>If <code>-code</code> is specified (as either a number or ok, error, break,
5618 continue, signal, return or exit), this code will be used instead
5619 of <code>JIM_OK</code>. This is generally useful when implementing flow of control
5621 <div class="paragraph
"><p>If <code>-level</code> is specified and greater than 1, it has the effect of delaying
5622 the new return code from <code>-code</code>. This is useful when rethrowing an error
5623 from <a href="#_catch
"><strong><code>catch</code></strong></a>. See the implementation of try/catch in tclcompat.tcl for
5624 an example of how this is done.</p></div>
5625 <div class="paragraph
"><p>Note: The following options are only used when <code>-code</code> is JIM_ERR.</p></div>
5626 <div class="paragraph
"><p>If <code>-errorinfo</code> is specified (as returned from <a href="#_info
"><strong><code>info</code></strong></a> <code>stacktrace</code>)
5627 it is used to initialize the stacktrace.</p></div>
5628 <div class="paragraph
"><p>If <code>-errorcode</code> is specified, it is used to set the global variable $::errorCode.</p></div>
5631 <h3 id="_scan
">scan</h3>
5632 <div class="paragraph
"><p><code><strong>scan</strong> <em>string format varName1 ?varName2 ...?</em></code></p></div>
5633 <div class="paragraph
"><p>This command parses fields from an input string in the same fashion
5634 as the C <em>sscanf</em> procedure. <code><em>string</em></code> gives the input to be parsed
5635 and <code><em>format</em></code> indicates how to parse it, using <em>%</em> fields as in
5636 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5637 man page for details. Each <code><em>varName</em></code> gives the name of a variable;
5638 when a field is scanned from <code><em>string</em></code>, the result is converted back
5639 into a string and assigned to the corresponding <code><em>varName</em></code>. The
5640 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5641 character value is converted to a decimal string, which is then
5642 assigned to the corresponding <code><em>varName</em></code>; no field width may be
5643 specified for this conversion.</p></div>
5646 <h3 id="_seek
">seek</h3>
5647 <div class="paragraph
"><p><code><strong>seek</strong> <em>fileId offset ?origin?</em></code></p></div>
5648 <div class="paragraph
"><p><code><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></code></p></div>
5649 <div class="paragraph
"><p>Change the current access position for <code><em>fileId</em></code>.
5650 The <code><em>offset</em></code> and <code><em>origin</em></code> arguments specify the position at
5651 which the next read or write will occur for <code><em>fileId</em></code>.
5652 <code><em>offset</em></code> must be a number (which may be negative) and <code><em>origin</em></code>
5653 must be one of the following:</p></div>
5654 <div class="dlist
"><dl>
5655 <dt class="hdlist1
">
5656 <code><strong>start</strong></code>
5660 The new access position will be <code><em>offset</em></code> bytes from the start
5664 <dt class="hdlist1
">
5665 <code><strong>current</strong></code>
5669 The new access position will be <code><em>offset</em></code> bytes from the current
5670 access position; a negative <code><em>offset</em></code> moves the access position
5671 backwards in the file.
5674 <dt class="hdlist1
">
5675 <code><strong>end</strong></code>
5679 The new access position will be <code><em>offset</em></code> bytes from the end of
5680 the file. A negative <code><em>offset</em></code> places the access position before
5681 the end-of-file, and a positive <code><em>offset</em></code> places the access position
5682 after the end-of-file.
5686 <div class="paragraph
"><p>The <code><em>origin</em></code> argument defaults to <code>start</code>.</p></div>
5687 <div class="paragraph
"><p><code><em>fileId</em></code> must have been the return value from a previous call to
5688 <a href="#_open
"><strong><code>open</code></strong></a>, or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one
5689 of the standard I/O channels.</p></div>
5690 <div class="paragraph
"><p>This command returns an empty string.</p></div>
5693 <h3 id="_set
">set</h3>
5694 <div class="paragraph
"><p><code><strong>set</strong> <em>varName ?value?</em></code></p></div>
5695 <div class="paragraph
"><p>Returns the value of variable <code><em>varName</em></code>.</p></div>
5696 <div class="paragraph
"><p>If <code><em>value</em></code> is specified, then set the value of <code><em>varName</em></code> to <code><em>value</em></code>,
5697 creating a new variable if one doesn’t already exist, and return
5698 its value.</p></div>
5699 <div class="paragraph
"><p>If <code><em>varName</em></code> contains an open parenthesis and ends with a
5700 close parenthesis, then it refers to an array element: the characters
5701 before the open parenthesis are the name of the array, and the characters
5702 between the parentheses are the index within the array.
5703 Otherwise <code><em>varName</em></code> refers to a scalar variable.</p></div>
5704 <div class="paragraph
"><p>If no procedure is active, then <code><em>varName</em></code> refers to a global
5706 <div class="paragraph
"><p>If a procedure is active, then <code><em>varName</em></code> refers to a parameter
5707 or local variable of the procedure, unless the <code><em>global</em></code> command
5708 has been invoked to declare <code><em>varName</em></code> to be global.</p></div>
5709 <div class="paragraph
"><p>The <code>::</code> prefix may also be used to explicitly reference a variable
5710 in the global scope.</p></div>
5713 <h3 id="_setref
">setref</h3>
5714 <div class="paragraph
"><p><code><strong>setref</strong> <em>reference string</em></code></p></div>
5715 <div class="paragraph
"><p>Store a new string in <code><em>reference</em></code>, replacing the existing string.
5716 The reference must be a valid reference create with the <a href="#_ref
"><strong><code>ref</code></strong></a>
5718 <div class="paragraph
"><p>See <a href="#_garbage_collection_references_lambda_function
">GARBAGE COLLECTION</a> for more detail.</p></div>
5721 <h3 id="_signal
">signal</h3>
5722 <div class="paragraph
"><p>Command for signal handling.</p></div>
5723 <div class="paragraph
"><p>See <a href="#_kill
"><strong><code>kill</code></strong></a> for the different forms which may be used to specify signals.</p></div>
5724 <div class="paragraph
"><p>Commands which return a list of signal names do so using the canonical form:
5725 "<code>SIGINT SIGTERM
</code>".</p></div>
5726 <div class="dlist
"><dl>
5727 <dt class="hdlist1
">
5728 <code><strong>signal handle</strong> ?<em>signals ...</em>?</code>
5732 If no signals are given, returns a list of all signals which are currently
5734 If signals are specified, these are added to the list of signals currently
5738 <dt class="hdlist1
">
5739 <code><strong>signal ignore</strong> ?<em>signals ...</em>?</code>
5743 If no signals are given, returns a lists all signals which are currently
5745 If signals are specified, these are added to the list of signals
5746 currently being ignored. These signals are still delivered, but
5747 are not considered by <a href="#_catch
"><strong><code>catch</code></strong></a> <code>-signal</code> or <a href="#_try
"><strong><code>try</code></strong></a> <code>-signal</code>. Use
5748 <a href="#_signal
"><strong><code>signal</code></strong></a> <code>check</code> to determine which signals have occurred but
5752 <dt class="hdlist1
">
5753 <code><strong>signal block</strong> ?<em>signals ...</em>?</code>
5757 If no signals are given, returns a lists all signals which are currently
5759 If signals are specified, these are added to the list of signals
5760 currently being blocked. These signals are not delivered to the process.
5761 This can be useful for signals such as <code>SIGPIPE</code>, especially in conjunction
5762 with <a href="#_exec
"><strong><code>exec</code></strong></a> as child processes inherit the parent’s signal disposition.
5765 <dt class="hdlist1
">
5766 <code><strong>signal default</strong> ?<em>signals ...</em>?</code>
5770 If no signals are given, returns a lists all signals which currently have
5771 the default behaviour.
5772 If signals are specified, these are added to the list of signals which have
5773 the default behaviour.
5776 <dt class="hdlist1
">
5777 <code><strong>signal check ?-clear?</strong> ?<em>signals ...</em>?</code>
5781 Returns a list of signals which have been delivered to the process
5782 but are <em>ignored</em>. If signals are specified, only that set of signals will
5783 be checked, otherwise all signals will be checked.
5784 If <code>-clear</code> is specified, any signals returned are removed and will not be
5785 returned by subsequent calls to <a href="#_signal
"><strong><code>signal</code></strong></a> <code>check</code> unless delivered again.
5788 <dt class="hdlist1
">
5789 <code><strong>signal throw</strong> ?<em>signal</em>?</code>
5793 Raises the given signal, which defaults to <code>SIGINT</code> if not specified.
5794 The behaviour is identical to:
5798 <div class="listingblock
">
5799 <div class="content
">
5800 <pre><code> kill signal [pid]</code></pre>
5802 <div class="paragraph
"><p>Note that <a href="#_signal
"><strong><code>signal</code></strong></a> <code>handle</code> and <a href="#_signal
"><strong><code>signal</code></strong></a> <code>ignore</code> represent two forms of signal
5803 handling. <a href="#_signal
"><strong><code>signal</code></strong></a> <code>handle</code> is used in conjunction with <a href="#_catch
"><strong><code>catch</code></strong></a> <code>-signal</code> or <a href="#_try
"><strong><code>try</code></strong></a> <code>-signal</code>
5804 to immediately abort execution when the signal is delivered. Alternatively, <a href="#_signal
"><strong><code>signal</code></strong></a> <code>ignore</code>
5805 is used in conjunction with <a href="#_signal
"><strong><code>signal</code></strong></a> <code>check</code> to handle signal synchronously. Consider the
5806 two examples below.</p></div>
5807 <div class="paragraph
"><p>Prevent a processing from taking too long</p></div>
5808 <div class="listingblock
">
5809 <div class="content
">
5810 <pre><code> signal handle SIGALRM
5813 .. possibly long running process ..
5816 puts stderr "Process took too long
"
5819 <div class="paragraph
"><p>Handle SIGHUP to reconfigure:</p></div>
5820 <div class="listingblock
">
5821 <div class="content
">
5822 <pre><code> signal ignore SIGHUP
5824 ... handle configuration/reconfiguration ...
5825 while {[signal check -clear SIGHUP] eq ""} {
5826 ... do processing ..
5828 # Received SIGHUP, so reconfigure
5831 <div class="paragraph
"><p>Note: signal handling is currently not supported in child interpreters.
5832 In these interpreters, the signal command does not exist.</p></div>
5835 <h3 id="_sleep
">sleep</h3>
5836 <div class="paragraph
"><p><code><strong>sleep</strong> <em>seconds</em></code></p></div>
5837 <div class="paragraph
"><p>Pauses for the given number of seconds, which may be a floating
5838 point value less than one to sleep for less than a second, or an
5839 integer to sleep for one or more seconds.</p></div>
5842 <h3 id="_source
">source</h3>
5843 <div class="paragraph
"><p><code><strong>source</strong> <em>fileName</em></code></p></div>
5844 <div class="paragraph
"><p>Read file <code><em>fileName</em></code> and pass the contents to the Tcl interpreter
5845 as a sequence of commands to execute in the normal fashion. The return
5846 value of <a href="#_source
"><strong><code>source</code></strong></a> is the return value of the last command executed
5847 from the file. If an error occurs in executing the contents of the
5848 file, then the <a href="#_source
"><strong><code>source</code></strong></a> command will return that error.</p></div>
5849 <div class="paragraph
"><p>If a <a href="#_return
"><strong><code>return</code></strong></a> command is invoked from within the file, the remainder of
5850 the file will be skipped and the <a href="#_source
"><strong><code>source</code></strong></a> command will return
5851 normally with the result from the <a href="#_return
"><strong><code>return</code></strong></a> command.</p></div>
5854 <h3 id="_split
">split</h3>
5855 <div class="paragraph
"><p><code><strong>split</strong> <em>string ?splitChars?</em></code></p></div>
5856 <div class="paragraph
"><p>Returns a list created by splitting <code><em>string</em></code> at each character
5857 that is in the <code><em>splitChars</em></code> argument.</p></div>
5858 <div class="paragraph
"><p>Each element of the result list will consist of the
5859 characters from <code><em>string</em></code> between instances of the
5860 characters in <code><em>splitChars</em></code>.</p></div>
5861 <div class="paragraph
"><p>Empty list elements will be generated if <code><em>string</em></code> contains
5862 adjacent characters in <code><em>splitChars</em></code>, or if the first or last
5863 character of <code><em>string</em></code> is in <code><em>splitChars</em></code>.</p></div>
5864 <div class="paragraph
"><p>If <code><em>splitChars</em></code> is an empty string then each character of
5865 <code><em>string</em></code> becomes a separate element of the result list.</p></div>
5866 <div class="paragraph
"><p><code><em>splitChars</em></code> defaults to the standard white-space characters.
5867 For example,</p></div>
5868 <div class="listingblock
">
5869 <div class="content
">
5870 <pre><code> split "comp.unix.misc
" .</code></pre>
5872 <div class="paragraph
"><p>returns <code><em>"comp unix misc
"</em></code> and</p></div>
5873 <div class="listingblock
">
5874 <div class="content
">
5875 <pre><code> split "Hello world
" {}</code></pre>
5877 <div class="paragraph
"><p>returns <code><em>"H e l l o { } w o r l d
"</em></code>.</p></div>
5880 <h3 id="_stackdump
">stackdump</h3>
5881 <div class="paragraph
"><p><code><strong>stackdump</strong> <em>stacktrace</em></code></p></div>
5882 <div class="paragraph
"><p>Creates a human readable representation of a stack trace.</p></div>
5885 <h3 id="_stacktrace
">stacktrace</h3>
5886 <div class="paragraph
"><p><code><strong>stacktrace</strong></code></p></div>
5887 <div class="paragraph
"><p>Returns a live stack trace as a list of <code>proc file line proc file line ...</code>.
5888 Iteratively uses <a href="#_info
"><strong><code>info</code></strong></a> <code>frame</code> to create the stack trace. This stack trace is in the
5889 same form as produced by <a href="#_catch
"><strong><code>catch</code></strong></a> and <a href="#_info
"><strong><code>info</code></strong></a> <code>stacktrace</code></p></div>
5890 <div class="paragraph
"><p>See also <a href="#_stackdump
"><strong><code>stackdump</code></strong></a>.</p></div>
5893 <h3 id="_string
">string</h3>
5894 <div class="paragraph
"><p><code><strong>string</strong> <em>option arg ?arg ...?</em></code></p></div>
5895 <div class="paragraph
"><p>Perform one of several string operations, depending on <code><em>option</em></code>.
5896 The legal options (which may be abbreviated) are:</p></div>
5897 <div class="dlist
"><dl>
5898 <dt class="hdlist1
">
5899 <code><strong>string bytelength</strong> <em>string</em></code>
5903 Returns the length of the string in bytes. This will return
5904 the same value as <a href="#_string
"><strong><code>string</code></strong></a> <code>length</code> if UTF-8 support is not enabled,
5905 or if the string is composed entirely of ASCII characters.
5906 See <a href="#_utf_8_and_unicode
">UTF-8 AND UNICODE</a>.
5909 <dt class="hdlist1
">
5910 <code><strong>string byterange</strong> <em>string first last</em></code>
5914 Like <a href="#_string
"><strong><code>string</code></strong></a> <code>range</code> except works on bytes rather than characters.
5915 These commands are identical if UTF-8 support is not enabled.
5918 <dt class="hdlist1
">
5919 <code><strong>string cat</strong> <em>?string1 string2 ...?</em></code>
5923 Concatenates the given strings into a single string.
5926 <dt class="hdlist1
">
5927 <code><strong>string compare ?-nocase?</strong> ?<strong>-length</strong> <em>len? string1 string2</em></code>
5931 Perform a character-by-character comparison of strings <code><em>string1</em></code> and
5932 <code><em>string2</em></code> in the same way as the C <em>strcmp</em> procedure. Return
5933 -1, 0, or 1, depending on whether <code><em>string1</em></code> is lexicographically
5934 less than, equal to, or greater than <code><em>string2</em></code>. If <code>-length</code>
5935 is specified, then only the first <code><em>len</em></code> characters are used
5936 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5937 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5940 <dt class="hdlist1
">
5941 <code><strong>string equal ?-nocase?</strong> <em>?<strong>-length</strong> len?</em> <em>string1 string2</em></code>
5945 Returns 1 if the strings are equal, or 0 otherwise. If <code>-length</code>
5946 is specified, then only the first <code><em>len</em></code> characters are used
5947 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5948 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5951 <dt class="hdlist1
">
5952 <code><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></code>
5956 Search <code><em>string2</em></code> for a sequence of characters that exactly match
5957 the characters in <code><em>string1</em></code>. If found, return the index of the
5958 first character in the first such match within <code><em>string2</em></code>. If not
5959 found, return -1. If <code><em>firstIndex</em></code> is specified, matching will start
5960 from <code><em>firstIndex</em></code> of <code><em>string1</em></code>.
5963 <dt class="hdlist1
">
5968 See <a href="#_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</a> for all allowed forms for <code><em>firstIndex</em></code>.
5971 <dt class="hdlist1
">
5972 <code><strong>string index</strong> <em>string charIndex</em></code>
5976 Returns the <code><em>charIndex</em></code><em>th character of the <code>'string</em></code>
5977 argument. A <code><em>charIndex</em></code> of 0 corresponds to the first
5978 character of the string.
5979 If <code><em>charIndex</em></code> is less than 0 or greater than
5980 or equal to the length of the string then an empty string is
5984 <dt class="hdlist1
">
5989 See <a href="#_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</a> for all allowed forms for <code><em>charIndex</em></code>.
5992 <dt class="hdlist1
">
5993 <code><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></code>
5997 Returns 1 if <code><em>string</em></code> is a valid member of the specified character
5998 class, otherwise returns 0. If <code>-strict</code> is specified, then an
5999 empty string returns 0, otherwise an empty string will return 1
6000 on any class. The following character classes are recognized
6001 (the class name can be abbreviated):
6004 <dt class="hdlist1
">
6008 <div class="dlist
"><dl>
6009 <dt class="hdlist1
">
6014 Any alphabet or digit character.
6017 <dt class="hdlist1
">
6022 Any alphabet character.
6025 <dt class="hdlist1
">
6030 Any character with a value less than 128 (those that are in the 7-bit ascii range).
6033 <dt class="hdlist1
">
6034 <code>boolean</code>
6038 Any of the valid string formats for a boolean value in Tcl (0, false, no, off, 1, true, yes, on)
6041 <dt class="hdlist1
">
6042 <code>control</code>
6046 Any control character.
6049 <dt class="hdlist1
">
6054 Any digit character.
6057 <dt class="hdlist1
">
6062 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
6063 In case of under/overflow in the value, 0 is returned.
6066 <dt class="hdlist1
">
6071 Any printing character, except space.
6074 <dt class="hdlist1
">
6075 <code>integer</code>
6079 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
6082 <dt class="hdlist1
">
6087 Any lower case alphabet character.
6090 <dt class="hdlist1
">
6095 Any printing character, including space.
6098 <dt class="hdlist1
">
6103 Any punctuation character.
6106 <dt class="hdlist1
">
6111 Any space character.
6114 <dt class="hdlist1
">
6119 Any upper case alphabet character.
6122 <dt class="hdlist1
">
6127 Any hexadecimal digit character ([0-9A-Fa-f]).
6132 <dt class="hdlist1
">
6137 Note that string classification does <code><em>not</em></code> respect UTF-8. See <a href="#_utf_8_and_unicode
">UTF-8 AND UNICODE</a>.
6140 <dt class="hdlist1
">
6145 Note that only <code><em>lowercase</em></code> boolean values are recognized (Tcl accepts any case).
6148 <dt class="hdlist1
">
6149 <code><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></code>
6153 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6154 the characters in <code><em>string1</em></code>. If found, return the index of the
6155 first character in the last such match within <code><em>string2</em></code>. If there
6156 is no match, then return -1. If <code><em>lastIndex</em></code> is specified, only characters
6157 up to <code><em>lastIndex</em></code> of <code><em>string2</em></code> will be considered in the match.
6160 <dt class="hdlist1
">
6165 See <a href="#_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</a> for all allowed forms for <code><em>lastIndex</em></code>.
6168 <dt class="hdlist1
">
6169 <code><strong>string length</strong> <em>string</em></code>
6173 Returns a decimal string giving the number of characters in <code><em>string</em></code>.
6174 If UTF-8 support is enabled, this may be different than the number of bytes.
6175 See <a href="#_utf_8_and_unicode
">UTF-8 AND UNICODE</a>.
6178 <dt class="hdlist1
">
6179 <code><strong>string map ?-nocase?</strong> <em>mapping string</em></code>
6183 Replaces substrings in <code><em>string</em></code> based on the key-value pairs in
6184 <code><em>mapping</em></code>, which is a list of <code>key value key value ...</code> as in the form
6185 returned by <a href="#_array
"><strong><code>array</code></strong></a> <code>get</code>. Each instance of a key in the string will be
6186 replaced with its corresponding value. If <code>-nocase</code> is specified, then
6187 matching is done without regard to case differences. Both key and value may
6188 be multiple characters. Replacement is done in an ordered manner, so the
6189 key appearing first in the list will be checked first, and so on. <code><em>string</em></code> is
6190 only iterated over once, so earlier key replacements will have no affect for
6191 later key matches. For example,
6195 <div class="listingblock
">
6196 <div class="content
">
6197 <pre><code> string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc</code></pre>
6199 <div class="dlist
"><dl>
6200 <dt class="hdlist1
">
6205 will return the string <code>01321221</code>.
6208 <dt class="hdlist1
">
6213 Note that if an earlier key is a prefix of a later one, it will completely mask the later
6214 one. So if the previous example is reordered like this,
6218 <div class="listingblock
">
6219 <div class="content
">
6220 <pre><code> string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc</code></pre>
6222 <div class="dlist
"><dl>
6223 <dt class="hdlist1
">
6228 it will return the string <code>02c322c222c</code>.
6231 <dt class="hdlist1
">
6232 <code><strong>string match ?-nocase?</strong> <em>pattern string</em></code>
6236 See if <code><em>pattern</em></code> matches <code><em>string</em></code>; return 1 if it does, 0
6237 if it doesn’t. Matching is done in a fashion similar to that
6238 used by the C-shell. For the two strings to match, their contents
6239 must be identical except that the following special sequences
6240 may appear in <code><em>pattern</em></code>:
6242 <div class="dlist
"><dl>
6243 <dt class="hdlist1
">
6248 Matches any sequence of characters in <code><em>string</em></code>,
6249 including a null string.
6252 <dt class="hdlist1
">
6257 Matches any single character in <code><em>string</em></code>.
6260 <dt class="hdlist1
">
6261 <code>[<em>chars</em>]</code>
6265 Matches any character in the set given by <code><em>chars</em></code>.
6266 If a sequence of the form <code><em>x-y</em></code> appears in <code><em>chars</em></code>,
6267 then any character between <code><em>x</em></code> and <code><em>y</em></code>, inclusive,
6271 <dt class="hdlist1
">
6276 Matches the single character <code><em>x</em></code>. This provides a way of
6277 avoiding the special interpretation of the characters <code>\*?[]</code>
6278 in <code><em>pattern</em></code>.
6283 <dt class="hdlist1
">
6288 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6291 <dt class="hdlist1
">
6292 <code><strong>string range</strong> <em>string first last</em></code>
6296 Returns a range of consecutive characters from <code><em>string</em></code>, starting
6297 with the character whose index is <code><em>first</em></code> and ending with the
6298 character whose index is <code><em>last</em></code>. An index of 0 refers to the
6299 first character of the string.
6302 <dt class="hdlist1
">
6307 See <a href="#_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</a> for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.
6310 <dt class="hdlist1
">
6315 If <code><em>first</em></code> is less than zero then it is treated as if it were zero, and
6316 if <code><em>last</em></code> is greater than or equal to the length of the string then
6317 it is treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than
6318 <code><em>last</em></code> then an empty string is returned.
6321 <dt class="hdlist1
">
6322 <code><strong>string repeat</strong> <em>string count</em></code>
6326 Returns a new string consisting of <code><em>string</em></code> repeated <code><em>count</em></code> times.
6329 <dt class="hdlist1
">
6330 <code><strong>string replace</strong> <em>string first last ?newstring?</em></code>
6334 Removes a range of consecutive characters from <code><em>string</em></code>, starting
6335 with the character whose index is <code><em>first</em></code> and ending with the
6336 character whose index is <code><em>last</em></code>. If <code><em>newstring</em></code> is specified,
6337 then it is placed in the removed character range. If <code><em>first</em></code> is
6338 less than zero then it is treated as if it were zero, and if <code><em>last</em></code>
6339 is greater than or equal to the length of the string then it is
6340 treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than <code><em>last</em></code>
6341 or the length of the initial string, or <code><em>last</em></code> is less than 0,
6342 then the initial string is returned untouched.
6345 <dt class="hdlist1
">
6346 <code><strong>string reverse</strong> <em>string</em></code>
6350 Returns a string that is the same length as <code><em>string</em></code> but
6351 with its characters in the reverse order.
6354 <dt class="hdlist1
">
6355 <code><strong>string tolower</strong> <em>string</em></code>
6359 Returns a value equal to <code><em>string</em></code> except that all upper case
6360 letters have been converted to lower case.
6363 <dt class="hdlist1
">
6364 <code><strong>string totitle</strong> <em>string</em></code>
6368 Returns a value equal to <code><em>string</em></code> except that the first character
6369 is converted to title case (or upper case if there is no UTF-8 titlecase variant)
6370 and all remaining characters have been converted to lower case.
6373 <dt class="hdlist1
">
6374 <code><strong>string toupper</strong> <em>string</em></code>
6378 Returns a value equal to <code><em>string</em></code> except that all lower case
6379 letters have been converted to upper case.
6382 <dt class="hdlist1
">
6383 <code><strong>string trim</strong> <em>string ?chars?</em></code>
6387 Returns a value equal to <code><em>string</em></code> except that any leading
6388 or trailing characters from the set given by <code><em>chars</em></code> are
6390 If <code><em>chars</em></code> is not specified then white space is removed
6391 (spaces, tabs, newlines, and carriage returns).
6394 <dt class="hdlist1
">
6395 <code><strong>string trimleft</strong> <em>string ?chars?</em></code>
6399 Returns a value equal to <code><em>string</em></code> except that any
6400 leading characters from the set given by <code><em>chars</em></code> are
6402 If <code><em>chars</em></code> is not specified then white space is removed
6403 (spaces, tabs, newlines, and carriage returns).
6406 <dt class="hdlist1
">
6407 <code><strong>string trimright</strong> <em>string ?chars?</em></code>
6411 Returns a value equal to <code><em>string</em></code> except that any
6412 trailing characters from the set given by <code><em>chars</em></code> are
6414 If <code><em>chars</em></code> is not specified then white space is removed
6415 (spaces, tabs, newlines, and carriage returns).
6416 Null characters are always removed.
6422 <h3 id="_subst
">subst</h3>
6423 <div class="paragraph
"><p><code><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></code></p></div>
6424 <div class="paragraph
"><p>This command performs variable substitutions, command substitutions,
6425 and backslash substitutions on its string argument and returns the
6426 fully-substituted result. The substitutions are performed in exactly
6427 the same way as for Tcl commands. As a result, the string argument
6428 is actually substituted twice, once by the Tcl parser in the usual
6429 fashion for Tcl commands, and again by the subst command.</p></div>
6430 <div class="paragraph
"><p>If any of the <code>-nobackslashes</code>, <code>-nocommands</code>, or <code>-novariables</code> are
6431 specified, then the corresponding substitutions are not performed.
6432 For example, if <code>-nocommands</code> is specified, no command substitution
6433 is performed: open and close brackets are treated as ordinary
6434 characters with no special interpretation.</p></div>
6435 <div class="paragraph
"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
6436 special treatment to double quotes or curly braces. For example,
6437 the following script returns <code>xyz {44}</code>, not <code>xyz {$a}</code>.</p></div>
6438 <div class="listingblock
">
6439 <div class="content
">
6440 <pre><code> set a 44
6441 subst {xyz {$a}}</code></pre>
6445 <h3 id="_switch
">switch</h3>
6446 <div class="paragraph
"><p><code><strong>switch</strong> <em>?options? string pattern body ?pattern body ...?</em></code></p></div>
6447 <div class="paragraph
"><p><code><strong>switch</strong> <em>?options? string {pattern body ?pattern body ...?}</em></code></p></div>
6448 <div class="paragraph
"><p>The <a href="#_switch
"><strong><code>switch</code></strong></a> command matches its string argument against each of
6449 the pattern arguments in order. As soon as it finds a pattern that
6450 matches string it evaluates the following body and returns the
6451 result of that evaluation. If the last pattern argument is default
6452 then it matches anything. If no pattern argument matches string and
6453 no default is given, then the <a href="#_switch
"><strong><code>switch</code></strong></a> command returns an empty string.
6454 If the initial arguments to switch start with - then they are treated
6455 as options. The following options are currently supported:</p></div>
6456 <div class="dlist
"><dl>
6457 <dt class="hdlist1
">
6462 Use exact matching when comparing string to a
6463 pattern. This is the default.
6466 <dt class="hdlist1
">
6471 When matching string to the patterns, use glob-style
6472 matching (i.e. the same as implemented by the string
6476 <dt class="hdlist1
">
6477 <code>-regexp</code>
6481 When matching string to the patterns, use regular
6482 expression matching (i.e. the same as implemented
6483 by the regexp command).
6486 <dt class="hdlist1
">
6487 <code>-command <em>commandname</em></code>
6491 When matching string to the patterns, use the given command, which
6492 must be a single word. The command is invoked as
6493 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
6494 and must return 1 if matched, or 0 if not.
6497 <dt class="hdlist1
">
6502 Marks the end of options. The argument following
6503 this one will be treated as string even if it starts
6504 with a <code>-</code>.
6508 <div class="paragraph
"><p>Two syntaxes are provided for the pattern and body arguments. The
6509 first uses a separate argument for each of the patterns and commands;
6510 this form is convenient if substitutions are desired on some of the
6511 patterns or commands. The second form places all of the patterns
6512 and commands together into a single argument; the argument must
6513 have proper list structure, with the elements of the list being the
6514 patterns and commands. The second form makes it easy to construct
6515 multi-line <a href="#_switch
"><strong><code>switch</code></strong></a> commands, since the braces around the whole list
6516 make it unnecessary to include a backslash at the end of each line.
6517 Since the pattern arguments are in braces in the second form, no
6518 command or variable substitutions are performed on them; this makes
6519 the behaviour of the second form different than the first form in
6520 some cases.</p></div>
6521 <div class="paragraph
"><p>If a body is specified as <code>-</code> it means that the body for the next
6522 pattern should also be used as the body for this pattern (if the
6523 next pattern also has a body of <code>-</code> then the body after that is
6524 used, and so on). This feature makes it possible to share a single
6525 body among several patterns.</p></div>
6526 <div class="paragraph
"><p>Below are some examples of <a href="#_switch
"><strong><code>switch</code></strong></a> commands:</p></div>
6527 <div class="listingblock
">
6528 <div class="content
">
6529 <pre><code> switch abc a - b {format 1} abc {format 2} default {format 3}</code></pre>
6531 <div class="paragraph
"><p>will return 2,</p></div>
6532 <div class="listingblock
">
6533 <div class="content
">
6534 <pre><code> switch -regexp aaab {
6541 <div class="paragraph
"><p>will return 1, and</p></div>
6542 <div class="listingblock
">
6543 <div class="content
">
6544 <pre><code> switch xyz {
6551 <div class="paragraph
"><p>will return 3.</p></div>
6554 <h3 id="_tailcall
">tailcall</h3>
6555 <div class="paragraph
"><p><code><strong>tailcall</strong> <em>cmd ?arg...?</em></code></p></div>
6556 <div class="paragraph
"><p>The <a href="#_tailcall
"><strong><code>tailcall</code></strong></a> command provides an optimised way of invoking a command whilst replacing
6557 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
6558 <div class="paragraph
"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
6559 <div class="listingblock
">
6560 <div class="content
">
6561 <pre><code> tailcall a b c</code></pre>
6563 <div class="listingblock
">
6564 <div class="content
">
6565 <pre><code> return [uplevel 1 [list a b c]]</code></pre>
6567 <div class="paragraph
"><p><a href="#_tailcall
"><strong><code>tailcall</code></strong></a> is useful as a dispatch mechanism:</p></div>
6568 <div class="listingblock
">
6569 <div class="content
">
6570 <pre><code> proc a {cmd args} {
6571 tailcall sub_$cmd {*}$args
6574 proc sub_cmd2 ...</code></pre>
6578 <h3 id="_tell
">tell</h3>
6579 <div class="paragraph
"><p><code><strong>tell</strong> <em>fileId</em></code></p></div>
6580 <div class="paragraph
"><p><code><em>fileId</em> <strong>tell</strong></code></p></div>
6581 <div class="paragraph
"><p>Returns a decimal string giving the current access position in
6582 <code><em>fileId</em></code>.</p></div>
6583 <div class="paragraph
"><p><code><em>fileId</em></code> must have been the return value from a previous call to
6584 <a href="#_open
"><strong><code>open</code></strong></a>, or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one
6585 of the standard I/O channels.</p></div>
6588 <h3 id="_throw
">throw</h3>
6589 <div class="paragraph
"><p><code><strong>throw</strong> <em>code ?msg?</em></code></p></div>
6590 <div class="paragraph
"><p>This command throws an exception (return) code along with an optional message.
6591 This command is mostly for convenient usage with <a href="#_try
"><strong><code>try</code></strong></a>.</p></div>
6592 <div class="paragraph
"><p>The command <code>throw break</code> is equivalent to <code>break</code>.
6593 The command <code>throw 20 message</code> can be caught with an <code>on 20 ...</code> clause to <a href="#_try
"><strong><code>try</code></strong></a>.</p></div>
6596 <h3 id="_time
">time</h3>
6597 <div class="paragraph
"><p><code><strong>time</strong> <em>command ?count?</em></code></p></div>
6598 <div class="paragraph
"><p>This command will call the Tcl interpreter <code><em>count</em></code>
6599 times to execute <code><em>command</em></code> (or once if <code><em>count</em></code> isn’t
6600 specified). It will then return a string of the form</p></div>
6601 <div class="listingblock
">
6602 <div class="content
">
6603 <pre><code> 503 microseconds per iteration</code></pre>
6605 <div class="paragraph
"><p>which indicates the average amount of time required per iteration,
6606 in microseconds.</p></div>
6607 <div class="paragraph
"><p>Time is measured in elapsed time, not CPU time.</p></div>
6610 <h3 id="_try
">try</h3>
6611 <div class="paragraph
"><p><code><strong>try</strong> <em>?catchopts? tryscript</em> ?<strong>on</strong> <em>returncodes {?resultvar? ?optsvar?} handlerscript ...</em>? ?<strong>finally</strong> <em>finalscript</em>?</code></p></div>
6612 <div class="paragraph
"><p>The <a href="#_try
"><strong><code>try</code></strong></a> command is provided as a convenience for exception handling.</p></div>
6613 <div class="paragraph
"><p>This interpeter first evaluates <code><em>tryscript</em></code> under the effect of the catch
6614 options <code><em>catchopts</em></code> (e.g. <code>-signal -noexit --</code>, see <a href="#_catch
"><strong><code>catch</code></strong></a>).</p></div>
6615 <div class="paragraph
"><p>It then evaluates the script for the first matching <em>on</em> handler
6616 (there many be zero or more) based on the return code from the <a href="#_try
"><strong><code>try</code></strong></a>
6617 section. For example a normal <code>JIM_ERR</code> error will be matched by
6618 an <em>on error</em> handler.</p></div>
6619 <div class="paragraph
"><p>Finally, any <code><em>finalscript</em></code> is evaluated.</p></div>
6620 <div class="paragraph
"><p>The result of this command is the result of <code><em>tryscript</em></code>, except in the
6621 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
6622 in which case the result is this new exception.</p></div>
6623 <div class="paragraph
"><p>The specified <code><em>returncodes</em></code> is a list of return codes either as names (<em>ok</em>, <em>error</em>, <em>break</em>, etc.)
6624 or as integers.</p></div>
6625 <div class="paragraph
"><p>If <code><em>resultvar</em></code> and <code><em>optsvar</em></code> are specified, they are set as for <a href="#_catch
"><strong><code>catch</code></strong></a> before evaluating
6626 the matching handler.</p></div>
6627 <div class="paragraph
"><p>For example:</p></div>
6628 <div class="listingblock
">
6629 <div class="content
">
6630 <pre><code> set f [open input]
6633 } on {continue break} {} {
6634 error "Unexpected break/continue
"
6635 } on error {msg opts} {
6636 puts "Dealing with error
"
6637 return {*}$opts $msg
6639 puts "Got signal: $sig
"
6644 <div class="paragraph
"><p>If break, continue or error are raised, they are dealt with by the matching
6646 <div class="paragraph
"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6647 <div class="paragraph
"><p>See also <a href="#_throw
"><strong><code>throw</code></strong></a>, <a href="#_catch
"><strong><code>catch</code></strong></a>, <a href="#_return
"><strong><code>return</code></strong></a>, <a href="#_error
"><strong><code>error</code></strong></a>.</p></div>
6650 <h3 id="_unknown
">unknown</h3>
6651 <div class="paragraph
"><p><code><strong>unknown</strong> <em>cmdName ?arg arg …?</em></code></p></div>
6652 <div class="paragraph
"><p>This command doesn’t actually exist as part of Tcl, but Tcl will
6653 invoke it if it does exist.</p></div>
6654 <div class="paragraph
"><p>If the Tcl interpreter encounters a command name for which there
6655 is not a defined command, then Tcl checks for the existence of
6656 a command named <a href="#_unknown
"><strong><code>unknown</code></strong></a>.</p></div>
6657 <div class="paragraph
"><p>If there is no such command, then the interpreter returns an
6659 <div class="paragraph
"><p>If the <a href="#_unknown
"><strong><code>unknown</code></strong></a> command exists, then it is invoked with
6660 arguments consisting of the fully-substituted name and arguments
6661 for the original non-existent command.</p></div>
6662 <div class="paragraph
"><p>The <a href="#_unknown
"><strong><code>unknown</code></strong></a> command typically does things like searching
6663 through library directories for a command procedure with the name
6664 <code><em>cmdName</em></code>, or expanding abbreviated command names to full-length,
6665 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6666 <div class="paragraph
"><p>In some cases (such as expanding abbreviations) <a href="#_unknown
"><strong><code>unknown</code></strong></a> will
6667 change the original command slightly and then (re-)execute it.
6668 The result of the <a href="#_unknown
"><strong><code>unknown</code></strong></a> command is used as the result for
6669 the original non-existent command.</p></div>
6672 <h3 id="_unset
">unset</h3>
6673 <div class="paragraph
"><p><code><strong>unset ?-nocomplain? ?--?</strong> <em>?name name …?</em></code></p></div>
6674 <div class="paragraph
"><p>Remove variables.
6675 Each <code><em>name</em></code> is a variable name, specified in any of the
6676 ways acceptable to the <a href="#_set
"><strong><code>set</code></strong></a> command.</p></div>
6677 <div class="paragraph
"><p>If a <code><em>name</em></code> refers to an element of an array, then that
6678 element is removed without affecting the rest of the array.</p></div>
6679 <div class="paragraph
"><p>If a <code><em>name</em></code> consists of an array name with no parenthesized
6680 index, then the entire array is deleted.</p></div>
6681 <div class="paragraph
"><p>The <a href="#_unset
"><strong><code>unset</code></strong></a> command returns an empty string as result.</p></div>
6682 <div class="paragraph
"><p>An error occurs if any of the variables doesn’t exist, unless <em>-nocomplain</em>
6683 is specified. The <em>--</em> argument may be specified to stop option processing
6684 in case the variable name may be <em>-nocomplain</em>.</p></div>
6687 <h3 id="_upcall
">upcall</h3>
6688 <div class="paragraph
"><p><code><strong>upcall</strong> <em>command ?args …?</em></code></p></div>
6689 <div class="paragraph
"><p>May be used from within a proc defined as <a href="#_local
"><strong><code>local</code></strong></a> <a href="#_proc
"><strong><code>proc</code></strong></a> in order to call
6690 the previous, hidden version of the same command.</p></div>
6691 <div class="paragraph
"><p>If there is no previous definition of the command, an error is returned.</p></div>
6694 <h3 id="_uplevel
">uplevel</h3>
6695 <div class="paragraph
"><p><code><strong>uplevel</strong> <em>?level? command ?command …?</em></code></p></div>
6696 <div class="paragraph
"><p>All of the <code><em>command</em></code> arguments are concatenated as if they had
6697 been passed to <a href="#_concat
"><strong><code>concat</code></strong></a>; the result is then evaluated in the
6698 variable context indicated by <code><em>level</em></code>. <a href="#_uplevel
"><strong><code>uplevel</code></strong></a> returns
6699 the result of that evaluation. If <code><em>level</em></code> is an integer, then
6700 it gives a distance (up the procedure calling stack) to move before
6701 executing the command. If <code><em>level</em></code> consists of <code>#</code> followed by
6702 a number then the number gives an absolute level number. If <code><em>level</em></code>
6703 is omitted then it defaults to <code>1</code>. <code><em>level</em></code> cannot be
6704 defaulted if the first <code><em>command</em></code> argument starts with a digit or <code>#</code>.</p></div>
6705 <div class="paragraph
"><p>For example, suppose that procedure <em>a</em> was invoked
6706 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6707 Suppose that <em>c</em> invokes the <a href="#_uplevel
"><strong><code>uplevel</code></strong></a> command. If <code><em>level</em></code>
6708 is <code>1</code> or <code>#2</code> or omitted, then the command will be executed
6709 in the variable context of <em>b</em>. If <code><em>level</em></code> is <code>2</code> or <code>#1</code>
6710 then the command will be executed in the variable context of <em>a</em>.</p></div>
6711 <div class="paragraph
"><p>If <code><em>level</em></code> is <em>3</em> or <code>#0</code> then the command will be executed
6712 at top-level (only global variables will be visible).
6713 The <a href="#_uplevel
"><strong><code>uplevel</code></strong></a> command causes the invoking procedure to disappear
6714 from the procedure calling stack while the command is being executed.
6715 In the above example, suppose <em>c</em> invokes the command</p></div>
6716 <div class="listingblock
">
6717 <div class="content
">
6718 <pre><code> uplevel 1 {set x 43; d}</code></pre>
6720 <div class="paragraph
"><p>where <em>d</em> is another Tcl procedure. The <a href="#_set
"><strong><code>set</code></strong></a> command will
6721 modify the variable <em>x</em> in <em>b’s context, and 'd</em> will execute
6722 at level 3, as if called from <em>b</em>. If it in turn executes
6723 the command</p></div>
6724 <div class="listingblock
">
6725 <div class="content
">
6726 <pre><code> uplevel {set x 42}</code></pre>
6728 <div class="paragraph
"><p>then the <a href="#_set
"><strong><code>set</code></strong></a> command will modify the same variable <em>x</em> in <em>b’s
6729 context: the procedure 'c</em> does not appear to be on the call stack
6730 when <em>d</em> is executing. The command <a href="#_info
"><strong><code>info</code></strong></a> <code>level</code> may
6731 be used to obtain the level of the current procedure.</p></div>
6732 <div class="paragraph
"><p><a href="#_uplevel
"><strong><code>uplevel</code></strong></a> makes it possible to implement new control
6733 constructs as Tcl procedures (for example, <a href="#_uplevel
"><strong><code>uplevel</code></strong></a> could
6734 be used to implement the <a href="#_while
"><strong><code>while</code></strong></a> construct as a Tcl procedure).</p></div>
6737 <h3 id="_upvar
">upvar</h3>
6738 <div class="paragraph
"><p><code><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar …?</em></code></p></div>
6739 <div class="paragraph
"><p>This command arranges for one or more local variables in the current
6740 procedure to refer to variables in an enclosing procedure call or
6741 to global variables.</p></div>
6742 <div class="paragraph
"><p><code><em>level</em></code> may have any of the forms permitted for the <a href="#_uplevel
"><strong><code>uplevel</code></strong></a>
6743 command, and may be omitted if the first letter of the first <code><em>otherVar</em></code>
6744 isn’t <code>#</code> or a digit (it defaults to <em>1</em>).</p></div>
6745 <div class="paragraph
"><p>For each <code><em>otherVar</em></code> argument, <a href="#_upvar
"><strong><code>upvar</code></strong></a> makes the variable
6746 by that name in the procedure frame given by <code><em>level</em></code> (or at
6747 global level, if <code><em>level</em></code> is <code>#0</code>) accessible
6748 in the current procedure by the name given in the corresponding
6749 <code><em>myVar</em></code> argument.</p></div>
6750 <div class="paragraph
"><p>The variable named by <code><em>otherVar</em></code> need not exist at the time of the
6751 call; it will be created the first time <code><em>myVar</em></code> is referenced, just like
6752 an ordinary variable.</p></div>
6753 <div class="paragraph
"><p><a href="#_upvar
"><strong><code>upvar</code></strong></a> may only be invoked from within procedures.</p></div>
6754 <div class="paragraph
"><p><a href="#_upvar
"><strong><code>upvar</code></strong></a> returns an empty string.</p></div>
6755 <div class="paragraph
"><p>The <a href="#_upvar
"><strong><code>upvar</code></strong></a> command simplifies the implementation of call-by-name
6756 procedure calling and also makes it easier to build new control constructs
6758 For example, consider the following procedure:</p></div>
6759 <div class="listingblock
">
6760 <div class="content
">
6761 <pre><code> proc add2 name {
6766 <div class="paragraph
"><p><em>add2</em> is invoked with an argument giving the name of a variable,
6767 and it adds two to the value of that variable.
6768 Although <em>add2</em> could have been implemented using <a href="#_uplevel
"><strong><code>uplevel</code></strong></a>
6769 instead of <a href="#_upvar
"><strong><code>upvar</code></strong></a>, <a href="#_upvar
"><strong><code>upvar</code></strong></a> makes it simpler for <em>add2</em>
6770 to access the variable in the caller’s procedure frame.</p></div>
6773 <h3 id="_wait
">wait</h3>
6774 <div class="paragraph
"><p><code><strong>wait</strong></code></p></div>
6775 <div class="paragraph
"><p><code><strong>wait -nohang</strong> <em>pid</em></code></p></div>
6776 <div class="paragraph
"><p>With no arguments, cleans up any processes started by <a href="#_exec
"><strong><code>exec</code></strong></a> <code>... &</code> that have completed
6777 (reaps zombie processes).</p></div>
6778 <div class="paragraph
"><p>With one or two arguments, waits for a process by id, either returned by <a href="#_exec
"><strong><code>exec</code></strong></a> <code>... &</code>
6779 or by <a href="#cmd_1
"><strong><code>os.fork</code></strong></a> (if supported).</p></div>
6780 <div class="paragraph
"><p>Waits for the process to complete, unless <code>-nohang</code> is specified, in which case returns
6781 immediately if the process is still running.</p></div>
6782 <div class="paragraph
"><p>Returns a list of 3 elements.</p></div>
6783 <div class="paragraph
"><p><code>{NONE x x}</code> if the process does not exist or has already been waited for, or
6784 if -nohang is specified, and the process is still alive.</p></div>
6785 <div class="paragraph
"><p><code>{CHILDSTATUS <pid> <exit-status>}</code> if the process exited normally.</p></div>
6786 <div class="paragraph
"><p><code>{CHILDKILLED <pid> <signal>}</code> if the process terminated on a signal.</p></div>
6787 <div class="paragraph
"><p><code>{CHILDSUSP <pid> none}</code> if the process terminated for some other reason.</p></div>
6788 <div class="paragraph
"><p>Note that on platforms supporting waitpid(2), <code>pid</code> can also be given special values such
6789 as 0 or -1. See waitpid(2) for more detail.</p></div>
6792 <h3 id="_while
">while</h3>
6793 <div class="paragraph
"><p><code><strong>while</strong> <em>test body</em></code></p></div>
6794 <div class="paragraph
"><p>The <code><em>while</em></code> command evaluates <code><em>test</em></code> as an expression
6795 (in the same way that <a href="#_expr
"><strong><code>expr</code></strong></a> evaluates its argument).
6796 The value of the expression must be numeric; if it is non-zero
6797 then <code><em>body</em></code> is executed by passing it to the Tcl interpreter.</p></div>
6798 <div class="paragraph
"><p>Once <code><em>body</em></code> has been executed then <code><em>test</em></code> is evaluated
6799 again, and the process repeats until eventually <code><em>test</em></code>
6800 evaluates to a zero numeric value. <a href="#_continue
"><strong><code>continue</code></strong></a>
6801 commands may be executed inside <code><em>body</em></code> to terminate the current
6802 iteration of the loop, and <a href="#_break
"><strong><code>break</code></strong></a>
6803 commands may be executed inside <code><em>body</em></code> to cause immediate
6804 termination of the <a href="#_while
"><strong><code>while</code></strong></a> command.</p></div>
6805 <div class="paragraph
"><p>The <a href="#_while
"><strong><code>while</code></strong></a> command always returns an empty string.</p></div>
6810 <h2 id="_optional_extensions
">OPTIONAL-EXTENSIONS</h2>
6811 <div class="sectionbody
">
6812 <div class="paragraph
"><p>The following extensions may or may not be available depending upon
6813 what options were selected when Jim Tcl was built.</p></div>
6815 <h3 id="cmd_1
">posix: os.fork, os.gethostname, os.getids, os.uptime</h3>
6816 <div class="dlist
"><dl>
6817 <dt class="hdlist1
">
6818 <code><strong>os.fork</strong></code>
6822 Invokes <em>fork(2)</em> and returns the result.
6825 <dt class="hdlist1
">
6826 <code><strong>os.gethostname</strong></code>
6830 Invokes <em>gethostname(3)</em> and returns the result.
6833 <dt class="hdlist1
">
6834 <code><strong>os.getids</strong></code>
6838 Returns the various user/group ids for the current process.
6842 <div class="listingblock
">
6843 <div class="content
">
6844 <pre><code> . os.getids
6845 uid 1000 euid 1000 gid 100 egid 100</code></pre>
6847 <div class="dlist
"><dl>
6848 <dt class="hdlist1
">
6849 <code><strong>os.uptime</strong></code>
6853 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
6861 <h2 id="_ansi_i_o_aio_and_eventloop_api
">ANSI I/O (aio) and EVENTLOOP API</h2>
6862 <div class="sectionbody
">
6863 <div class="paragraph
"><p>Jim provides an alternative object-based API for I/O.</p></div>
6864 <div class="paragraph
"><p>See <a href="#_open
"><strong><code>open</code></strong></a> and <a href="#_socket
"><strong><code>socket</code></strong></a> for commands which return an I/O handle.</p></div>
6866 <h3 id="_aio
">aio</h3>
6867 <div class="dlist
"><dl>
6868 <dt class="hdlist1
">
6869 <code>$handle <strong>accept</strong> ?addrvar?</code>
6873 Server socket only: Accept a connection and return stream.
6874 If <code><em>addrvar</em></code> is specified, the address of the connected client is stored
6875 in the named variable in the form <em>addr:port</em> for IP sockets or <em>path</em> for Unix domain sockets.
6876 See <a href="#_socket
"><strong><code>socket</code></strong></a> for details.
6879 <dt class="hdlist1
">
6880 <code>$handle <strong>buffering none|line|full</strong></code>
6884 Sets the buffering mode of the stream.
6887 <dt class="hdlist1
">
6888 <code>$handle <strong>close ?r(ead)|w(rite)|-nodelete?</strong></code>
6893 The <code><em>read</em></code> and <code><em>write</em></code> arguments perform a "half-close
" on a socket. See the <em>shutdown(2)</em> man page.
6894 The <code><em>-nodelete</em></code> option is applicable only for Unix domain sockets. It closes the socket
6895 but does not delete the bound path (e.g. after <a href="#cmd_1
"><strong><code>os.fork</code></strong></a>).
6898 <dt class="hdlist1
">
6899 <code>$handle <strong>copyto</strong> <em>tofd ?size?</em></code>
6903 Copy bytes to the file descriptor <code><em>tofd</em></code>. If <code><em>size</em></code> is specified, at most
6904 that many bytes will be copied. Otherwise copying continues until the end
6905 of the input file. Returns the number of bytes actually copied.
6908 <dt class="hdlist1
">
6909 <code>$handle <strong>eof</strong></code>
6913 Returns 1 if stream is at eof
6916 <dt class="hdlist1
">
6917 <code>$handle <strong>filename</strong></code>
6921 Returns the original filename associated with the handle.
6922 Handles returned by <a href="#_socket
"><strong><code>socket</code></strong></a> give the socket type instead of a filename.
6925 <dt class="hdlist1
">
6926 <code>$handle <strong>flush</strong></code>
6933 <dt class="hdlist1
">
6934 <code>$handle <strong>gets</strong> <em>?var?</em></code>
6938 Read one line and return it or store it in the var
6941 <dt class="hdlist1
">
6942 <code>$handle <strong>isatty</strong></code>
6946 Returns 1 if the stream is a tty device.
6949 <dt class="hdlist1
">
6950 <code>$handle <strong>lock ?-wait?</strong></code>
6954 Apply a POSIX lock to the open file associated with the handle using
6955 <em>fcntl(F_SETLK)</em>, or <em>fcntl(F_SETLKW)</em> to wait for the lock to be available if <code><em>-wait</em></code>
6957 The handle must be open for write access.
6958 Returns 1 if the lock was successfully obtained, 0 otherwise.
6959 An error occurs if the handle is not suitable for locking (e.g.
6960 if it is not open for write)
6963 <dt class="hdlist1
">
6964 <code>$handle <strong>ndelay ?0|1?</strong></code>
6968 Set O_NDELAY (if arg). Returns current/new setting.
6969 Note that in general ANSI I/O interacts badly with non-blocking I/O.
6973 <dt class="hdlist1
">
6974 <code>$handle <strong>peername</strong></code>
6978 Returns the remote address or path of the connected socket. See <em>getpeername(2)</em>.
6981 <dt class="hdlist1
">
6982 <code>$handle <strong>puts ?-nonewline?</strong> <em>str</em></code>
6986 Write the string, with newline unless -nonewline
6989 <dt class="hdlist1
">
6990 <code>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></code>
6994 Read and return bytes from the stream. To eof if no len.
6997 <dt class="hdlist1
">
6998 <code>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></code>
7002 Receives a message from the handle via recvfrom(2) and returns it.
7003 At most <code><em>maxlen</em></code> bytes are read. If <code><em>addrvar</em></code> is specified, the sending address
7004 of the message is stored in the named variable in the form <em>addr:port</em> for IP sockets
7005 or <em>path</em> for Unix domain sockets. See <a href="#_socket
"><strong><code>socket</code></strong></a> for details.
7008 <dt class="hdlist1
">
7009 <code>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></code>
7013 Seeks in the stream (default <em>current</em>)
7016 <dt class="hdlist1
">
7017 <code>$handle <strong>sendto</strong> <em>str ?address</em></code>
7021 Sends the string, <code><em>str</em></code>, to the given address (host:port or path) via the socket using <em>sendto(2)</em>.
7022 This is intended for udp/dgram sockets and may give an error or behave in unintended
7023 ways for other handle types.
7024 Returns the number of bytes written.
7027 <dt class="hdlist1
">
7028 <code>$handle <strong>sockname</strong></code>
7032 Returns the bound address or path of the socket. See <em>getsockname(2)</em>.
7035 <dt class="hdlist1
">
7036 <code>$handle <strong>sockopt</strong> <em>?name value?</em></code>
7040 With no arguments, returns a dictionary of socket options currently set for the handle
7041 (will be empty for a non-socket). With <code><em>name</em></code> and <code><em>value</em></code>, sets the socket option
7042 to the given value. Currently supports the following boolean socket options:
7043 <code>broadcast, debug, keepalive, nosigpipe, oobinline, tcp_nodelay</code>, and the following
7044 integer socket options: <code>sndbuf, rcvbuf</code>
7047 <dt class="hdlist1
">
7048 <code>$handle <strong>sync</strong></code>
7052 Flush the stream, then <em>fsync(2)</em> to commit any changes to storage.
7053 Only available on platforms that support <em>fsync(2)</em>.
7056 <dt class="hdlist1
">
7057 <code>$handle <strong>tell</strong></code>
7061 Returns the current seek position
7064 <dt class="hdlist1
">
7065 <code>$handle <strong>tty</strong> ?settings?</code>
7069 If no arguments are given, returns a dictionary containing the tty settings for the stream.
7070 If arguments are given, they must either be a dictionary, or <code>setting value ...</code>
7071 Abbrevations are supported for both settings and values, so the following is acceptable:
7072 <code>$f tty parity e input c out raw</code>.
7073 Only available on platforms that support <em>termios(3)</em>. Supported settings are:
7075 <div class="dlist
"><dl>
7076 <dt class="hdlist1
">
7077 <code><strong>baud</strong> <em>rate</em></code>
7081 Baud rate. e.g. 115200
7084 <dt class="hdlist1
">
7085 <code><strong>data 5|6|7|8</strong></code>
7092 <dt class="hdlist1
">
7093 <code><strong>stop 1|2</strong></code>
7100 <dt class="hdlist1
">
7101 <code><strong>parity even|odd|none</strong></code>
7108 <dt class="hdlist1
">
7109 <code><strong>handshake xonxoff|rtscts|none</strong></code>
7116 <dt class="hdlist1
">
7117 <code><strong>input raw|cooked</strong></code>
7121 Input character processing. In raw mode, the usual key sequences such as ^C do
7122 not generate signals.
7125 <dt class="hdlist1
">
7126 <code><strong>output raw|cooked</strong></code>
7130 Output character processing. Typically CR → CRNL is disabled in raw mode.
7133 <dt class="hdlist1
">
7134 <code><strong>echo 0|1</strong></code>
7138 Disable or enable echo on input. Note that this is a set-only value.
7139 Setting <code>input</code> to <code>raw</code> or <code>cooked</code> will overwrite this setting.
7142 <dt class="hdlist1
">
7143 <code><strong>vmin</strong> <em>numchars</em></code>
7147 Minimum number of characters to read.
7150 <dt class="hdlist1
">
7151 <code><strong>vtime</strong> <em>time</em></code>
7155 Timeout for noncanonical read (units of 0.1 seconds)
7160 <dt class="hdlist1
">
7161 <code>$handle <strong>ssl</strong> ?<strong>-server</strong> <em>cert priv</em>?</code>
7165 Upgrades the stream to a SSL/TLS session and returns the handle.
7168 <dt class="hdlist1
">
7169 <code>$handle <strong>unlock</strong></code>
7173 Release a POSIX lock previously acquired by <a href="#_aio
"><strong><code>aio</code></strong></a> <code>lock</code>.
7176 <dt class="hdlist1
">
7177 <code>$handle <strong>verify</strong></code>
7181 Verifies the certificate of a SSL/TLS stream peer
7184 <dt class="hdlist1
">
7185 <code><strong>load_ssl_certs</strong> <em>dir</em></code>
7189 Loads SSL/TLS CA certificates for use during verification
7195 <h3 id="_fconfigure
">fconfigure</h3>
7196 <div class="dlist
"><dl>
7197 <dt class="hdlist1
">
7198 <code><strong>fconfigure</strong> <em>handle</em> <strong>?-blocking 0|1? ?-buffering noneline|full? ?-translation</strong> <em>mode</em>?</code>
7202 For compatibility with Tcl, a limited form of the <a href="#_fconfigure
"><strong><code>fconfigure</code></strong></a>
7203 command is supported.
7205 <div class="ulist
"><ul>
7208 <a href="#_fconfigure
"><strong><code>fconfigure</code></strong></a> <code>... -blocking</code> maps to <a href="#_aio
"><strong><code>aio</code></strong></a> <code>ndelay</code>
7213 <a href="#_fconfigure
"><strong><code>fconfigure</code></strong></a> <code>... -buffering</code> maps to <a href="#_aio
"><strong><code>aio</code></strong></a> <code>buffering</code>
7218 <a href="#_fconfigure
"><strong><code>fconfigure</code></strong></a> <code>... -translation</code> is accepted but ignored
7226 <h3 id="cmd_2
">eventloop: after, vwait, update</h3>
7227 <div class="paragraph
"><p>The following commands allow a script to be invoked when the given condition occurs.
7228 If no script is given, returns the current script. If the given script is the empty, the
7229 handler is removed.</p></div>
7230 <div class="dlist
"><dl>
7231 <dt class="hdlist1
">
7232 <code>$handle <strong>readable</strong> <em>?readable-script?</em></code>
7236 Sets or returns the script for when the socket is readable.
7239 <dt class="hdlist1
">
7240 <code>$handle <strong>writable</strong> <em>?writable-script?</em></code>
7244 Sets or returns the script for when the socket is writable.
7247 <dt class="hdlist1
">
7248 <code>$handle <strong>onexception</strong> <em>?exception-script?</em></code>
7252 Sets or returns the script for when oob data received.
7256 <div class="paragraph
"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <code>fileevent</code>. e.g.</p></div>
7257 <div class="dlist
"><dl>
7258 <dt class="hdlist1
">
7263 <code>fileevent $handle <strong>readable</strong> <em>...</em></code>
7267 <div class="paragraph
"><p>Time-based execution is also available via the eventloop API.</p></div>
7268 <div class="dlist
"><dl>
7269 <dt class="hdlist1
">
7270 <code><strong>after</strong> <em>ms</em></code>
7274 Sleeps for the given number of milliseconds. No events are
7275 processed during this time.
7278 <dt class="hdlist1
">
7279 <code><strong>after</strong> <em>ms</em>|<strong>idle</strong> <em>script ?script ...?</em></code>
7283 The scripts are concatenated and executed after the given
7284 number of milliseconds have elapsed. If <em>idle</em> is specified,
7285 the script will run the next time the event loop is processed
7286 with <a href="#cmd_2
"><strong><code>vwait</code></strong></a> or <a href="#cmd_2
"><strong><code>update</code></strong></a>. The script is only run once and
7287 then removed. Returns an event id.
7290 <dt class="hdlist1
">
7291 <code><strong>after cancel</strong> <em>id|command</em></code>
7295 Cancels an <a href="#cmd_2
"><strong><code>after</code></strong></a> event with the given event id or matching
7296 command (script). Returns the number of milliseconds
7297 remaining until the event would have fired. Returns the
7298 empty string if no matching event is found.
7301 <dt class="hdlist1
">
7302 <code><strong>after info</strong> <em>?id?</em></code>
7306 If <code><em>id</em></code> is not given, returns a list of current <a href="#cmd_2
"><strong><code>after</code></strong></a>
7307 events. If <code><em>id</em></code> is given, returns a list containing the
7308 associated script and either <em>timer</em> or <em>idle</em> to indicated
7309 the type of the event. An error occurs if <code><em>id</em></code> does not
7313 <dt class="hdlist1
">
7314 <code><strong>vwait</strong> <em>variable</em></code>
7318 A call to <a href="#cmd_2
"><strong><code>vwait</code></strong></a> enters the eventloop. <a href="#cmd_2
"><strong><code>vwait</code></strong></a> processes
7319 events until the named (global) variable changes or all
7320 event handlers are removed. The variable need not exist
7321 beforehand. If there are no event handlers defined, <a href="#cmd_2
"><strong><code>vwait</code></strong></a>
7322 returns immediately.
7325 <dt class="hdlist1
">
7326 <code><strong>update ?idletasks?</strong></code>
7330 A call to <a href="#cmd_2
"><strong><code>update</code></strong></a> enters the eventloop to process expired events, but
7331 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
7333 Returns once handlers have been run for all expired events.
7337 <div class="paragraph
"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
7338 an attempt is made to call (the user-defined command) <code>bgerror</code> with the details of the error.
7339 If the <code>bgerror</code> command does not exist, the error message details are printed to stderr instead.</p></div>
7340 <div class="paragraph
"><p>If a file event handler script generates an error, the handler is automatically removed
7341 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
7342 <div class="dlist
"><dl>
7343 <dt class="hdlist1
">
7344 <code><strong>bgerror</strong> <em>msg</em></code>
7348 Called when an event handler script generates an error. Note that the normal command resolution
7349 rules are used for bgerror. First the name is resolved in the current namespace, then in the
7356 <h3 id="_socket
">socket</h3>
7357 <div class="paragraph
"><p>Various socket types may be created.</p></div>
7358 <div class="dlist
"><dl>
7359 <dt class="hdlist1
">
7360 <code><strong>socket unix</strong> <em>path</em></code>
7364 A unix domain socket client connected to <em>path</em>
7367 <dt class="hdlist1
">
7368 <code><strong>socket unix.server</strong> <em>path</em></code>
7372 A unix domain socket server listening on <em>path</em>
7375 <dt class="hdlist1
">
7376 <code><strong>socket unix.dgram</strong> <em>?path?</em></code>
7380 A unix domain socket datagram client, optionally connected to <em>path</em>
7383 <dt class="hdlist1
">
7384 <code><strong>socket unix.dgram.server</strong> <em>path</em></code>
7388 A unix domain socket datagram server server listening on <em>path</em>
7391 <dt class="hdlist1
">
7392 <code><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></code>
7396 A TCP socket client. (See the forms for <code><em>addr</em></code> below)
7399 <dt class="hdlist1
">
7400 <code><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></code>
7404 A TCP socket server (<code><em>addr</em></code> defaults to <code>0.0.0.0</code> for IPv4 or <code>[::]</code> for IPv6).
7407 <dt class="hdlist1
">
7408 <code><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</code>
7412 A UDP socket client. If the address is not specified,
7413 the client socket will be unbound and <em>sendto</em> must be used
7414 to indicated the destination.
7417 <dt class="hdlist1
">
7418 <code><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></code>
7422 A UDP socket server.
7425 <dt class="hdlist1
">
7426 <code><strong>socket pipe</strong></code>
7430 A synonym for <a href="#_pipe
"><strong><code>pipe</code></strong></a>
7433 <dt class="hdlist1
">
7434 <code><strong>socket pair</strong></code>
7438 A socketpair (see socketpair(2)). Like <a href="#_pipe
"><strong><code>pipe</code></strong></a>, this command returns
7439 a list of two channels: {s1 s2}. These channels are both readable and writable.
7443 <div class="paragraph
"><p>This command creates a socket connected (client) or bound (server) to the given
7445 <div class="paragraph
"><p>The returned value is channel and may generally be used with the various file I/O
7446 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
7447 <div class="listingblock
">
7448 <div class="content
">
7449 <pre><code> . set f [socket stream www.google.com:80]
7451 . $f puts -nonewline "GET / HTTP/
1.0\r\n\r\n
"
7454 . $f close</code></pre>
7456 <div class="paragraph
"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
7457 the EVENTLOOP API.</p></div>
7458 <div class="listingblock
">
7459 <div class="content
">
7460 <pre><code> set f [socket stream.server 80]
7462 set client [$f accept]
7465 $client puts -nonewline "HTTP/
1.1 404 Not found\r\n
"
7468 vwait done</code></pre>
7470 <div class="paragraph
"><p>The address, <code><em>addr</em></code>, can be given in one of the following forms:</p></div>
7471 <div class="olist arabic
"><ol class="arabic
">
7474 For IPv4 socket types, an IPv4 address such as 192.168.1.1
7479 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
7488 <div class="paragraph
"><p>Note that on many systems, listening on an IPv6 address such as [::] will
7489 also accept requests via IPv4.</p></div>
7490 <div class="paragraph
"><p>Where a hostname is specified, the <code><em>first</em></code> returned address is used
7491 which matches the socket type is used.</p></div>
7492 <div class="paragraph
"><p>An unconnected dgram socket (either <em>dgram</em> or <em>unix.dgram</em>) must use
7493 <code>sendto</code> to specify the destination address.</p></div>
7494 <div class="paragraph
"><p>The path for Unix domain sockets is automatically removed when the socket
7495 is closed. Use <a href="#_close
"><strong><code>close</code></strong></a> <code>-nodelete</code> in the rare case where this behaviour
7496 should be avoided (e.g. after <a href="#cmd_1
"><strong><code>os.fork</code></strong></a>).</p></div>
7499 <h3 id="_syslog
">syslog</h3>
7500 <div class="paragraph
"><p><code><strong>syslog</strong> <em>?options? ?priority? message</em></code></p></div>
7501 <div class="paragraph
"><p>This command sends message to system syslog facility with given
7502 priority. Valid priorities are:</p></div>
7503 <div class="literalblock
">
7504 <div class="content
">
7505 <pre><code>emerg, alert, crit, err, error, warning, notice, info, debug</code></pre>
7507 <div class="paragraph
"><p>If a message is specified, but no priority is specified, then a
7508 priority of info is used.</p></div>
7509 <div class="paragraph
"><p>By default, facility user is used and the value of global tcl variable
7510 argv0 is used as ident string. However, any of the following options
7511 may be specified before priority to control these parameters:</p></div>
7512 <div class="dlist
"><dl>
7513 <dt class="hdlist1
">
7514 <code><strong>-facility</strong> <em>value</em></code>
7518 Use specified facility instead of user. The following
7519 values for facility are recognized:
7521 <div class="literalblock
">
7522 <div class="content
">
7523 <pre><code>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
7524 uucp, local0-local7</code></pre>
7527 <dt class="hdlist1
">
7528 <code><strong>-ident</strong> <em>string</em></code>
7532 Use given string instead of argv0 variable for ident string.
7535 <dt class="hdlist1
">
7536 <code><strong>-options</strong> <em>integer</em></code>
7540 Set syslog options such as <code>LOG_CONS</code>, <code>LOG_NDELAY</code>. You should
7541 use numeric values of those from your system syslog.h file,
7542 because I haven’t got time to implement yet another hash
7549 <h3 id="cmd_3
">pack: pack, unpack</h3>
7550 <div class="paragraph
"><p>The optional <em>pack</em> extension provides commands to encode and decode binary strings.</p></div>
7551 <div class="dlist
"><dl>
7552 <dt class="hdlist1
">
7553 <code><strong>pack</strong> <em>varName value</em> <strong>-intle|-intbe|-floatle|-floatbe|-str</strong> <em>bitwidth ?bitoffset?</em></code>
7557 Packs the binary representation of <code><em>value</em></code> into the variable
7558 <code><em>varName</em></code>. The value is packed according to the given type
7559 (integer/floating point/string, big-endian/little-endian), width and bit offset.
7560 The variable is created if necessary (like <a href="#_append
"><strong><code>append</code></strong></a>).
7561 The variable is expanded if necessary.
7564 <dt class="hdlist1
">
7565 <code><strong>unpack</strong> <em>binvalue</em> <strong>-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str</strong> <em>bitpos bitwidth</em></code>
7569 Unpacks bits from <code><em>binvalue</em></code> at bit position <code><em>bitpos</em></code> and with <code><em>bitwidth</em></code>.
7570 Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
7571 and signed/unsigned) and returns it. For integer types, <code><em>bitwidth</em></code>
7572 may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
7573 <code><em>bitwidth</em></code> may be 32 bits (for single precision numbers) or 64 bits (for double precision).
7574 For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
7575 access outside the length of the value will return 0 for integer types, 0.0 for floating point types
7576 or the empty string for the string type.
7582 <h3 id="_zlib
">zlib</h3>
7583 <div class="paragraph
"><p>The optional <em>zlib</em> extension provides a Tcl-compatible subset of the <a href="#_zlib
"><strong><code>zlib</code></strong></a> command.</p></div>
7584 <div class="dlist
"><dl>
7585 <dt class="hdlist1
">
7586 <code><strong>crc32</strong> <em>data</em> <em>?startValue?</em></code>
7590 Returns the CRC32 checksum of a buffer. Optionally, an initial value may be specified; this is most useful
7591 for calculating the checksum of chunked data read from a stream (for instance, a pipe).
7594 <dt class="hdlist1
">
7595 <code><strong>deflate</strong> <em>string</em> <em>?level?</em></code>
7599 Compresses a buffer and outputs a raw, Deflate-compressed stream. Optionally, a compression level (1-9) may
7600 be specified to choose the desired speed vs. compression rate ratio.
7603 <dt class="hdlist1
">
7604 <code><strong>inflate</strong> <em>data</em> <em>?bufferSize?</em></code>
7608 Decompresses a raw, Deflate-compressed stream. When the uncompressed data size is known and specified, memory
7609 allocation is more efficient. Otherwise, decomperssion is chunked and therefore slower.
7612 <dt class="hdlist1
">
7613 <code><strong>gzip</strong> <em>string</em> <em>?-level level?</em></code>
7617 Compresses a buffer and adds a gzip header.
7620 <dt class="hdlist1
">
7621 <code><strong>gunzip</strong> <em>data</em> <em>?-buffersize size?</em></code>
7625 Decompresses a gzip-compressed buffer. Decompression is chunked, with a default, small buffer size of 64K
7626 which guarantees lower memory footprint at the cost of speed. It is recommended to use a bigger size, on
7627 systems without a severe memory constraint.
7633 <h3 id="_binary
">binary</h3>
7634 <div class="paragraph
"><p>The optional, pure-Tcl <em>binary</em> extension provides the Tcl-compatible <a href="#_binary
"><strong><code>binary</code></strong></a> <code>scan</code> and <a href="#_binary
"><strong><code>binary</code></strong></a> <code>format</code>
7635 commands based on the low-level <a href="#cmd_3
"><strong><code>pack</code></strong></a> and <a href="#cmd_3
"><strong><code>unpack</code></strong></a> commands.</p></div>
7636 <div class="paragraph
"><p>See the Tcl documentation at: <a href="http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm
">http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm</a></p></div>
7637 <div class="paragraph
"><p>Note that <em>binary format</em> with f/r/R specifiers (single-precision float) uses the value of Infinity
7638 in case of overflow.</p></div>
7641 <h3 id="cmd_4
">oo: class, super</h3>
7642 <div class="paragraph
"><p>The optional, pure-Tcl <em>oo</em> extension provides object-oriented (OO) support for Jim Tcl.</p></div>
7643 <div class="paragraph
"><p>See the online documentation (<a href="http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/
">http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/</a>) for more details.</p></div>
7644 <div class="dlist
"><dl>
7645 <dt class="hdlist1
">
7646 <code><strong>class</strong> <em>classname ?baseclasses? classvars</em></code>
7650 Create a new class, <code><em>classname</em></code>, with the given dictionary
7651 (<code><em>classvars</em></code>) as class variables. These are the initial variables
7652 which all newly created objects of this class are initialised with.
7653 If a list of baseclasses is given, methods and instance variables
7657 <dt class="hdlist1
">
7658 <code><strong>super</strong> <em>method ?args ...?</em></code>
7662 From within a method, invokes the given method on the base class.
7663 Note that this will only call the last baseclass given.
7669 <h3 id="_tree
">tree</h3>
7670 <div class="paragraph
"><p>The optional, pure-Tcl <em>tree</em> extension implements an OO, general purpose tree structure
7671 similar to that provided by tcllib ::struct::tree (<a href="http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/struct_tree.html
">http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/struct_tree.html</a>)</p></div>
7672 <div class="paragraph
"><p>A tree is a collection of nodes, where each node (except the root node) has a single parent
7673 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.</p></div>
7674 <div class="dlist
"><dl>
7675 <dt class="hdlist1
">
7676 <code><strong>tree</strong></code>
7680 Creates and returns a new tree object with a single node named "root
".
7681 All operations on the tree are invoked through this object.
7684 <dt class="hdlist1
">
7685 <code>$tree <strong>destroy</strong></code>
7689 Destroy the tree and all it’s nodes. (Note that the tree will also
7690 be automatically garbage collected once it goes out of scope).
7693 <dt class="hdlist1
">
7694 <code>$tree <strong>set</strong> <em>nodename key value</em></code>
7698 Set the value for the given attribute key.
7701 <dt class="hdlist1
">
7702 <code>$tree <strong>lappend</strong> <em>nodename key value ...</em></code>
7706 Append to the (list) value(s) for the given attribute key, or set if not yet set.
7709 <dt class="hdlist1
">
7710 <code>$tree <strong>keyexists</strong> <em>nodename key</em></code>
7714 Returns 1 if the given attribute key exists.
7717 <dt class="hdlist1
">
7718 <code>$tree <strong>get</strong> <em>nodename key</em></code>
7722 Returns the value associated with the given attribute key.
7725 <dt class="hdlist1
">
7726 <code>$tree <strong>getall</strong> <em>nodename</em></code>
7730 Returns the entire attribute dictionary associated with the given key.
7733 <dt class="hdlist1
">
7734 <code>$tree <strong>depth</strong> <em>nodename</em></code>
7738 Returns the depth of the given node. The depth of "root
" is 0.
7741 <dt class="hdlist1
">
7742 <code>$tree <strong>parent</strong> <em>nodename</em></code>
7746 Returns the node name of the parent node, or "" for the root node.
7749 <dt class="hdlist1
">
7750 <code>$tree <strong>numchildren</strong> <em>nodename</em></code>
7754 Returns the number of child nodes.
7757 <dt class="hdlist1
">
7758 <code>$tree <strong>children</strong> <em>nodename</em></code>
7762 Returns a list of the child nodes.
7765 <dt class="hdlist1
">
7766 <code>$tree <strong>next</strong> <em>nodename</em></code>
7770 Returns the next sibling node, or "" if none.
7773 <dt class="hdlist1
">
7774 <code>$tree <strong>insert</strong> <em>nodename ?index?</em></code>
7778 Add a new child node to the given node. The index is a list index
7779 such as <code>3</code> or <code>end-2</code>. The default index is <code>end</code>.
7780 Returns the name of the newly added node.
7783 <dt class="hdlist1
">
7784 <code>$tree <strong>walk</strong> <em>nodename</em> <strong>dfs|bfs</strong> {<em>actionvar nodevar</em>} <em>script</em></code>
7788 Walks the tree starting from the given node, either breadth first (<code>bfs</code>)
7789 depth first (<code>dfs</code>).
7790 The value <code>"enter
"</code> or <code>"exit
"</code> is stored in variable <code><em>actionvar</em></code>.
7791 The name of each node is stored in <code><em>nodevar</em></code>.
7792 The script is evaluated twice for each node, on entry and exit.
7795 <dt class="hdlist1
">
7796 <code>$tree <strong>dump</strong></code>
7800 Dumps the tree contents to stdout
7806 <h3 id="_tcl_prefix
">tcl::prefix</h3>
7807 <div class="paragraph
"><p>The optional tclprefix extension provides the Tcl8.6-compatible <a href="#_tcl_prefix
"><strong><code>tcl::prefix</code></strong></a> command
7808 (<a href="http://www.tcl.tk/man/tcl8.6/TclCmd/prefix.htm
">http://www.tcl.tk/man/tcl8.6/TclCmd/prefix.htm</a>) for matching strings against a table
7809 of possible values (typically commands or options).</p></div>
7810 <div class="dlist
"><dl>
7811 <dt class="hdlist1
">
7812 <code><strong>tcl::prefix all</strong> <em>table string</em></code>
7816 Returns a list of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7819 <dt class="hdlist1
">
7820 <code><strong>tcl::prefix longest</strong> <em>table string</em></code>
7824 Returns the longest common prefix of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7827 <dt class="hdlist1
">
7828 <code><strong>tcl::prefix match</strong> <em>?options? table string</em></code>
7832 If <code><em>string</em></code> equals one element in <code><em>table</em></code> or is a prefix to
7833 exactly one element, the matched element is returned. If not, the
7834 result depends on the <code>-error</code> option.
7836 <div class="ulist
"><ul>
7839 <code><strong>-exact</strong></code> Accept only exact matches.
7844 <code><strong>-message</strong> <em>string</em></code> Use <code><em>string</em></code> in the error message at a mismatch. Default is "option
".
7849 <code><strong>-error</strong> <em>options</em></code> The options are used when no match is found. If <code><em>options</em></code> is
7850 empty, no error is generated and an empty string is returned.
7851 Otherwise the options are used as return options when
7852 generating the error message. The default corresponds to
7853 setting <code>-level 0</code>.
7861 <h3 id="_tcl_autocomplete
">tcl::autocomplete</h3>
7862 <div class="paragraph
"><p>Scriptable command line completion is supported in the interactive shell, <em>jimsh</em>, through
7863 the <a href="#_tcl_autocomplete
"><strong><code>tcl::autocomplete</code></strong></a> callback. A simple implementation is provided, however this may
7864 be replaced with a custom command instead if desired.</p></div>
7865 <div class="paragraph
"><p>In the interactive shell, press <TAB> to activate command line completion.</p></div>
7866 <div class="dlist
"><dl>
7867 <dt class="hdlist1
">
7868 <code><strong>tcl::autocomplete</strong> <em>commandline</em></code>
7872 This command is called with the current command line when the user presses <TAB>.
7873 The command should return a list of all possible command lines that match the current command line.
7874 For example if <code><strong>pr</strong></code> is the current command line, the list <code><strong>{prefix proc}</strong></code> may be returned.
7880 <h3 id="_history
">history</h3>
7881 <div class="paragraph
"><p>The optional history extension provides script access to the command line editing
7882 and history support available in <em>jimsh</em>. See <em>examples/jtclsh.tcl</em> for an example.
7883 Note: if line editing support is not available, <a href="#_history
"><strong><code>history</code></strong></a> <code>getline</code> acts like <a href="#_gets
"><strong><code>gets</code></strong></a> and
7884 the remaining subcommands do nothing.</p></div>
7885 <div class="dlist
"><dl>
7886 <dt class="hdlist1
">
7887 <code><strong>history load</strong> <em>filename</em></code>
7891 Load history from a (text) file. If the file does not exist or is not readable,
7895 <dt class="hdlist1
">
7896 <code><strong>history getline</strong> <em>prompt ?varname?</em></code>
7900 Displays the given prompt and allows a line to be entered. Similarly to <a href="#_gets
"><strong><code>gets</code></strong></a>,
7901 if <code><em>varname</em></code> is given, it receives the line and the length of the line is returned,
7902 or -1 on EOF. If <code><em>varname</em></code> is not given, the line is returned directly.
7905 <dt class="hdlist1
">
7906 <code><strong>history completion</strong> <em>command</em></code>
7910 Sets an autocompletion command (see <a href="#_tcl_autocomplete
"><strong><code>tcl::autocomplete</code></strong></a>) that is active during <a href="#_history
"><strong><code>history</code></strong></a> <code>getline</code>.
7911 If the command is empty, autocompletion is disabled.
7914 <dt class="hdlist1
">
7915 <code><strong>history add</strong> <em>line</em></code>
7919 Adds the given line to the history buffer.
7922 <dt class="hdlist1
">
7923 <code><strong>history save</strong> <em>filename</em></code>
7927 Saves the current history buffer to the given file.
7930 <dt class="hdlist1
">
7931 <code><strong>history show</strong></code>
7935 Displays the current history buffer to standard output.
7941 <h3 id="_namespace
">namespace</h3>
7942 <div class="paragraph
"><p>Provides namespace-related functions. See also: <a href="http://www.tcl.tk/man/tcl8.6/TclCmd/namespace.htm
">http://www.tcl.tk/man/tcl8.6/TclCmd/namespace.htm</a></p></div>
7943 <div class="dlist
"><dl>
7944 <dt class="hdlist1
">
7945 <code><strong>namespace code</strong> <em>script</em></code>
7949 Captures the current namespace context for later execution of
7950 the script <code><em>script</em></code>. It returns a new script in which script has
7951 been wrapped in a <code><strong>namespace inscope</strong></code> command.
7954 <dt class="hdlist1
">
7955 <code><strong>namespace current</strong></code>
7959 Returns the fully-qualified name for the current namespace.
7962 <dt class="hdlist1
">
7963 <code><strong>namespace delete</strong> <em>?namespace …?</em></code>
7967 Deletes all commands and variables with the given namespace prefixes.
7970 <dt class="hdlist1
">
7971 <code><strong>namespace eval</strong> <em>namespace arg ?arg…?</em></code>
7975 Activates a namespace called <code><em>namespace</em></code> and evaluates some code in that context.
7978 <dt class="hdlist1
">
7979 <code><strong>namespace origin</strong> <em>command</em></code>
7983 Returns the fully-qualified name of the original command to which the imported command <code><em>command</em></code> refers.
7986 <dt class="hdlist1
">
7987 <code><strong>namespace parent</strong> ?namespace?</code>
7991 Returns the fully-qualified name of the parent namespace for namespace <code><em>namespace</em></code>, if given, otherwise
7992 for the current namespace.
7995 <dt class="hdlist1
">
7996 <code><strong>namespace qualifiers</strong> <em>string</em></code>
8000 Returns any leading namespace qualifiers for <code><em>string</em></code>
8003 <dt class="hdlist1
">
8004 <code><strong>namespace tail</strong> <em>string</em></code>
8008 Returns the simple name at the end of a qualified string.
8011 <dt class="hdlist1
">
8012 <code><strong>namespace upvar</strong> <em>namespace ?arg…?</em></code>
8016 This command arranges for zero or more local variables in the current procedure to refer to variables in <code><em>namespace</em></code>
8019 <dt class="hdlist1
">
8020 <code><strong>namespace which</strong> <em>?-command|-variable? name</em></code>
8024 Looks up <code><em>name</em></code> as either a command (the default) or variable and returns its fully-qualified name.
8030 <h3 id="_interp
">interp</h3>
8031 <div class="paragraph
"><p>The optional <em>interp</em> command allows sub-interpreters to be created where commands may be run
8032 independently (but synchronously) of the main interpreter.</p></div>
8033 <div class="dlist
"><dl>
8034 <dt class="hdlist1
">
8035 <code><strong>interp</strong></code>
8039 Creates and returns a new interpreter object (command).
8040 The created interpeter contains any built-in commands along with static extensions,
8041 but does not include any dynamically loaded commands (package require, load).
8042 These must be reloaded in the child interpreter if required.
8045 <dt class="hdlist1
">
8046 <code><strong>$interp delete</strong></code>
8050 Deletes the interpeter object.
8053 <dt class="hdlist1
">
8054 <code><strong>$interp eval</strong> <em>script</em> …</code>
8058 Evaluates a script in the context for the child interpreter, in the same way as <em>eval</em>.
8061 <dt class="hdlist1
">
8062 <code><strong>$interp alias</strong> <em>alias childcmd parentcmd ?arg …?</em></code>
8066 Similar to <em>alias</em>, but creates a command, <code><em>childcmd</em></code>, in the child interpreter that is an
8067 alias for <code><em>parentcmd</em></code> in the parent interpreter, with the given, fixed arguments.
8068 The alias may be deleted in the child with <em>rename</em>.
8074 <h3 id="_json_encode
">json::encode</h3>
8075 <div class="paragraph
"><p>The Tcl → JSON encoder is part of the optional <em>json</em> package.</p></div>
8076 <div class="dlist
"><dl>
8077 <dt class="hdlist1
">
8078 <code><strong>json::encode</strong> <em>value ?schema?</em></code>
8082 Encode a Tcl value as JSON according to the schema (defaults to <code><em>str</em></code>). The following schema types are supported:
8084 <div class="ulist
"><ul>
8087 <em>str</em> - Tcl string → JSON string
8092 <em>num</em> - Tcl value → bare numeric value or null
8097 <em>bool</em> - Tcl boolean value → true, false
8102 <em>obj ?name subschema …?</em> - Tcl dict → JSON object. For each dict key matching <em>name</em>, the corresponding <em>subschema</em>
8103 is applied. The special name <code><em>*</em></code> matches any keys not otherwise matched, otherwise the default <code><em>str</em></code> is used.
8108 <em>list ?subschema?</em> - Tcl list → JSON array. The <em>subschema</em> (default <code><em>str</em></code>) is applied for each element of the list/array.
8113 <em>mixed ?subschema …?</em> = Tcl list → JSON array. Each <em>subschema</em> is applied for the corresponding element of the list/array.
8118 <dt class="hdlist1
">
8123 The following are examples:
8127 <div class="listingblock
">
8128 <div class="content
">
8129 <pre><code> . json::encode {1 2 true false null 5.0} list
8130 [ "1", "2", "true
", "false
", "null
", "5.0" ]
8131 . json::encode {1 2 true false null 5.0} {list num}
8132 [ 1, 2, true, false, null, 5.0 ]
8133 . json::encode {0 1 2 true false 5.0 off} {list bool}
8134 [ false, true, true, true, false, true, false ]
8135 . json::encode {a 1 b hello c {3 4}} obj
8136 { "a
":"1", "b
":"hello
", "c
":"3 4" }
8137 . json::encode {a 1 b hello c {3 4}} {obj a num c {list num}}
8138 { "a
":1, "b
":"hello
", "c
":[ 3, 4 ] }
8139 . json::encode {true true {abc def}} {mixed str num obj}
8140 [ "true
", true, { "abc
":"def
" } ]
8141 . json::encode {a 1 b 3.0 c hello d null} {obj c str * num}
8142 { "a
":1, "b
":3.0, "c
":"hello
", "d
":null }</code></pre>
8146 <h3 id="_json_decode
">json::decode</h3>
8147 <div class="paragraph
"><p>The JSON → Tcl decoder is part of the optional <em>json</em> package.</p></div>
8148 <div class="dlist
"><dl>
8149 <dt class="hdlist1
">
8150 <code><strong>json::decode</strong> ?<strong>-index</strong>? ?<strong>-null</strong> <em>string</em>? ?<strong>-schema</strong>? <em>json-string</em></code>
8154 Decodes the given JSON string (must be array or object) into a Tcl data structure. If <em><code>-index</code></em> is specified,
8155 decodes JSON arrays as dictionaries with numeric keys. This makes it possible to retrieve data from nested
8156 arrays and dictionaries with just <em><code>dict get</code></em>. With the option <em><code>-schema</code></em> returns a list of <code><em>{data schema}</em></code>
8157 where the schema is compatible with <a href="#_json_encode
"><strong><code>json::encode</code></strong></a>. Otherwise just returns the data.
8158 Decoding is as follows (with schema types listed in parentheses):
8160 <div class="ulist
"><ul>
8163 object → dict (<em>obj</em>)
8168 array → list (<em>mixed</em> or <em>list</em>)
8173 number → as-is (<em>num</em>)
8178 boolean → as-is (<em>bool</em>)
8183 string → string (<em>str</em>)
8188 null → supplied null string or the default <code><em>"null
"</em></code> (<em>num</em>)
8193 <dt class="hdlist1
">
8198 Note that an object decoded into a dict will return the keys in the same order as the original string.
8202 <div class="listingblock
">
8203 <div class="content
">
8204 <pre><code> . json::decode {[1, 2]}
8206 . json::decode -schema {[1, 2]}
8208 . json::decode -schema {{"a
":1, "b
":2}}
8209 {a 1 b 2} {obj a num b num}
8210 . json::decode -schema {[1, 2, {a:"b
", c:false}, "hello
"]}
8211 {1 2 {a b c false} hello} {mixed num num {obj a str c bool} str}
8212 . json::decode -index {["foo
", "bar
"]}
8213 {0 foo 1 bar}</code></pre>
8219 <h2 id="BuiltinVariables
">BUILT-IN VARIABLES</h2>
8220 <div class="sectionbody
">
8221 <div class="paragraph
"><p>The following global variables are created automatically
8222 by the Tcl library.</p></div>
8223 <div class="dlist
"><dl>
8224 <dt class="hdlist1
">
8225 <code><strong>env</strong></code>
8229 This variable is set by Jim as an array
8230 whose elements are the environment variables for the process.
8231 Reading an element will return the value of the corresponding
8232 environment variable.
8233 This array is initialised at startup from the <a href="#_env
"><strong><code>env</code></strong></a> command.
8234 It may be modified and will affect the environment passed to
8235 commands invoked with <a href="#_exec
"><strong><code>exec</code></strong></a>.
8238 <dt class="hdlist1
">
8239 <code><strong>platform_tcl</strong></code>
8243 This variable is set by Jim as an array containing information
8244 about the platform on which Jim was built. Currently this includes
8245 <em>os</em> and <em>platform</em>.
8248 <dt class="hdlist1
">
8249 <code><strong>auto_path</strong></code>
8253 This variable contains a list of paths to search for packages.
8254 It defaults to a location based on where jim is installed
8255 (e.g. <code>/usr/local/lib/jim</code>), but may be changed by <code>jimsh</code>
8256 or the embedding application. Note that <code>jimsh</code> will consider
8257 the environment variable <code>$JIMLIB</code> to be a list of colon-separated
8258 list of paths to add to <code><strong>auto_path</strong></code>.
8261 <dt class="hdlist1
">
8262 <code><strong>errorCode</strong></code>
8266 This variable holds the value of the -errorcode return
8267 option set by the most recent error that occurred in this
8268 interpreter. This list value represents additional information
8269 about the error in a form that is easy to process with
8270 programs. The first element of the list identifies a general
8271 class of errors, and determines the format of the rest of
8272 the list. The following formats for -errorcode return options
8273 are used by the Tcl core; individual applications may define
8274 additional formats. Currently only <a href="#_exec
"><strong><code>exec</code></strong></a> sets this variable.
8275 Otherwise it will be <code>NONE</code>.
8279 <div class="paragraph
"><p>The following global variables are set by jimsh.</p></div>
8280 <div class="dlist
"><dl>
8281 <dt class="hdlist1
">
8282 <code><strong>tcl_interactive</strong></code>
8286 This variable is set to 1 if jimsh is started in interactive mode
8290 <dt class="hdlist1
">
8291 <code><strong>tcl_platform</strong></code>
8295 This variable is set by Jim as an array containing information
8296 about the platform upon which Jim was built. The following is an
8297 example of the contents of this array.
8301 <div class="listingblock
">
8302 <div class="content
">
8303 <pre><code> tcl_platform(byteOrder) = littleEndian
8304 tcl_platform(engine) = Jim
8305 tcl_platform(os) = Darwin
8306 tcl_platform(platform) = unix
8307 tcl_platform(pointerSize) = 8
8308 tcl_platform(threaded) = 0
8309 tcl_platform(wordSize) = 8
8310 tcl_platform(pathSeparator) = :</code></pre>
8312 <div class="dlist
"><dl>
8313 <dt class="hdlist1
">
8314 <code><strong>argv0</strong></code>
8318 If jimsh is invoked to run a script, this variable contains the name
8322 <dt class="hdlist1
">
8323 <code><strong>argv</strong></code>
8327 If jimsh is invoked to run a script, this variable contains a list
8328 of any arguments supplied to the script.
8331 <dt class="hdlist1
">
8332 <code><strong>argc</strong></code>
8336 If jimsh is invoked to run a script, this variable contains the number
8337 of arguments supplied to the script.
8340 <dt class="hdlist1
">
8341 <code><strong>jim::argv0</strong></code>
8345 The value of argv[0] when jimsh was invoked.
8349 <div class="paragraph
"><p>The following variables have special meaning to Jim Tcl:</p></div>
8350 <div class="dlist
"><dl>
8351 <dt class="hdlist1
">
8352 <code><strong>jim::defer</strong></code>
8356 If this variable is set, it is considered to be a list of scripts to evaluate
8357 when the current proc exits (local variables), or the interpreter exits (global variable).
8358 See <a href="#_defer
"><strong><code>defer</code></strong></a>.
8361 <dt class="hdlist1
">
8362 <code><strong>history::multiline</strong></code>
8366 If this variable is set to "1", interactive line editing operates in multiline mode.
8367 That is, long lines will wrap across multiple lines rather than scrolling within a
8375 <h2 id="_changes_in_previous_releases
">CHANGES IN PREVIOUS RELEASES</h2>
8376 <div class="sectionbody
">
8378 <h3 id="_in_v0_74
">In v0.74</h3>
8379 <div class="olist arabic
"><ol class="arabic
">
8382 Numbers with leading zeros are treated as decimal, not octal
8387 Add <a href="#_aio
"><strong><code>aio</code></strong></a> <code>isatty</code>
8392 Add LFS (64 bit) support for <a href="#_aio
"><strong><code>aio</code></strong></a> <code>seek</code>, <a href="#_aio
"><strong><code>aio</code></strong></a> <code>tell</code>, <a href="#_aio
"><strong><code>aio</code></strong></a> <code>copyto</code>, <a href="#_file
"><strong><code>file</code></strong></a> <code>copy</code>
8397 <a href="#_string
"><strong><code>string</code></strong></a> <code>compare</code> and <a href="#_string
"><strong><code>string</code></strong></a> <code>equal</code> now support <em>-length</em>
8402 <a href="#_glob
"><strong><code>glob</code></strong></a> now supports <em>-directory</em>
8408 <h3 id="_in_v0_73
">In v0.73</h3>
8409 <div class="olist arabic
"><ol class="arabic
">
8412 Built-in regexp now support non-capturing parentheses: (?:…)
8417 Add <a href="#_string
"><strong><code>string</code></strong></a> <code>replace</code>
8422 Add <a href="#_string
"><strong><code>string</code></strong></a> <code>totitle</code>
8427 Add <a href="#_info
"><strong><code>info</code></strong></a> <code>statics</code>
8432 Add <code>build-jim-ext</code> for easy separate building of loadable modules (extensions)
8437 <a href="#_local
"><strong><code>local</code></strong></a> now works with any command, not just procs
8442 Add <a href="#_info
"><strong><code>info</code></strong></a> <code>alias</code> to access the target of an alias
8447 UTF-8 encoding past the basic multilingual plane (BMP) is supported
8452 Add <a href="#_tcl_prefix
"><strong><code>tcl::prefix</code></strong></a>
8457 Add <a href="#_history
"><strong><code>history</code></strong></a>
8462 Most extensions are now enabled by default
8467 Add support for namespaces and the <a href="#_namespace
"><strong><code>namespace</code></strong></a> command
8472 Add <a href="#_apply
"><strong><code>apply</code></strong></a>
8478 <h3 id="_in_v0_72
">In v0.72</h3>
8479 <div class="olist arabic
"><ol class="arabic
">
8482 procs now allow <em>args</em> and optional parameters in any position
8487 Add Tcl-compatible expr functions, <code>rand()</code>, <code>srand()</code> and <code>pow()</code>
8492 Add support for the <em>-force</em> option to <a href="#_file
"><strong><code>file</code></strong></a> <code>delete</code>
8497 Better diagnostics when <a href="#_source
"><strong><code>source</code></strong></a> fails to load a script with a missing quote or bracket
8502 New <code>tcl_platform(pathSeparator)</code>
8507 Add support settings the modification time with <a href="#_file
"><strong><code>file</code></strong></a> <code>mtime</code>
8512 <a href="#_exec
"><strong><code>exec</code></strong></a> is now fully supported on win32 (mingw32)
8517 <a href="#_file
"><strong><code>file</code></strong></a> <code>join</code>, <a href="#_pwd
"><strong><code>pwd</code></strong></a>, <a href="#_glob
"><strong><code>glob</code></strong></a> etc. now work for mingw32
8522 Line editing is now supported for the win32 console (mingw32)
8527 Add <a href="#_aio
"><strong><code>aio</code></strong></a> <code>listen</code> command
8533 <h3 id="_in_v0_71
">In v0.71</h3>
8534 <div class="olist arabic
"><ol class="arabic
">
8537 Allow <em>args</em> to be renamed in procs
8542 Add <code>$(…)</code> shorthand syntax for expressions
8547 Add automatic reference variables in procs with <code>&var</code> syntax
8552 Support <code>jimsh --version</code>
8557 Additional variables in <code>tcl_platform()</code>
8562 <a href="#_local
"><strong><code>local</code></strong></a> procs now push existing commands and <a href="#_upcall
"><strong><code>upcall</code></strong></a> can call them
8567 Add <a href="#_loop
"><strong><code>loop</code></strong></a> command (TclX compatible)
8572 Add <a href="#_aio
"><strong><code>aio</code></strong></a> <code>buffering</code> command
8577 <a href="#_info
"><strong><code>info</code></strong></a> <code>complete</code> can now return the missing character
8582 <a href="#_binary
"><strong><code>binary</code></strong></a> <code>format</code> and <a href="#_binary
"><strong><code>binary</code></strong></a> <code>scan</code> are now (optionally) supported
8587 Add <a href="#_string
"><strong><code>string</code></strong></a> <code>byterange</code>
8592 Built-in regexp now support non-greedy repetition (*?, +?, ??)
8598 <h3 id="_in_v0_70
">In v0.70</h3>
8599 <div class="olist arabic
"><ol class="arabic
">
8602 <code>platform_tcl()</code> settings are now automatically determined
8607 Add aio <code>$handle filename</code>
8612 Add <a href="#_info
"><strong><code>info</code></strong></a> <code>channels</code>
8617 The <em>bio</em> extension is gone. Now <a href="#_aio
"><strong><code>aio</code></strong></a> supports <em>copyto</em>.
8622 Add <a href="#_exists
"><strong><code>exists</code></strong></a> command
8627 Add the pure-Tcl <em>oo</em> extension
8632 The <a href="#_exec
"><strong><code>exec</code></strong></a> command now only uses vfork(), not fork()
8637 Unit test framework is less verbose and more Tcl-compatible
8642 Optional UTF-8 support
8647 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
8652 Command line editing in interactive mode, e.g. <em>jimsh</em>
8658 <h3 id="_in_v0_63
">In v0.63</h3>
8659 <div class="olist arabic
"><ol class="arabic
">
8662 <a href="#_source
"><strong><code>source</code></strong></a> now checks that a script is complete (.i.e. not missing a brace)
8667 <em>info complete</em> now uses the real parser and so is 100% accurate
8672 Better access to live stack frames with <em>info frame</em>, <a href="#_stacktrace
"><strong><code>stacktrace</code></strong></a> and <a href="#_stackdump
"><strong><code>stackdump</code></strong></a>
8677 <a href="#_tailcall
"><strong><code>tailcall</code></strong></a> no longer loses stack trace information
8682 Add <a href="#_alias
"><strong><code>alias</code></strong></a> and <a href="#_curry
"><strong><code>curry</code></strong></a>
8687 <a href="#_lambda
"><strong><code>lambda</code></strong></a>, <a href="#_alias
"><strong><code>alias</code></strong></a> and <a href="#_curry
"><strong><code>curry</code></strong></a> are implemented via <a href="#_tailcall
"><strong><code>tailcall</code></strong></a> for efficiency
8692 <a href="#_local
"><strong><code>local</code></strong></a> allows procedures to be deleted automatically at the end of the current procedure
8697 udp sockets are now supported for both clients and servers.
8702 vfork-based exec is now working correctly
8707 Add <em>file tempfile</em>
8712 Add <em>socket pipe</em>
8717 Enhance <em>try … on … finally</em> to be more Tcl 8.6 compatible
8722 It is now possible to <a href="#_return
"><strong><code>return</code></strong></a> from within <a href="#_try
"><strong><code>try</code></strong></a>
8727 IPv6 support is now included
8732 Add <em>string is</em>
8737 Event handlers works better if an error occurs. eof handler has been removed.
8742 <a href="#_exec
"><strong><code>exec</code></strong></a> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
8747 Command pipelines via open "|
…" are now supported
8752 <a href="#_pid
"><strong><code>pid</code></strong></a> can now return pids of a command pipeline
8757 Add <em>info references</em>
8762 Add support for <em>after <code>'ms</em></code><em>, 'after idle</em>, <em>after info</em>, <a href="#cmd_2
"><strong><code>update</code></strong></a>
8767 <a href="#_exec
"><strong><code>exec</code></strong></a> now sets environment based on $::env
8772 Add <em>dict keys</em>
8777 Add support for <em>lsort -index</em>
8783 <h3 id="_in_v0_62
">In v0.62</h3>
8784 <div class="olist arabic
"><ol class="arabic
">
8787 Add support to <a href="#_exec
"><strong><code>exec</code></strong></a> for <em>>&</em>, <em>>>&</em>, <em>|&</em>, <em>2>@1</em>
8792 Fix <a href="#_exec
"><strong><code>exec</code></strong></a> error messages when special token (e.g. <em>></em>) is the last token
8797 Fix <a href="#_subst
"><strong><code>subst</code></strong></a> handling of backslash escapes.
8802 Allow abbreviated options for <a href="#_subst
"><strong><code>subst</code></strong></a>
8807 Add support for <a href="#_return
"><strong><code>return</code></strong></a>, <a href="#_break
"><strong><code>break</code></strong></a>, <a href="#_continue
"><strong><code>continue</code></strong></a> in subst
8812 Many <a href="#_expr
"><strong><code>expr</code></strong></a> bug fixes
8817 Add support for functions in <a href="#_expr
"><strong><code>expr</code></strong></a> (e.g. int(), abs()), and also <em>in</em>, <em>ni</em> list operations
8822 The variable name argument to <a href="#_regsub
"><strong><code>regsub</code></strong></a> is now optional
8827 Add support for <em>unset -nocomplain</em>
8832 Add support for list commands: <a href="#_lassign
"><strong><code>lassign</code></strong></a>, <a href="#_lrepeat
"><strong><code>lrepeat</code></strong></a>
8837 Fully-functional <a href="#_lsearch
"><strong><code>lsearch</code></strong></a> is now implemented
8842 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
8847 Allow <a href="#_catch
"><strong><code>catch</code></strong></a> to determine what return codes are caught
8852 Allow <a href="#_incr
"><strong><code>incr</code></strong></a> to increment an unset variable by first setting to 0
8857 Allow <em>args</em> and optional arguments to the left or required arguments in <a href="#_proc
"><strong><code>proc</code></strong></a>
8862 Add <em>file copy</em>
8867 Add <em>try … finally</em> command
8875 <h2 id="_licence
">LICENCE</h2>
8876 <div class="sectionbody
">
8877 <div class="literalblock
">
8878 <div class="content
">
8879 <pre><code>Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
8880 Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
8881 Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
8882 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
8883 Copyright 2008 Andrew Lunn <andrew@lunn.ch>
8884 Copyright 2008 Duane Ellis <openocd@duaneellis.com>
8885 Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
8886 Copyright 2009 Steve Bennett <steveb@workware.net.au></code></pre>
8888 <div class="literalblock
">
8889 <div class="content
">
8890 <pre><code>Redistribution and use in source and binary forms, with or without
8891 modification, are permitted provided that the following conditions
8893 1. Redistributions of source code must retain the above copyright
8894 notice, this list of conditions and the following disclaimer.
8895 2. Redistributions in binary form must reproduce the above
8896 copyright notice, this list of conditions and the following
8897 disclaimer in the documentation and/or other materials
8898 provided with the distribution.</code></pre>
8900 <div class="literalblock
">
8901 <div class="content
">
8902 <pre><code>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
8903 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8904 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
8905 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
8906 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8907 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8908 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8909 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8910 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8911 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8912 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
8913 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</code></pre>
8915 <div class="literalblock
">
8916 <div class="content
">
8917 <pre><code>The views and conclusions contained in the software and documentation
8918 are those of the authors and should not be interpreted as representing
8919 official policies, either expressed or implied, of the Jim Tcl Project.</code></pre>
8924 <div id="footnotes
"><hr /></div>