tcltest: do a better job of cleanup up after tests
[jimtcl.git] / Tcl_shipped.html
blob5e289f8932aa49bdeacbf93337fb167821586f95
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
6 <meta name="generator" content="AsciiDoc 8.6.9" />
7 <title>Jim Tcl(n)</title>
8 <style type="text/css">
9 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
11 /* Default font. */
12 body {
13 font-family: Georgia,serif;
16 /* Title font. */
17 h1, h2, h3, h4, h5, h6,
18 div.title, caption.title,
19 thead, p.table.header,
20 #toctitle,
21 #author, #revnumber, #revdate, #revremark,
22 #footer {
23 font-family: Arial,Helvetica,sans-serif;
26 body {
27 margin: 1em 5% 1em 5%;
30 a {
31 color: blue;
32 text-decoration: underline;
34 a:visited {
35 color: fuchsia;
38 em {
39 font-style: italic;
40 color: navy;
43 strong {
44 font-weight: bold;
45 color: #083194;
48 h1, h2, h3, h4, h5, h6 {
49 color: #527bbd;
50 margin-top: 1.2em;
51 margin-bottom: 0.5em;
52 line-height: 1.3;
55 h1, h2, h3 {
56 border-bottom: 2px solid silver;
58 h2 {
59 padding-top: 0.5em;
61 h3 {
62 float: left;
64 h3 + * {
65 clear: left;
67 h5 {
68 font-size: 1.0em;
71 div.sectionbody {
72 margin-left: 0;
75 hr {
76 border: 1px solid silver;
79 p {
80 margin-top: 0.5em;
81 margin-bottom: 0.5em;
84 ul, ol, li > p {
85 margin-top: 0;
87 ul > li { color: #aaa; }
88 ul > li > * { color: black; }
90 .monospaced, code, pre {
91 font-family: "Courier New", Courier, monospace;
92 font-size: inherit;
93 color: navy;
94 padding: 0;
95 margin: 0;
97 pre {
98 white-space: pre-wrap;
101 #author {
102 color: #527bbd;
103 font-weight: bold;
104 font-size: 1.1em;
106 #email {
108 #revnumber, #revdate, #revremark {
111 #footer {
112 font-size: small;
113 border-top: 2px solid silver;
114 padding-top: 0.5em;
115 margin-top: 4.0em;
117 #footer-text {
118 float: left;
119 padding-bottom: 0.5em;
121 #footer-badges {
122 float: right;
123 padding-bottom: 0.5em;
126 #preamble {
127 margin-top: 1.5em;
128 margin-bottom: 1.5em;
130 div.imageblock, div.exampleblock, div.verseblock,
131 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
132 div.admonitionblock {
133 margin-top: 1.0em;
134 margin-bottom: 1.5em;
136 div.admonitionblock {
137 margin-top: 2.0em;
138 margin-bottom: 2.0em;
139 margin-right: 10%;
140 color: #606060;
143 div.content { /* Block element content. */
144 padding: 0;
147 /* Block element titles. */
148 div.title, caption.title {
149 color: #527bbd;
150 font-weight: bold;
151 text-align: left;
152 margin-top: 1.0em;
153 margin-bottom: 0.5em;
155 div.title + * {
156 margin-top: 0;
159 td div.title:first-child {
160 margin-top: 0.0em;
162 div.content div.title:first-child {
163 margin-top: 0.0em;
165 div.content + div.title {
166 margin-top: 0.0em;
169 div.sidebarblock > div.content {
170 background: #ffffee;
171 border: 1px solid #dddddd;
172 border-left: 4px solid #f0f0f0;
173 padding: 0.5em;
176 div.listingblock > div.content {
177 border: 1px solid #dddddd;
178 border-left: 5px solid #f0f0f0;
179 background: #f8f8f8;
180 padding: 0.5em;
183 div.quoteblock, div.verseblock {
184 padding-left: 1.0em;
185 margin-left: 1.0em;
186 margin-right: 10%;
187 border-left: 5px solid #f0f0f0;
188 color: #888;
191 div.quoteblock > div.attribution {
192 padding-top: 0.5em;
193 text-align: right;
196 div.verseblock > pre.content {
197 font-family: inherit;
198 font-size: inherit;
200 div.verseblock > div.attribution {
201 padding-top: 0.75em;
202 text-align: left;
204 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
205 div.verseblock + div.attribution {
206 text-align: left;
209 div.admonitionblock .icon {
210 vertical-align: top;
211 font-size: 1.1em;
212 font-weight: bold;
213 text-decoration: underline;
214 color: #527bbd;
215 padding-right: 0.5em;
217 div.admonitionblock td.content {
218 padding-left: 0.5em;
219 border-left: 3px solid #dddddd;
222 div.exampleblock > div.content {
223 border-left: 3px solid #dddddd;
224 padding-left: 0.5em;
227 div.imageblock div.content { padding-left: 0; }
228 span.image img { border-style: none; vertical-align: text-bottom; }
229 a.image:visited { color: white; }
231 dl {
232 margin-top: 0.8em;
233 margin-bottom: 0.8em;
235 dt {
236 margin-top: 0.5em;
237 margin-bottom: 0;
238 font-style: normal;
239 color: navy;
241 dd > *:first-child {
242 margin-top: 0.1em;
245 ul, ol {
246 list-style-position: outside;
248 ol.arabic {
249 list-style-type: decimal;
251 ol.loweralpha {
252 list-style-type: lower-alpha;
254 ol.upperalpha {
255 list-style-type: upper-alpha;
257 ol.lowerroman {
258 list-style-type: lower-roman;
260 ol.upperroman {
261 list-style-type: upper-roman;
264 div.compact ul, div.compact ol,
265 div.compact p, div.compact p,
266 div.compact div, div.compact div {
267 margin-top: 0.1em;
268 margin-bottom: 0.1em;
271 tfoot {
272 font-weight: bold;
274 td > div.verse {
275 white-space: pre;
278 div.hdlist {
279 margin-top: 0.8em;
280 margin-bottom: 0.8em;
282 div.hdlist tr {
283 padding-bottom: 15px;
285 dt.hdlist1.strong, td.hdlist1.strong {
286 font-weight: bold;
288 td.hdlist1 {
289 vertical-align: top;
290 font-style: normal;
291 padding-right: 0.8em;
292 color: navy;
294 td.hdlist2 {
295 vertical-align: top;
297 div.hdlist.compact tr {
298 margin: 0;
299 padding-bottom: 0;
302 .comment {
303 background: yellow;
306 .footnote, .footnoteref {
307 font-size: 0.8em;
310 span.footnote, span.footnoteref {
311 vertical-align: super;
314 #footnotes {
315 margin: 20px 0 20px 0;
316 padding: 7px 0 0 0;
319 #footnotes div.footnote {
320 margin: 0 0 5px 0;
323 #footnotes hr {
324 border: none;
325 border-top: 1px solid silver;
326 height: 1px;
327 text-align: left;
328 margin-left: 0;
329 width: 20%;
330 min-width: 100px;
333 div.colist td {
334 padding-right: 0.5em;
335 padding-bottom: 0.3em;
336 vertical-align: top;
338 div.colist td img {
339 margin-top: 0.3em;
342 @media print {
343 #footer-badges { display: none; }
346 #toc {
347 margin-bottom: 2.5em;
350 #toctitle {
351 color: #527bbd;
352 font-size: 1.1em;
353 font-weight: bold;
354 margin-top: 1.0em;
355 margin-bottom: 0.1em;
358 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
359 margin-top: 0;
360 margin-bottom: 0;
362 div.toclevel2 {
363 margin-left: 2em;
364 font-size: 0.9em;
366 div.toclevel3 {
367 margin-left: 4em;
368 font-size: 0.9em;
370 div.toclevel4 {
371 margin-left: 6em;
372 font-size: 0.9em;
375 span.aqua { color: aqua; }
376 span.black { color: black; }
377 span.blue { color: blue; }
378 span.fuchsia { color: fuchsia; }
379 span.gray { color: gray; }
380 span.green { color: green; }
381 span.lime { color: lime; }
382 span.maroon { color: maroon; }
383 span.navy { color: navy; }
384 span.olive { color: olive; }
385 span.purple { color: purple; }
386 span.red { color: red; }
387 span.silver { color: silver; }
388 span.teal { color: teal; }
389 span.white { color: white; }
390 span.yellow { color: yellow; }
392 span.aqua-background { background: aqua; }
393 span.black-background { background: black; }
394 span.blue-background { background: blue; }
395 span.fuchsia-background { background: fuchsia; }
396 span.gray-background { background: gray; }
397 span.green-background { background: green; }
398 span.lime-background { background: lime; }
399 span.maroon-background { background: maroon; }
400 span.navy-background { background: navy; }
401 span.olive-background { background: olive; }
402 span.purple-background { background: purple; }
403 span.red-background { background: red; }
404 span.silver-background { background: silver; }
405 span.teal-background { background: teal; }
406 span.white-background { background: white; }
407 span.yellow-background { background: yellow; }
409 span.big { font-size: 2em; }
410 span.small { font-size: 0.6em; }
412 span.underline { text-decoration: underline; }
413 span.overline { text-decoration: overline; }
414 span.line-through { text-decoration: line-through; }
416 div.unbreakable { page-break-inside: avoid; }
420 * xhtml11 specific
422 * */
424 div.tableblock {
425 margin-top: 1.0em;
426 margin-bottom: 1.5em;
428 div.tableblock > table {
429 border: 3px solid #527bbd;
431 thead, p.table.header {
432 font-weight: bold;
433 color: #527bbd;
435 p.table {
436 margin-top: 0;
438 /* Because the table frame attribute is overriden by CSS in most browsers. */
439 div.tableblock > table[frame="void"] {
440 border-style: none;
442 div.tableblock > table[frame="hsides"] {
443 border-left-style: none;
444 border-right-style: none;
446 div.tableblock > table[frame="vsides"] {
447 border-top-style: none;
448 border-bottom-style: none;
453 * html5 specific
455 * */
457 table.tableblock {
458 margin-top: 1.0em;
459 margin-bottom: 1.5em;
461 thead, p.tableblock.header {
462 font-weight: bold;
463 color: #527bbd;
465 p.tableblock {
466 margin-top: 0;
468 table.tableblock {
469 border-width: 3px;
470 border-spacing: 0px;
471 border-style: solid;
472 border-color: #527bbd;
473 border-collapse: collapse;
475 th.tableblock, td.tableblock {
476 border-width: 1px;
477 padding: 4px;
478 border-style: solid;
479 border-color: #527bbd;
482 table.tableblock.frame-topbot {
483 border-left-style: hidden;
484 border-right-style: hidden;
486 table.tableblock.frame-sides {
487 border-top-style: hidden;
488 border-bottom-style: hidden;
490 table.tableblock.frame-none {
491 border-style: hidden;
494 th.tableblock.halign-left, td.tableblock.halign-left {
495 text-align: left;
497 th.tableblock.halign-center, td.tableblock.halign-center {
498 text-align: center;
500 th.tableblock.halign-right, td.tableblock.halign-right {
501 text-align: right;
504 th.tableblock.valign-top, td.tableblock.valign-top {
505 vertical-align: top;
507 th.tableblock.valign-middle, td.tableblock.valign-middle {
508 vertical-align: middle;
510 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
511 vertical-align: bottom;
516 * manpage specific
518 * */
520 body.manpage h1 {
521 padding-top: 0.5em;
522 padding-bottom: 0.5em;
523 border-top: 2px solid silver;
524 border-bottom: 2px solid silver;
526 body.manpage h2 {
527 border-style: none;
529 body.manpage div.sectionbody {
530 margin-left: 3em;
533 @media print {
534 body.manpage div#toc { display: none; }
538 </style>
539 <script type="text/javascript">
540 /*<![CDATA[*/
541 var asciidoc = { // Namespace.
543 /////////////////////////////////////////////////////////////////////
544 // Table Of Contents generator
545 /////////////////////////////////////////////////////////////////////
547 /* Author: Mihai Bazon, September 2002
548 * http://students.infoiasi.ro/~mishoo
550 * Table Of Content generator
551 * Version: 0.4
553 * Feel free to use this script under the terms of the GNU General Public
554 * License, as long as you do not remove or alter this notice.
557 /* modified by Troy D. Hanson, September 2006. License: GPL */
558 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
560 // toclevels = 1..4.
561 toc: function (toclevels) {
563 function getText(el) {
564 var text = "";
565 for (var i = el.firstChild; i != null; i = i.nextSibling) {
566 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
567 text += i.data;
568 else if (i.firstChild != null)
569 text += getText(i);
571 return text;
574 function TocEntry(el, text, toclevel) {
575 this.element = el;
576 this.text = text;
577 this.toclevel = toclevel;
580 function tocEntries(el, toclevels) {
581 var result = new Array;
582 var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
583 // Function that scans the DOM tree for header elements (the DOM2
584 // nodeIterator API would be a better technique but not supported by all
585 // browsers).
586 var iterate = function (el) {
587 for (var i = el.firstChild; i != null; i = i.nextSibling) {
588 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
589 var mo = re.exec(i.tagName);
590 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
591 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
593 iterate(i);
597 iterate(el);
598 return result;
601 var toc = document.getElementById("toc");
602 if (!toc) {
603 return;
606 // Delete existing TOC entries in case we're reloading the TOC.
607 var tocEntriesToRemove = [];
608 var i;
609 for (i = 0; i < toc.childNodes.length; i++) {
610 var entry = toc.childNodes[i];
611 if (entry.nodeName.toLowerCase() == 'div'
612 && entry.getAttribute("class")
613 && entry.getAttribute("class").match(/^toclevel/))
614 tocEntriesToRemove.push(entry);
616 for (i = 0; i < tocEntriesToRemove.length; i++) {
617 toc.removeChild(tocEntriesToRemove[i]);
620 // Rebuild TOC entries.
621 var entries = tocEntries(document.getElementById("content"), toclevels);
622 for (var i = 0; i < entries.length; ++i) {
623 var entry = entries[i];
624 if (entry.element.id == "")
625 entry.element.id = "_toc_" + i;
626 var a = document.createElement("a");
627 a.href = "#" + entry.element.id;
628 a.appendChild(document.createTextNode(entry.text));
629 var div = document.createElement("div");
630 div.appendChild(a);
631 div.className = "toclevel" + entry.toclevel;
632 toc.appendChild(div);
634 if (entries.length == 0)
635 toc.parentNode.removeChild(toc);
639 /////////////////////////////////////////////////////////////////////
640 // Footnotes generator
641 /////////////////////////////////////////////////////////////////////
643 /* Based on footnote generation code from:
644 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
647 footnotes: function () {
648 // Delete existing footnote entries in case we're reloading the footnodes.
649 var i;
650 var noteholder = document.getElementById("footnotes");
651 if (!noteholder) {
652 return;
654 var entriesToRemove = [];
655 for (i = 0; i < noteholder.childNodes.length; i++) {
656 var entry = noteholder.childNodes[i];
657 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
658 entriesToRemove.push(entry);
660 for (i = 0; i < entriesToRemove.length; i++) {
661 noteholder.removeChild(entriesToRemove[i]);
664 // Rebuild footnote entries.
665 var cont = document.getElementById("content");
666 var spans = cont.getElementsByTagName("span");
667 var refs = {};
668 var n = 0;
669 for (i=0; i<spans.length; i++) {
670 if (spans[i].className == "footnote") {
671 n++;
672 var note = spans[i].getAttribute("data-note");
673 if (!note) {
674 // Use [\s\S] in place of . so multi-line matches work.
675 // Because JavaScript has no s (dotall) regex flag.
676 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
677 spans[i].innerHTML =
678 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
679 "' title='View footnote' class='footnote'>" + n + "</a>]";
680 spans[i].setAttribute("data-note", note);
682 noteholder.innerHTML +=
683 "<div class='footnote' id='_footnote_" + n + "'>" +
684 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
685 n + "</a>. " + note + "</div>";
686 var id =spans[i].getAttribute("id");
687 if (id != null) refs["#"+id] = n;
690 if (n == 0)
691 noteholder.parentNode.removeChild(noteholder);
692 else {
693 // Process footnoterefs.
694 for (i=0; i<spans.length; i++) {
695 if (spans[i].className == "footnoteref") {
696 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
697 href = href.match(/#.*/)[0]; // Because IE return full URL.
698 n = refs[href];
699 spans[i].innerHTML =
700 "[<a href='#_footnote_" + n +
701 "' title='View footnote' class='footnote'>" + n + "</a>]";
707 install: function(toclevels) {
708 var timerId;
710 function reinstall() {
711 asciidoc.footnotes();
712 if (toclevels) {
713 asciidoc.toc(toclevels);
717 function reinstallAndRemoveTimer() {
718 clearInterval(timerId);
719 reinstall();
722 timerId = setInterval(reinstall, 500);
723 if (document.addEventListener)
724 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
725 else
726 window.onload = reinstallAndRemoveTimer;
730 asciidoc.install();
731 /*]]>*/
732 </script>
733 </head>
734 <body class="manpage">
735 <div id="header">
736 <h1>
737 Jim Tcl(n) Manual Page
738 </h1>
739 <h2>NAME</h2>
740 <div class="sectionbody">
741 <p>Jim Tcl v0.77 -
742 reference manual for the Jim Tcl scripting language
743 </p>
744 </div>
745 </div>
746 <div id="content">
747 <div class="sect1">
748 <h2 id="_synopsis">SYNOPSIS</h2>
749 <div class="sectionbody">
750 <div class="literalblock">
751 <div class="content">
752 <pre><code>cc &lt;source&gt; -ljim</code></pre>
753 </div></div>
754 <div class="paragraph"><p>or</p></div>
755 <div class="literalblock">
756 <div class="content">
757 <pre><code>jimsh [&lt;scriptfile&gt;]
758 jimsh -e '&lt;immediate-script&gt;'
759 jimsh --version</code></pre>
760 </div></div>
761 <div class="ulist"><div class="title">Quick Index</div><ul>
762 <li>
764 <a href="#CommandIndex">Command Reference</a>
765 </p>
766 </li>
767 <li>
769 <a href="#OperatorPrecedence">Operator Precedence</a>
770 </p>
771 </li>
772 <li>
774 <a href="#BuiltinVariables">Builtin Variables</a>
775 </p>
776 </li>
777 <li>
779 <a href="#BackslashSequences">Backslash Sequences</a>
780 </p>
781 </li>
782 </ul></div>
783 </div>
784 </div>
785 <div class="sect1">
786 <h2 id="_introduction">INTRODUCTION</h2>
787 <div class="sectionbody">
788 <div class="paragraph"><p>Jim Tcl is a small footprint reimplementation of the Tcl scripting language.
789 The core language engine is compatible with Tcl 8.5+, while implementing
790 a significant subset of the Tcl 8.6 command set, plus additional features
791 available only in Jim Tcl.</p></div>
792 <div class="paragraph"><p>Some notable differences with Tcl 8.5/8.6 are:</p></div>
793 <div class="olist arabic"><ol class="arabic">
794 <li>
796 Object-based I/O (aio), but with a Tcl-compatibility layer
797 </p>
798 </li>
799 <li>
801 I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
802 </p>
803 </li>
804 <li>
806 Integers are 64bit
807 </p>
808 </li>
809 <li>
811 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
812 </p>
813 </li>
814 <li>
816 Builtin dictionary type (<a href="#_dict"><strong><code>dict</code></strong></a>) with some limitations compared to Tcl 8.6
817 </p>
818 </li>
819 <li>
821 <a href="#_env"><strong><code>env</code></strong></a> command to access environment variables
822 </p>
823 </li>
824 <li>
826 Operating system features: <a href="#cmd_1"><strong><code>os.fork</code></strong></a>, <a href="#cmd_1"><strong><code>os.wait</code></strong></a>, <a href="#cmd_1"><strong><code>os.uptime</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>
827 </p>
828 </li>
829 <li>
831 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>
832 </p>
833 </li>
834 <li>
836 Support for "static" variables in procedures
837 </p>
838 </li>
839 <li>
841 Threads and coroutines are not supported
842 </p>
843 </li>
844 <li>
846 Command and variable traces are not supported
847 </p>
848 </li>
849 <li>
851 Built-in command line editing
852 </p>
853 </li>
854 <li>
856 Expression shorthand syntax: <code>$(&#8230;)</code>
857 </p>
858 </li>
859 <li>
861 Modular build allows many features to be omitted or built as dynamic, loadable modules
862 </p>
863 </li>
864 <li>
866 Highly suitable for use in an embedded environment
867 </p>
868 </li>
869 <li>
871 Support for UDP, IPv6, Unix-Domain sockets in addition to TCP sockets
872 </p>
873 </li>
874 </ol></div>
875 </div>
876 </div>
877 <div class="sect1">
878 <h2 id="_recent_changes">RECENT CHANGES</h2>
879 <div class="sectionbody">
880 <div class="sect2">
881 <h3 id="_changes_between_0_76_and_0_77">Changes between 0.76 and 0.77</h3>
882 <div class="olist arabic"><ol class="arabic">
883 <li>
885 Add support for <a href="#_aio"><strong><code>aio</code></strong></a> <code>sync</code>
886 </p>
887 </li>
888 <li>
890 Add SSL and TLS support in aio
891 </p>
892 </li>
893 <li>
895 Added <a href="#_zlib"><strong><code>zlib</code></strong></a>
896 </p>
897 </li>
898 <li>
900 Added support for boolean constants in <a href="#_expr"><strong><code>expr</code></strong></a>
901 </p>
902 </li>
903 <li>
905 <a href="#_string"><strong><code>string</code></strong></a> <code>is</code> now supports <em>boolean</em> class
906 </p>
907 </li>
908 <li>
910 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>
911 </p>
912 </li>
913 <li>
915 Add new <a href="#_interp"><strong><code>interp</code></strong></a> command
916 </p>
917 </li>
918 </ol></div>
919 </div>
920 <div class="sect2">
921 <h3 id="_changes_between_0_75_and_0_76">Changes between 0.75 and 0.76</h3>
922 <div class="olist arabic"><ol class="arabic">
923 <li>
925 <a href="#_glob"><strong><code>glob</code></strong></a> now supports the <code>-tails</code> option
926 </p>
927 </li>
928 <li>
930 Add support for <a href="#_string"><strong><code>string</code></strong></a> <code>cat</code>
931 </p>
932 </li>
933 <li>
935 Allow <a href="#_info"><strong><code>info</code></strong></a> <code>source</code> to add source info
936 </p>
937 </li>
938 </ol></div>
939 </div>
940 <div class="sect2">
941 <h3 id="_changes_between_0_74_and_0_75">Changes between 0.74 and 0.75</h3>
942 <div class="olist arabic"><ol class="arabic">
943 <li>
945 <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
946 </p>
947 </li>
948 <li>
950 <a href="#_file"><strong><code>file</code></strong></a> <code>copy</code> <code>-force</code> handles source and target as the same file
951 </p>
952 </li>
953 <li>
955 <a href="#_format"><strong><code>format</code></strong></a> now supports <code>%b</code> for binary conversion
956 </p>
957 </li>
958 <li>
960 <a href="#_lsort"><strong><code>lsort</code></strong></a> now supports <code>-unique</code> and <code>-real</code>
961 </p>
962 </li>
963 <li>
965 Add support for half-close with <a href="#_aio"><strong><code>aio</code></strong></a> <code>close</code> <code>?r|w?</code>
966 </p>
967 </li>
968 <li>
970 Add <a href="#_socket"><strong><code>socket</code></strong></a> <code>pair</code> for a bidirectional pipe
971 </p>
972 </li>
973 <li>
975 Add <em>--random-hash</em> to randomise hash tables for greater security
976 </p>
977 </li>
978 <li>
980 <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>
981 </p>
982 </li>
983 <li>
985 <a href="#_file"><strong><code>file</code></strong></a> <code>stat</code> no longer requires the variable name
986 </p>
987 </li>
988 <li>
990 Add support for <a href="#_file"><strong><code>file</code></strong></a> <code>link</code>
991 </p>
992 </li>
993 </ol></div>
994 </div>
995 <div class="sect2">
996 <h3 id="_changes_between_0_73_and_0_74">Changes between 0.73 and 0.74</h3>
997 <div class="olist arabic"><ol class="arabic">
998 <li>
1000 Numbers with leading zeros are treated as decimal, not octal
1001 </p>
1002 </li>
1003 <li>
1005 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>isatty</code>
1006 </p>
1007 </li>
1008 <li>
1010 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>
1011 </p>
1012 </li>
1013 <li>
1015 <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>
1016 </p>
1017 </li>
1018 <li>
1020 <a href="#_glob"><strong><code>glob</code></strong></a> now supports <em>-directory</em>
1021 </p>
1022 </li>
1023 </ol></div>
1024 </div>
1025 <div class="sect2">
1026 <h3 id="_changes_between_0_72_and_0_73">Changes between 0.72 and 0.73</h3>
1027 <div class="olist arabic"><ol class="arabic">
1028 <li>
1030 Built-in regexp now support non-capturing parentheses: (?:&#8230;)
1031 </p>
1032 </li>
1033 <li>
1035 Add <a href="#_string"><strong><code>string</code></strong></a> <code>replace</code>
1036 </p>
1037 </li>
1038 <li>
1040 Add <a href="#_string"><strong><code>string</code></strong></a> <code>totitle</code>
1041 </p>
1042 </li>
1043 <li>
1045 Add <a href="#_info"><strong><code>info</code></strong></a> <code>statics</code>
1046 </p>
1047 </li>
1048 <li>
1050 Add <code>build-jim-ext</code> for easy separate building of loadable modules (extensions)
1051 </p>
1052 </li>
1053 <li>
1055 <a href="#_local"><strong><code>local</code></strong></a> now works with any command, not just procs
1056 </p>
1057 </li>
1058 <li>
1060 Add <a href="#_info"><strong><code>info</code></strong></a> <code>alias</code> to access the target of an alias
1061 </p>
1062 </li>
1063 <li>
1065 UTF-8 encoding past the basic multilingual plane (BMP) is supported
1066 </p>
1067 </li>
1068 <li>
1070 Add <a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a>
1071 </p>
1072 </li>
1073 <li>
1075 Add <a href="#_history"><strong><code>history</code></strong></a>
1076 </p>
1077 </li>
1078 <li>
1080 Most extensions are now enabled by default
1081 </p>
1082 </li>
1083 <li>
1085 Add support for namespaces and the <a href="#_namespace"><strong><code>namespace</code></strong></a> command
1086 </p>
1087 </li>
1088 <li>
1090 Add <a href="#_apply"><strong><code>apply</code></strong></a>
1091 </p>
1092 </li>
1093 </ol></div>
1094 </div>
1095 <div class="sect2">
1096 <h3 id="_changes_between_0_71_and_0_72">Changes between 0.71 and 0.72</h3>
1097 <div class="olist arabic"><ol class="arabic">
1098 <li>
1100 procs now allow <em>args</em> and optional parameters in any position
1101 </p>
1102 </li>
1103 <li>
1105 Add Tcl-compatible expr functions, <code>rand()</code>, <code>srand()</code> and <code>pow()</code>
1106 </p>
1107 </li>
1108 <li>
1110 Add support for the <em>-force</em> option to <a href="#_file"><strong><code>file</code></strong></a> <code>delete</code>
1111 </p>
1112 </li>
1113 <li>
1115 Better diagnostics when <a href="#_source"><strong><code>source</code></strong></a> fails to load a script with a missing quote or bracket
1116 </p>
1117 </li>
1118 <li>
1120 New <code>tcl_platform(pathSeparator)</code>
1121 </p>
1122 </li>
1123 <li>
1125 Add support settings the modification time with <a href="#_file"><strong><code>file</code></strong></a> <code>mtime</code>
1126 </p>
1127 </li>
1128 <li>
1130 <a href="#_exec"><strong><code>exec</code></strong></a> is now fully supported on win32 (mingw32)
1131 </p>
1132 </li>
1133 <li>
1135 <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
1136 </p>
1137 </li>
1138 <li>
1140 Line editing is now supported for the win32 console (mingw32)
1141 </p>
1142 </li>
1143 <li>
1145 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>listen</code> command
1146 </p>
1147 </li>
1148 </ol></div>
1149 </div>
1150 <div class="sect2">
1151 <h3 id="_changes_between_0_70_and_0_71">Changes between 0.70 and 0.71</h3>
1152 <div class="olist arabic"><ol class="arabic">
1153 <li>
1155 Allow <em>args</em> to be renamed in procs
1156 </p>
1157 </li>
1158 <li>
1160 Add <code>$(&#8230;)</code> shorthand syntax for expressions
1161 </p>
1162 </li>
1163 <li>
1165 Add automatic reference variables in procs with <code>&amp;var</code> syntax
1166 </p>
1167 </li>
1168 <li>
1170 Support <code>jimsh --version</code>
1171 </p>
1172 </li>
1173 <li>
1175 Additional variables in <code>tcl_platform()</code>
1176 </p>
1177 </li>
1178 <li>
1180 <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
1181 </p>
1182 </li>
1183 <li>
1185 Add <a href="#_loop"><strong><code>loop</code></strong></a> command (TclX compatible)
1186 </p>
1187 </li>
1188 <li>
1190 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>buffering</code> command
1191 </p>
1192 </li>
1193 <li>
1195 <a href="#_info"><strong><code>info</code></strong></a> <code>complete</code> can now return the missing character
1196 </p>
1197 </li>
1198 <li>
1200 <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
1201 </p>
1202 </li>
1203 <li>
1205 Add <a href="#_string"><strong><code>string</code></strong></a> <code>byterange</code>
1206 </p>
1207 </li>
1208 <li>
1210 Built-in regexp now support non-greedy repetition (*?, +?, ??)
1211 </p>
1212 </li>
1213 </ol></div>
1214 </div>
1215 </div>
1216 </div>
1217 <div class="sect1">
1218 <h2 id="_tcl_introduction">TCL INTRODUCTION</h2>
1219 <div class="sectionbody">
1220 <div class="paragraph"><p>Tcl stands for <em>tool command language</em> and is pronounced
1221 <em><a href="http://www.oxforddictionaries.com/definition/american_english/tickle">tickle</a></em>.
1222 It is actually two things: a language and a library.</p></div>
1223 <div class="paragraph"><p>First, Tcl is a simple textual language, intended primarily for
1224 issuing commands to interactive programs such as text editors,
1225 debuggers, illustrators, and shells. It has a simple syntax and is also
1226 programmable, so Tcl users can write command procedures to provide more
1227 powerful commands than those in the built-in set.</p></div>
1228 <div class="paragraph"><p>Second, Tcl is a library package that can be embedded in application
1229 programs. The Tcl library consists of a parser for the Tcl language,
1230 routines to implement the Tcl built-in commands, and procedures that
1231 allow each application to extend Tcl with additional commands specific
1232 to that application. The application program generates Tcl commands and
1233 passes them to the Tcl parser for execution. Commands may be generated
1234 by reading characters from an input source, or by associating command
1235 strings with elements of the application&#8217;s user interface, such as menu
1236 entries, buttons, or keystrokes.</p></div>
1237 <div class="paragraph"><p>When the Tcl library receives commands it parses them into component
1238 fields and executes built-in commands directly. For commands implemented
1239 by the application, Tcl calls back to the application to execute the
1240 commands. In many cases commands will invoke recursive invocations of the
1241 Tcl interpreter by passing in additional strings to execute (procedures,
1242 looping commands, and conditional commands all work in this way).</p></div>
1243 <div class="paragraph"><p>An application program gains three advantages by using Tcl for its command
1244 language. First, Tcl provides a standard syntax: once users know Tcl,
1245 they will be able to issue commands easily to any Tcl-based application.
1246 Second, Tcl provides programmability. All a Tcl application needs
1247 to do is to implement a few application-specific low-level commands.
1248 Tcl provides many utility commands plus a general programming interface
1249 for building up complex command procedures. By using Tcl, applications
1250 need not re-implement these features.</p></div>
1251 <div class="paragraph"><p>Third, Tcl can be used as a common language for communicating between
1252 applications. Inter-application communication is not built into the
1253 Tcl core described here, but various add-on libraries, such as the Tk
1254 toolkit, allow applications to issue commands to each other. This makes
1255 it possible for applications to work together in much more powerful ways
1256 than was previously possible.</p></div>
1257 <div class="paragraph"><p>Fourth, Jim Tcl includes a command processor, <code>jimsh</code>, which can be
1258 used to run standalone Tcl scripts, or to run Tcl commands interactively.</p></div>
1259 <div class="paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
1260 the language syntax and the built-in commands that will be available
1261 in any application based on Tcl. The individual library procedures are
1262 described in more detail in separate manual pages, one per procedure.</p></div>
1263 </div>
1264 </div>
1265 <div class="sect1">
1266 <h2 id="_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER</h2>
1267 <div class="sectionbody">
1268 <div class="paragraph"><p>A simple, but powerful command processor, <code>jimsh</code>, is part of Jim Tcl.
1269 It may be invoked in interactive mode as:</p></div>
1270 <div class="literalblock">
1271 <div class="content">
1272 <pre><code>jimsh</code></pre>
1273 </div></div>
1274 <div class="paragraph"><p>or to process the Tcl script in a file with:</p></div>
1275 <div class="literalblock">
1276 <div class="content">
1277 <pre><code>jimsh filename</code></pre>
1278 </div></div>
1279 <div class="paragraph"><p>It may also be invoked to execute an immediate script with:</p></div>
1280 <div class="literalblock">
1281 <div class="content">
1282 <pre><code>jimsh -e "script"</code></pre>
1283 </div></div>
1284 <div class="sect2">
1285 <h3 id="_interactive_mode">Interactive Mode</h3>
1286 <div class="paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
1287 those commands and prints the results.</p></div>
1288 <div class="literalblock">
1289 <div class="content">
1290 <pre><code>$ jimsh
1291 Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
1292 . info version
1293 0.73
1294 . lsort [info commands p*]
1295 package parray pid popen proc puts pwd
1296 . foreach i {a b c} {
1297 {&gt; puts $i
1298 {&gt; }
1302 . bad
1303 invalid command name "bad"
1304 [error] . exit
1305 $</code></pre>
1306 </div></div>
1307 <div class="paragraph"><p>If <code>jimsh</code> is configured with line editing (it is by default) and a VT-100-compatible
1308 terminal is detected, Emacs-style line editing commands are available, including:
1309 arrow keys, <code>^W</code> to erase a word, <code>^U</code> to erase the line, <code>^R</code> for reverse incremental search
1310 in history. Additionally, the <code>h</code> command may be used to display the command history.</p></div>
1311 <div class="paragraph"><p>Command line history is automatically saved and loaded from <code>~/.jim_history</code></p></div>
1312 <div class="paragraph"><p>In interactive mode, <code>jimsh</code> automatically runs the script <code>~/.jimrc</code> at startup
1313 if it exists.</p></div>
1314 </div>
1315 </div>
1316 </div>
1317 <div class="sect1">
1318 <h2 id="_interpreters">INTERPRETERS</h2>
1319 <div class="sectionbody">
1320 <div class="paragraph"><p>The central data structure in Tcl is an interpreter (C type <em>Jim_Interp</em>).
1321 An interpreter consists of a set of command bindings, a set of variable
1322 values, and a few other miscellaneous pieces of state. Each Tcl command
1323 is interpreted in the context of a particular interpreter.</p></div>
1324 <div class="paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
1325 simultaneously, each associated with a different widget or portion of
1326 the application. Interpreters are relatively lightweight structures.
1327 They can be created and deleted quickly, so application programmers should
1328 feel free to use multiple interpreters if that simplifies the application.</p></div>
1329 </div>
1330 </div>
1331 <div class="sect1">
1332 <h2 id="_data_types">DATA TYPES</h2>
1333 <div class="sectionbody">
1334 <div class="paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
1335 to commands, all command results, and all variable values are strings.</p></div>
1336 <div class="paragraph"><p>Where commands require numeric arguments or return numeric results,
1337 the arguments and results are passed as strings. Many commands expect
1338 their string arguments to have certain formats, but this interpretation
1339 is up to the individual commands. For example, arguments often contain
1340 Tcl command strings, which may get executed as part of the commands.
1341 The easiest way to understand the Tcl interpreter is to remember that
1342 everything is just an operation on a string. In many cases Tcl constructs
1343 will look similar to more structured constructs from other languages.
1344 However, the Tcl constructs are not structured at all; they are just
1345 strings of characters, and this gives them a different behaviour than
1346 the structures they may look like.</p></div>
1347 <div class="paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
1348 the interpretation, there are three common forms that strings take:
1349 commands, expressions, and lists. The major sections below discuss
1350 these three forms in more detail.</p></div>
1351 </div>
1352 </div>
1353 <div class="sect1">
1354 <h2 id="_basic_command_syntax">BASIC COMMAND SYNTAX</h2>
1355 <div class="sectionbody">
1356 <div class="paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
1357 and Lisp. However, the interpretation of commands is different
1358 in Tcl than in either of those other two systems.
1359 A Tcl command string consists of one or more commands separated
1360 by newline characters or semi-colons.
1361 Each command consists of a collection of fields separated by
1362 white space (spaces or tabs).
1363 The first field must be the name of a command, and the
1364 additional fields, if any, are arguments that will be passed to
1365 that command. For example, the command:</p></div>
1366 <div class="literalblock">
1367 <div class="content">
1368 <pre><code>set a 22</code></pre>
1369 </div></div>
1370 <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
1371 the last two, <em>a</em> and <em>22</em>, will be passed as arguments to
1372 the <a href="#_set"><strong><code>set</code></strong></a> command. The command name may refer either to a built-in
1373 Tcl command, an application-specific command bound in with the library
1374 procedure <em>Jim_CreateCommand</em>, or a command procedure defined with the
1375 <a href="#_proc"><strong><code>proc</code></strong></a> built-in command.</p></div>
1376 <div class="paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1377 interpret those strings in any fashion they wish. The <a href="#_set"><strong><code>set</code></strong></a> command,
1378 for example, will treat its first argument as the name of a variable
1379 and its second argument as a string value to assign to that variable.
1380 For other commands arguments may be interpreted as integers, lists,
1381 file names, or Tcl commands.</p></div>
1382 <div class="paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1383 However, if the Tcl interpreter cannot locate a command it invokes a
1384 special command named <a href="#_unknown"><strong><code>unknown</code></strong></a> which attempts to find or create the
1385 command.</p></div>
1386 <div class="paragraph"><p>For example, at many sites <a href="#_unknown"><strong><code>unknown</code></strong></a> will search through library
1387 directories for the desired command and create it as a Tcl procedure if
1388 it is found. The <a href="#_unknown"><strong><code>unknown</code></strong></a> command often provides automatic completion
1389 of abbreviated commands, but usually only for commands that were typed
1390 interactively.</p></div>
1391 <div class="paragraph"><p>It&#8217;s probably a bad idea to use abbreviations in command scripts and
1392 other forms that will be re-used over time: changes to the command set
1393 may cause abbreviations to become ambiguous, resulting in scripts that
1394 no longer work.</p></div>
1395 </div>
1396 </div>
1397 <div class="sect1">
1398 <h2 id="_comments">COMMENTS</h2>
1399 <div class="sectionbody">
1400 <div class="paragraph"><p>If the first non-blank character in a command is <code>#</code>, then everything
1401 from the <code>#</code> up through the next newline character is treated as
1402 a comment and ignored. When comments are embedded inside nested
1403 commands (e.g. fields enclosed in braces) they must have properly-matched
1404 braces (this is necessary because when Tcl parses the top-level command
1405 it doesn&#8217;t yet know that the nested field will be used as a command so
1406 it cannot process the nested comment character as a comment).</p></div>
1407 </div>
1408 </div>
1409 <div class="sect1">
1410 <h2 id="_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES</h2>
1411 <div class="sectionbody">
1412 <div class="paragraph"><p>Normally each argument field ends at the next white space, but
1413 double-quotes may be used to create arguments with embedded space.</p></div>
1414 <div class="paragraph"><p>If an argument field begins with a double-quote, then the argument isn&#8217;t
1415 terminated by white space (including newlines) or a semi-colon (see below
1416 for information on semi-colons); instead it ends at the next double-quote
1417 character. The double-quotes are not included in the resulting argument.
1418 For example, the command</p></div>
1419 <div class="literalblock">
1420 <div class="content">
1421 <pre><code>set a "This is a single argument"</code></pre>
1422 </div></div>
1423 <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>
1424 <div class="paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1425 and backslash substitutions still occur, as described below. If the
1426 first character of a command field is not a quote, then quotes receive
1427 no special interpretation in the parsing of that field.</p></div>
1428 </div>
1429 </div>
1430 <div class="sect1">
1431 <h2 id="_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES</h2>
1432 <div class="sectionbody">
1433 <div class="paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1434 to quotes except for two differences. First, they nest; this makes them
1435 easier to use for complicated arguments like nested Tcl command strings.
1436 Second, the substitutions described below for commands, variables, and
1437 backslashes do <strong>not</strong> occur in arguments enclosed in braces, so braces
1438 can be used to prevent substitutions where they are undesirable.</p></div>
1439 <div class="paragraph"><p>If an argument field begins with a left brace, then the argument ends
1440 at the matching right brace. Tcl will strip off the outermost layer
1441 of braces and pass the information between the braces to the command
1442 without any further modification. For example, in the command</p></div>
1443 <div class="literalblock">
1444 <div class="content">
1445 <pre><code>set a {xyz a {b c d}}</code></pre>
1446 </div></div>
1447 <div class="paragraph"><p>the <a href="#_set"><strong><code>set</code></strong></a> command will receive two arguments: <em>a</em>
1448 and <em>xyz a {b c d}</em>.</p></div>
1449 <div class="paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1450 not be on the same line as the starting quote or brace; in this case
1451 the newline will be included in the argument field along with any other
1452 characters up to the matching brace or quote. For example, the <a href="#_eval"><strong><code>eval</code></strong></a>
1453 command takes one argument, which is a command string; <a href="#_eval"><strong><code>eval</code></strong></a> invokes
1454 the Tcl interpreter to execute the command string. The command</p></div>
1455 <div class="literalblock">
1456 <div class="content">
1457 <pre><code>eval {
1458 set a 22
1459 set b 33
1460 }</code></pre>
1461 </div></div>
1462 <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>
1463 <div class="paragraph"><p>If the first character of a command field is not a left
1464 brace, then neither left nor right
1465 braces in the field will be treated specially (except as part of
1466 variable substitution; see below).</p></div>
1467 </div>
1468 </div>
1469 <div class="sect1">
1470 <h2 id="_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS</h2>
1471 <div class="sectionbody">
1472 <div class="paragraph"><p>If an open bracket occurs in a field of a command, then command
1473 substitution occurs (except for fields enclosed in braces). All of the
1474 text up to the matching close bracket is treated as a Tcl command and
1475 executed immediately. Then the result of that command is substituted
1476 for the bracketed text. For example, consider the command</p></div>
1477 <div class="literalblock">
1478 <div class="content">
1479 <pre><code>set a [set b]</code></pre>
1480 </div></div>
1481 <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
1482 variable and <a href="#_set"><strong><code>set</code></strong></a> returns the contents of that variable. In this case,
1483 if variable <em>b</em> has the value <em>foo</em>, then the command above is equivalent
1484 to the command</p></div>
1485 <div class="literalblock">
1486 <div class="content">
1487 <pre><code>set a foo</code></pre>
1488 </div></div>
1489 <div class="paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1490 <em>b</em> has the value <em>foo</em> and the variable <em>c</em> has the value <em>gorp</em>,
1491 then the command</p></div>
1492 <div class="literalblock">
1493 <div class="content">
1494 <pre><code>set a xyz[set b].[set c]</code></pre>
1495 </div></div>
1496 <div class="paragraph"><p>is equivalent to the command</p></div>
1497 <div class="literalblock">
1498 <div class="content">
1499 <pre><code>set a xyzfoo.gorp</code></pre>
1500 </div></div>
1501 <div class="paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1502 or semi-colons in the usual fashion. In this case the value of the last
1503 command is used for substitution. For example, the command</p></div>
1504 <div class="literalblock">
1505 <div class="content">
1506 <pre><code>set a x[set b 22
1507 expr $b+2]x</code></pre>
1508 </div></div>
1509 <div class="paragraph"><p>is equivalent to the command</p></div>
1510 <div class="literalblock">
1511 <div class="content">
1512 <pre><code>set a x24x</code></pre>
1513 </div></div>
1514 <div class="paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1515 between them are not interpreted specially; they are passed through to
1516 the argument verbatim.</p></div>
1517 </div>
1518 </div>
1519 <div class="sect1">
1520 <h2 id="_variable_substitution_with">VARIABLE SUBSTITUTION WITH $</h2>
1521 <div class="sectionbody">
1522 <div class="paragraph"><p>The dollar sign (<code>$</code>) may be used as a special shorthand form for
1523 substituting variable values. If <code>$</code> appears in an argument that isn&#8217;t
1524 enclosed in braces then variable substitution will occur. The characters
1525 after the <code>$</code>, up to the first character that isn&#8217;t a number, letter,
1526 or underscore, are taken as a variable name and the string value of that
1527 variable is substituted for the name.</p></div>
1528 <div class="paragraph"><p>For example, if variable <em>foo</em> has the value <em>test</em>, then the command</p></div>
1529 <div class="literalblock">
1530 <div class="content">
1531 <pre><code>set a $foo.c</code></pre>
1532 </div></div>
1533 <div class="paragraph"><p>is equivalent to the command</p></div>
1534 <div class="literalblock">
1535 <div class="content">
1536 <pre><code>set a test.c</code></pre>
1537 </div></div>
1538 <div class="paragraph"><p>There are two special forms for variable substitution. If the next
1539 character after the name of the variable is an open parenthesis, then
1540 the variable is assumed to be an array name, and all of the characters
1541 between the open parenthesis and the next close parenthesis are taken as
1542 an index into the array. Command substitutions and variable substitutions
1543 are performed on the information between the parentheses before it is
1544 used as an index.</p></div>
1545 <div class="paragraph"><p>For example, if the variable <em>x</em> is an array with one element named
1546 <em>first</em> and value <em>87</em> and another element named <em>14</em> and value <em>more</em>,
1547 then the command</p></div>
1548 <div class="literalblock">
1549 <div class="content">
1550 <pre><code>set a xyz$x(first)zyx</code></pre>
1551 </div></div>
1552 <div class="paragraph"><p>is equivalent to the command</p></div>
1553 <div class="literalblock">
1554 <div class="content">
1555 <pre><code>set a xyz87zyx</code></pre>
1556 </div></div>
1557 <div class="paragraph"><p>If the variable <em>index</em> has the value <em>14</em>, then the command</p></div>
1558 <div class="literalblock">
1559 <div class="content">
1560 <pre><code>set a xyz$x($index)zyx</code></pre>
1561 </div></div>
1562 <div class="paragraph"><p>is equivalent to the command</p></div>
1563 <div class="literalblock">
1564 <div class="content">
1565 <pre><code>set a xyzmorezyx</code></pre>
1566 </div></div>
1567 <div class="paragraph"><p>For more information on arrays, see VARIABLES AND ARRAYS below.</p></div>
1568 <div class="paragraph"><p>The second special form for variables occurs when the dollar sign is
1569 followed by an open curly brace. In this case the variable name consists
1570 of all the characters up to the next curly brace.</p></div>
1571 <div class="paragraph"><p>Array references are not possible in this form: the name between braces
1572 is assumed to refer to a scalar variable. For example, if variable
1573 <em>foo</em> has the value <em>test</em>, then the command</p></div>
1574 <div class="literalblock">
1575 <div class="content">
1576 <pre><code>set a abc${foo}bar</code></pre>
1577 </div></div>
1578 <div class="paragraph"><p>is equivalent to the command</p></div>
1579 <div class="literalblock">
1580 <div class="content">
1581 <pre><code>set a abctestbar</code></pre>
1582 </div></div>
1583 <div class="paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1584 braces: the dollar sign and variable name are passed through to the
1585 argument verbatim.</p></div>
1586 <div class="paragraph"><p>The dollar sign abbreviation is simply a shorthand form. <code>$a</code> is
1587 completely equivalent to <code>[set a]</code>; it is provided as a convenience
1588 to reduce typing.</p></div>
1589 </div>
1590 </div>
1591 <div class="sect1">
1592 <h2 id="_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS</h2>
1593 <div class="sectionbody">
1594 <div class="paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1595 newline character). However, semi-colon (<code>;</code>) is treated as a command
1596 separator character; multiple commands may be placed on one line by
1597 separating them with a semi-colon. Semi-colons are not treated as
1598 command separators if they appear within curly braces or double-quotes.</p></div>
1599 </div>
1600 </div>
1601 <div class="sect1">
1602 <h2 id="_backslash_substitution">BACKSLASH SUBSTITUTION</h2>
1603 <div class="sectionbody">
1604 <div class="paragraph"><p>Backslashes may be used to insert non-printing characters into command
1605 fields and also to insert special characters like braces and brackets
1606 into fields without them being interpreted specially as described above.</p></div>
1607 <div class="paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1608 listed below. In each case, the backslash
1609 sequence is replaced by the given character:</p></div>
1610 <div class="dlist" id="BackslashSequences"><dl>
1611 <dt class="hdlist1">
1612 <code>\b</code>
1613 </dt>
1614 <dd>
1616 Backspace (0x8)
1617 </p>
1618 </dd>
1619 <dt class="hdlist1">
1620 <code>\f</code>
1621 </dt>
1622 <dd>
1624 Form feed (0xc)
1625 </p>
1626 </dd>
1627 <dt class="hdlist1">
1628 <code>\n</code>
1629 </dt>
1630 <dd>
1632 Newline (0xa)
1633 </p>
1634 </dd>
1635 <dt class="hdlist1">
1636 <code>\r</code>
1637 </dt>
1638 <dd>
1640 Carriage-return (0xd).
1641 </p>
1642 </dd>
1643 <dt class="hdlist1">
1644 <code>\t</code>
1645 </dt>
1646 <dd>
1648 Tab (0x9).
1649 </p>
1650 </dd>
1651 <dt class="hdlist1">
1652 <code>\v</code>
1653 </dt>
1654 <dd>
1656 Vertical tab (0xb).
1657 </p>
1658 </dd>
1659 <dt class="hdlist1">
1660 <code>\{</code>
1661 </dt>
1662 <dd>
1664 Left brace ({).
1665 </p>
1666 </dd>
1667 <dt class="hdlist1">
1668 <code>\}</code>
1669 </dt>
1670 <dd>
1672 Right brace (}).
1673 </p>
1674 </dd>
1675 <dt class="hdlist1">
1676 <code>\[</code>
1677 </dt>
1678 <dd>
1680 Open bracket ([).
1681 </p>
1682 </dd>
1683 <dt class="hdlist1">
1684 <code>\]</code>
1685 </dt>
1686 <dd>
1688 Close bracket (]).
1689 </p>
1690 </dd>
1691 <dt class="hdlist1">
1692 <code>\$</code>
1693 </dt>
1694 <dd>
1696 Dollar sign ($).
1697 </p>
1698 </dd>
1699 <dt class="hdlist1">
1700 <code>\&lt;space&gt;</code>
1701 </dt>
1702 <dd>
1704 Space ( ): doesn&#8217;t terminate argument.
1705 </p>
1706 </dd>
1707 <dt class="hdlist1">
1708 <code>\;</code>
1709 </dt>
1710 <dd>
1712 Semi-colon: doesn&#8217;t terminate command.
1713 </p>
1714 </dd>
1715 <dt class="hdlist1">
1716 <code>\"</code>
1717 </dt>
1718 <dd>
1720 Double-quote.
1721 </p>
1722 </dd>
1723 <dt class="hdlist1">
1724 <code>\&lt;newline&gt;</code>
1725 </dt>
1726 <dd>
1728 Nothing: this joins two lines together
1729 into a single line. This backslash feature is unique in that
1730 it will be applied even when the sequence occurs within braces.
1731 </p>
1732 </dd>
1733 <dt class="hdlist1">
1734 <code>\\</code>
1735 </dt>
1736 <dd>
1738 Backslash (<em>\</em>).
1739 </p>
1740 </dd>
1741 <dt class="hdlist1">
1742 <code>\ddd</code>
1743 </dt>
1744 <dd>
1746 The digits <code><em>ddd</em></code> (one, two, or three of them) give the octal value of
1747 the character. Note that Jim supports null characters in strings.
1748 </p>
1749 </dd>
1750 <dt class="hdlist1">
1751 <code>\unnnn</code>
1752 </dt>
1753 <dt class="hdlist1">
1754 <code>\u{nnn}</code>
1755 </dt>
1756 <dt class="hdlist1">
1757 <code>\Unnnnnnnn</code>
1758 </dt>
1759 <dd>
1761 The UTF-8 encoding of the unicode codepoint represented by the hex digits, <code><em>nnnn</em></code>, is inserted.
1762 The <em>u</em> form allows for one to four hex digits.
1763 The <em>U</em> form allows for one to eight hex digits.
1764 The <em>u{nnn}</em> form allows for one to eight hex digits, but makes it easier to insert
1765 characters UTF-8 characters which are followed by a hex digit.
1766 </p>
1767 </dd>
1768 </dl></div>
1769 <div class="paragraph"><p>For example, in the command</p></div>
1770 <div class="literalblock">
1771 <div class="content">
1772 <pre><code>set a \{x\[\ yz\141</code></pre>
1773 </div></div>
1774 <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>
1775 <div class="paragraph"><p>If a backslash is followed by something other than one of the options
1776 described above, then the backslash is transmitted to the argument
1777 field without any special processing, and the Tcl scanner continues
1778 normal processing with the next character. For example, in the
1779 command</p></div>
1780 <div class="literalblock">
1781 <div class="content">
1782 <pre><code>set \*a \\\{foo</code></pre>
1783 </div></div>
1784 <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
1785 argument will be <code>\{foo</code>.</p></div>
1786 <div class="paragraph"><p>If an argument is enclosed in braces, then backslash sequences inside
1787 the argument are parsed but no substitution occurs (except for
1788 backslash-newline): the backslash
1789 sequence is passed through to the argument as is, without making
1790 any special interpretation of the characters in the backslash sequence.
1791 In particular, backslashed braces are not counted in locating the
1792 matching right brace that terminates the argument.
1793 For example, in the
1794 command</p></div>
1795 <div class="literalblock">
1796 <div class="content">
1797 <pre><code>set a {\{abc}</code></pre>
1798 </div></div>
1799 <div class="paragraph"><p>the second argument to <a href="#_set"><strong><code>set</code></strong></a> will be <code>\{abc</code>.</p></div>
1800 <div class="paragraph"><p>This backslash mechanism is not sufficient to generate absolutely
1801 any argument structure; it only covers the
1802 most common cases. To produce particularly complicated arguments
1803 it is probably easiest to use the <a href="#_format"><strong><code>format</code></strong></a> command along with
1804 command substitution.</p></div>
1805 </div>
1806 </div>
1807 <div class="sect1">
1808 <h2 id="_string_and_list_index_specifications">STRING AND LIST INDEX SPECIFICATIONS</h2>
1809 <div class="sectionbody">
1810 <div class="paragraph"><p>Many string and list commands take one or more <em>index</em> parameters which
1811 specify a position in the string relative to the start or end of the string/list.</p></div>
1812 <div class="paragraph"><p>The index may be one of the following forms:</p></div>
1813 <div class="dlist"><dl>
1814 <dt class="hdlist1">
1815 <code>integer</code>
1816 </dt>
1817 <dd>
1819 A simple integer, where <em>0</em> refers to the first element of the string
1820 or list.
1821 </p>
1822 </dd>
1823 <dt class="hdlist1">
1824 <code>integer+integer</code> or
1825 </dt>
1826 <dt class="hdlist1">
1827 <code>integer-integer</code>
1828 </dt>
1829 <dd>
1831 The sum or difference of the two integers. e.g. <code>2+3</code> refers to the 5th element.
1832 This is useful when used with (e.g.) <code>$i+1</code> rather than the more verbose
1833 <code>[expr {$i+1}]</code>
1834 </p>
1835 </dd>
1836 <dt class="hdlist1">
1837 <code>end</code>
1838 </dt>
1839 <dd>
1841 The last element of the string or list.
1842 </p>
1843 </dd>
1844 <dt class="hdlist1">
1845 <code>end-integer</code>
1846 </dt>
1847 <dd>
1849 The <em>nth-from-last</em> element of the string or list.
1850 </p>
1851 </dd>
1852 </dl></div>
1853 </div>
1854 </div>
1855 <div class="sect1">
1856 <h2 id="_command_summary">COMMAND SUMMARY</h2>
1857 <div class="sectionbody">
1858 <div class="olist arabic"><ol class="arabic">
1859 <li>
1861 A command is just a string.
1862 </p>
1863 </li>
1864 <li>
1866 Within a string commands are separated by newlines or semi-colons
1867 (unless the newline or semi-colon is within braces or brackets
1868 or is backslashed).
1869 </p>
1870 </li>
1871 <li>
1873 A command consists of fields. The first field is the name of the command.
1874 The other fields are strings that are passed to that command as arguments.
1875 </p>
1876 </li>
1877 <li>
1879 Fields are normally separated by white space.
1880 </p>
1881 </li>
1882 <li>
1884 Double-quotes allow white space and semi-colons to appear within
1885 a single argument.
1886 Command substitution, variable substitution, and backslash substitution
1887 still occur inside quotes.
1888 </p>
1889 </li>
1890 <li>
1892 Braces defer interpretation of special characters.
1893 If a field begins with a left brace, then it consists of everything
1894 between the left brace and the matching right brace. The
1895 braces themselves are not included in the argument.
1896 No further processing is done on the information between the braces
1897 except that backslash-newline sequences are eliminated.
1898 </p>
1899 </li>
1900 <li>
1902 If a field doesn&#8217;t begin with a brace then backslash,
1903 variable, and command substitution are done on the field. Only a
1904 single level of processing is done: the results of one substitution
1905 are not scanned again for further substitutions or any other
1906 special treatment. Substitution can
1907 occur on any field of a command, including the command name
1908 as well as the arguments.
1909 </p>
1910 </li>
1911 <li>
1913 If the first non-blank character of a command is a <code>#</code>, everything
1914 from the <code>#</code> up through the next newline is treated as a comment
1915 and ignored.
1916 </p>
1917 </li>
1918 </ol></div>
1919 </div>
1920 </div>
1921 <div class="sect1">
1922 <h2 id="_expressions">EXPRESSIONS</h2>
1923 <div class="sectionbody">
1924 <div class="paragraph"><p>The second major interpretation applied to strings in Tcl is
1925 as expressions. Several commands, such as <a href="#_expr"><strong><code>expr</code></strong></a>, <a href="#_for"><strong><code>for</code></strong></a>,
1926 and <a href="#_if"><strong><code>if</code></strong></a>, treat one or more of their arguments as expressions
1927 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
1928 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
1929 <div class="paragraph"><p>The operators permitted in Tcl expressions are a subset of
1930 the operators permitted in C expressions, and they have the
1931 same meaning and precedence as the corresponding C operators.
1932 Expressions almost always yield numeric results
1933 (integer or floating-point values).
1934 For example, the expression</p></div>
1935 <div class="literalblock">
1936 <div class="content">
1937 <pre><code>8.2 + 6</code></pre>
1938 </div></div>
1939 <div class="paragraph"><p>evaluates to 14.2.</p></div>
1940 <div class="paragraph"><p>Tcl expressions differ from C expressions in the way that
1941 operands are specified, and in that Tcl expressions support
1942 non-numeric operands and string comparisons.</p></div>
1943 <div class="paragraph"><p>A Tcl expression consists of a combination of operands, operators,
1944 and parentheses.</p></div>
1945 <div class="paragraph"><p>White space may be used between the operands and operators and
1946 parentheses; it is ignored by the expression processor.
1947 Where possible, operands are interpreted as integer values.</p></div>
1948 <div class="paragraph"><p>Integer values may be specified in decimal (the normal case) or in
1949 hexadecimal (if the first two characters of the operand are <em>0x</em>).
1950 Note that Jim Tcl does <strong>not</strong> treat numbers with leading zeros as octal.</p></div>
1951 <div class="paragraph"><p>If an operand does not have one of the integer formats given
1952 above, then it is treated as a floating-point number if that is
1953 possible. Floating-point numbers may be specified in any of the
1954 ways accepted by an ANSI-compliant C compiler (except that the
1955 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
1956 most installations). For example, all of the
1957 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
1958 <div class="paragraph"><p>If no numeric interpretation is possible, then an operand is left
1959 as a string (and only a limited set of operators may be applied to
1960 it).</p></div>
1961 <div class="paragraph"><p>String constants representing boolean constants
1962 (<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>)
1963 are also recognized and can be used in logical operations.</p></div>
1964 <div class="olist arabic"><ol class="arabic">
1965 <li>
1967 Operands may be specified in any of the following ways:
1968 </p>
1969 </li>
1970 <li>
1972 As a numeric value, either integer or floating-point.
1973 </p>
1974 </li>
1975 <li>
1977 As one of valid boolean constants
1978 </p>
1979 </li>
1980 <li>
1982 As a Tcl variable, using standard <em>$</em> notation.
1983 The variable&#8217;s value will be used as the operand.
1984 </p>
1985 </li>
1986 <li>
1988 As a string enclosed in double-quotes.
1989 The expression parser will perform backslash, variable, and
1990 command substitutions on the information between the quotes,
1991 and use the resulting value as the operand
1992 </p>
1993 </li>
1994 <li>
1996 As a string enclosed in braces.
1997 The characters between the open brace and matching close brace
1998 will be used as the operand without any substitutions.
1999 </p>
2000 </li>
2001 <li>
2003 As a Tcl command enclosed in brackets.
2004 The command will be executed and its result will be used as
2005 the operand.
2006 </p>
2007 </li>
2008 </ol></div>
2009 <div class="paragraph"><p>Where substitutions occur above (e.g. inside quoted strings), they
2010 are performed by the expression processor.
2011 However, an additional layer of substitution may already have
2012 been performed by the command parser before the expression
2013 processor was called.</p></div>
2014 <div class="paragraph"><p>As discussed below, it is usually best to enclose expressions
2015 in braces to prevent the command parser from performing substitutions
2016 on the contents.</p></div>
2017 <div class="paragraph"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
2018 the value 3 and the variable <em>b</em> has the value 6. Then the expression
2019 on the left side of each of the lines below will evaluate to the value
2020 on the right side of the line:</p></div>
2021 <div class="literalblock">
2022 <div class="content">
2023 <pre><code>$a + 3.1 6.1
2024 2 + "$a.$b" 5.6
2025 4*[llength "6 2"] 8
2026 {word one} &lt; "word $a" 0</code></pre>
2027 </div></div>
2028 <div class="paragraph"><p>The valid operators are listed below, grouped in decreasing order
2029 of precedence:</p></div>
2030 <div class="dlist" id="OperatorPrecedence"><dl>
2031 <dt class="hdlist1">
2032 <code>int() double() round() abs(), rand(), srand()</code>
2033 </dt>
2034 <dd>
2036 Unary functions (except rand() which takes no arguments)
2037 </p>
2038 <div class="ulist"><ul>
2039 <li>
2041 <code><em>int()</em></code> converts the numeric argument to an integer by truncating down.
2042 </p>
2043 </li>
2044 <li>
2046 <code><em>double()</em></code> converts the numeric argument to floating point.
2047 </p>
2048 </li>
2049 <li>
2051 <code><em>round()</em></code> converts the numeric argument to the closest integer value.
2052 </p>
2053 </li>
2054 <li>
2056 <code><em>abs()</em></code> takes the absolute value of the numeric argument.
2057 </p>
2058 </li>
2059 <li>
2061 <code><em>rand()</em></code> returns a pseudo-random floating-point value in the range (0,1).
2062 </p>
2063 </li>
2064 <li>
2066 <code><em>srand()</em></code> takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
2067 </p>
2068 </li>
2069 </ul></div>
2070 </dd>
2071 <dt class="hdlist1">
2072 <code>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</code>
2073 </dt>
2074 <dd>
2076 Unary math functions.
2077 If Jim is compiled with math support, these functions are available.
2078 </p>
2079 </dd>
2080 <dt class="hdlist1">
2081 <code>- + ~ !</code>
2082 </dt>
2083 <dd>
2085 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
2086 may be applied to string operands, and bit-wise NOT may be
2087 applied only to integers.
2088 </p>
2089 </dd>
2090 <dt class="hdlist1">
2091 <code>** pow(x,y)</code>
2092 </dt>
2093 <dd>
2095 Power. e.g. <em>x<sup>y</sup></em>. If Jim is compiled with math support, supports doubles and
2096 integers. Otherwise supports integers only. (Note that the math-function form
2097 has the same highest precedence)
2098 </p>
2099 </dd>
2100 <dt class="hdlist1">
2101 <code>* / %</code>
2102 </dt>
2103 <dd>
2105 Multiply, divide, remainder. None of these operands may be
2106 applied to string operands, and remainder may be applied only
2107 to integers.
2108 </p>
2109 </dd>
2110 <dt class="hdlist1">
2111 <code>+ -</code>
2112 </dt>
2113 <dd>
2115 Add and subtract. Valid for any numeric operands.
2116 </p>
2117 </dd>
2118 <dt class="hdlist1">
2119 <code>&lt;&lt; &gt;&gt; &lt;&lt;&lt; &gt;&gt;&gt;</code>
2120 </dt>
2121 <dd>
2123 Left and right shift, left and right rotate. Valid for integer operands only.
2124 </p>
2125 </dd>
2126 <dt class="hdlist1">
2127 <code>&lt; &gt; &lt;= &gt;=</code>
2128 </dt>
2129 <dd>
2131 Boolean less, greater, less than or equal, and greater than or equal.
2132 Each operator produces 1 if the condition is true, 0 otherwise.
2133 These operators may be applied to strings as well as numeric operands,
2134 in which case string comparison is used.
2135 </p>
2136 </dd>
2137 <dt class="hdlist1">
2138 <code>== !=</code>
2139 </dt>
2140 <dd>
2142 Boolean equal and not equal. Each operator produces a zero/one result.
2143 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
2144 if possible, then floating point types, and finally strings will be compared.
2145 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
2146 </p>
2147 </dd>
2148 <dt class="hdlist1">
2149 <code>eq ne</code>
2150 </dt>
2151 <dd>
2153 String equal and not equal. Uses the string value directly without
2154 attempting to convert to a number first.
2155 </p>
2156 </dd>
2157 <dt class="hdlist1">
2158 <code>in ni</code>
2159 </dt>
2160 <dd>
2162 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
2163 is contained in the right operand (as a list), or 0 otherwise. The result for
2164 <code>{$a ni $list}</code> is equivalent to <code>{!($a in $list)}</code>.
2165 </p>
2166 </dd>
2167 <dt class="hdlist1">
2168 <code>&amp;</code>
2169 </dt>
2170 <dd>
2172 Bit-wise AND. Valid for integer operands only.
2173 </p>
2174 </dd>
2175 <dt class="hdlist1">
2176 <code>|</code>
2177 </dt>
2178 <dd>
2180 Bit-wise OR. Valid for integer operands only.
2181 </p>
2182 </dd>
2183 <dt class="hdlist1">
2184 <code>^</code>
2185 </dt>
2186 <dd>
2188 Bit-wise exclusive OR. Valid for integer operands only.
2189 </p>
2190 </dd>
2191 <dt class="hdlist1">
2192 <code>&amp;&amp;</code>
2193 </dt>
2194 <dd>
2196 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
2197 Valid for numeric operands only (integers or floating-point).
2198 </p>
2199 </dd>
2200 <dt class="hdlist1">
2201 <code>||</code>
2202 </dt>
2203 <dd>
2205 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
2206 Valid for numeric operands only (integers or floating-point).
2207 </p>
2208 </dd>
2209 <dt class="hdlist1">
2210 <code>x ? y : z</code>
2211 </dt>
2212 <dd>
2214 If-then-else, as in C. If <code><em>x</em></code>
2215 evaluates to non-zero, then the result is the value of <code><em>y</em></code>.
2216 Otherwise the result is the value of <code><em>z</em></code>.
2217 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
2218 be of any type.
2219 </p>
2220 </dd>
2221 </dl></div>
2222 <div class="paragraph"><p>See the C manual for more details on the results
2223 produced by each operator.
2224 All of the binary operators group left-to-right within the same
2225 precedence level. For example, the expression</p></div>
2226 <div class="literalblock">
2227 <div class="content">
2228 <pre><code>4*2 &lt; 7</code></pre>
2229 </div></div>
2230 <div class="paragraph"><p>evaluates to 0.</p></div>
2231 <div class="paragraph"><p>The <code>&amp;&amp;</code>, <code>||</code>, and <code>?:</code> operators have <em>lazy evaluation</em>, just as
2232 in C, which means that operands are not evaluated if they are not
2233 needed to determine the outcome. For example, in</p></div>
2234 <div class="literalblock">
2235 <div class="content">
2236 <pre><code>$v ? [a] : [b]</code></pre>
2237 </div></div>
2238 <div class="paragraph"><p>only one of <code>[a]</code> or <code>[b]</code> will actually be evaluated,
2239 depending on the value of <code>$v</code>.</p></div>
2240 <div class="paragraph"><p>All internal computations involving integers are done with the C
2241 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
2242 computations involving floating-point are done with the C type
2243 <em>double</em>.</p></div>
2244 <div class="paragraph"><p>When converting a string to floating-point, exponent overflow is
2245 detected and results in a Tcl error.
2246 For conversion to integer from string, detection of overflow depends
2247 on the behaviour of some routines in the local C library, so it should
2248 be regarded as unreliable.
2249 In any case, overflow and underflow are generally not detected
2250 reliably for intermediate results.</p></div>
2251 <div class="paragraph"><p>Conversion among internal representations for integer, floating-point,
2252 string operands is done automatically as needed.
2253 For arithmetic computations, integers are used until some
2254 floating-point number is introduced, after which floating-point is used.
2255 For example,</p></div>
2256 <div class="literalblock">
2257 <div class="content">
2258 <pre><code>5 / 4</code></pre>
2259 </div></div>
2260 <div class="paragraph"><p>yields the result 1, while</p></div>
2261 <div class="literalblock">
2262 <div class="content">
2263 <pre><code>5 / 4.0
2264 5 / ( [string length "abcd"] + 0.0 )</code></pre>
2265 </div></div>
2266 <div class="paragraph"><p>both yield the result 1.25.</p></div>
2267 <div class="paragraph"><p>String values may be used as operands of the comparison operators,
2268 although the expression evaluator tries to do comparisons as integer
2269 or floating-point when it can.
2270 If one of the operands of a comparison is a string and the other
2271 has a numeric value, the numeric operand is converted back to
2272 a string using the C <em>sprintf</em> format specifier
2273 <em>%d</em> for integers and <em>%g</em> for floating-point values.
2274 For example, the expressions</p></div>
2275 <div class="literalblock">
2276 <div class="content">
2277 <pre><code>"0x03" &gt; "2"
2278 "0y" &lt; "0x12"</code></pre>
2279 </div></div>
2280 <div class="paragraph"><p>both evaluate to 1. The first comparison is done using integer
2281 comparison, and the second is done using string comparison after
2282 the second operand is converted to the string <em>18</em>.</p></div>
2283 <div class="paragraph"><p>In general it is safest to enclose an expression in braces when
2284 entering it in a command: otherwise, if the expression contains
2285 any white space then the Tcl interpreter will split it
2286 among several arguments. For example, the command</p></div>
2287 <div class="literalblock">
2288 <div class="content">
2289 <pre><code>expr $a + $b</code></pre>
2290 </div></div>
2291 <div class="paragraph"><p>results in three arguments being passed to <a href="#_expr"><strong><code>expr</code></strong></a>: <code>$a</code>,
2292 +, and <code>$b</code>. In addition, if the expression isn&#8217;t in braces
2293 then the Tcl interpreter will perform variable and command substitution
2294 immediately (it will happen in the command parser rather than in
2295 the expression parser). In many cases the expression is being
2296 passed to a command that will evaluate the expression later (or
2297 even many times if, for example, the expression is to be used to
2298 decide when to exit a loop). Usually the desired goal is to re-do
2299 the variable or command substitutions each time the expression is
2300 evaluated, rather than once and for all at the beginning. For example,
2301 the command</p></div>
2302 <div class="literalblock">
2303 <div class="content">
2304 <pre><code>for {set i 1} $i&lt;=10 {incr i} {...} ** WRONG **</code></pre>
2305 </div></div>
2306 <div class="paragraph"><p>is probably intended to iterate over all values of <code>i</code> from 1 to 10.
2307 After each iteration of the body of the loop, <a href="#_for"><strong><code>for</code></strong></a> will pass
2308 its second argument to the expression evaluator to see whether or not
2309 to continue processing. Unfortunately, in this case the value of <code>i</code>
2310 in the second argument will be substituted once and for all when the
2311 <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>
2312 command was invoked then the second argument of <a href="#_for"><strong><code>for</code></strong></a> will be <code>0&lt;=10</code>
2313 which will always evaluate to 1, even though <code>i</code> eventually
2314 becomes greater than 10. In the above case the loop will never
2315 terminate. Instead, the expression should be placed in braces:</p></div>
2316 <div class="literalblock">
2317 <div class="content">
2318 <pre><code>for {set i 1} {$i&lt;=10} {incr i} {...} ** RIGHT **</code></pre>
2319 </div></div>
2320 <div class="paragraph"><p>This causes the substitution of <em>i</em>
2321 to be delayed; it will be re-done each time the expression is
2322 evaluated, which is the desired result.</p></div>
2323 </div>
2324 </div>
2325 <div class="sect1">
2326 <h2 id="_lists">LISTS</h2>
2327 <div class="sectionbody">
2328 <div class="paragraph"><p>The third major way that strings are interpreted in Tcl is as lists.
2329 A list is just a string with a list-like structure
2330 consisting of fields separated by white space. For example, the
2331 string</p></div>
2332 <div class="literalblock">
2333 <div class="content">
2334 <pre><code>Al Sue Anne John</code></pre>
2335 </div></div>
2336 <div class="paragraph"><p>is a list with four elements or fields.
2337 Lists have the same basic structure as command strings, except
2338 that a newline character in a list is treated as a field separator
2339 just like space or tab. Conventions for braces and quotes
2340 and backslashes are the same for lists as for commands. For example,
2341 the string</p></div>
2342 <div class="literalblock">
2343 <div class="content">
2344 <pre><code>a b\ c {d e {f g h}}</code></pre>
2345 </div></div>
2346 <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>
2347 <div class="paragraph"><p>Whenever an element is extracted from a list, the same rules about
2348 braces and quotes and backslashes are applied as for commands. Thus in
2349 the example above when the third element is extracted from the list,
2350 the result is</p></div>
2351 <div class="literalblock">
2352 <div class="content">
2353 <pre><code>d e {f g h}</code></pre>
2354 </div></div>
2355 <div class="paragraph"><p>(when the field was extracted, all that happened was to strip off
2356 the outermost layer of braces). Command substitution and
2357 variable substitution are never
2358 made on a list (at least, not by the list-processing commands; the
2359 list can always be passed to the Tcl interpreter for evaluation).</p></div>
2360 <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>,
2361 <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
2362 you to build lists, extract elements from them, search them, and perform
2363 other list-related functions.</p></div>
2364 <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>
2365 </div>
2366 </div>
2367 <div class="sect1">
2368 <h2 id="_list_expansion">LIST EXPANSION</h2>
2369 <div class="sectionbody">
2370 <div class="paragraph"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
2371 arguments. Support for this feature is also available in Jim.</p></div>
2372 <div class="paragraph"><p>Consider the following attempt to exec a list:</p></div>
2373 <div class="literalblock">
2374 <div class="content">
2375 <pre><code>set cmd {ls -l}
2376 exec $cmd</code></pre>
2377 </div></div>
2378 <div class="paragraph"><p>This will attempt to exec a command named "ls -l", which will clearly not
2379 work. Typically eval and concat are required to solve this problem, however
2380 it can be solved much more easily with <code>{*}</code>.</p></div>
2381 <div class="literalblock">
2382 <div class="content">
2383 <pre><code>exec {*}$cmd</code></pre>
2384 </div></div>
2385 <div class="paragraph"><p>This will expand the following argument into individual elements and then evaluate
2386 the resulting command.</p></div>
2387 <div class="paragraph"><p>Note that the official Tcl syntax is <code>{*}</code>, however <code>{expand}</code> is retained
2388 for backward compatibility with experimental versions of this feature.</p></div>
2389 </div>
2390 </div>
2391 <div class="sect1">
2392 <h2 id="_regular_expressions">REGULAR EXPRESSIONS</h2>
2393 <div class="sectionbody">
2394 <div class="paragraph"><p>Tcl provides two commands that support string matching using regular
2395 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
2396 <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-regexp</code>.</p></div>
2397 <div class="paragraph"><p>Regular expressions may be implemented one of two ways. Either using the system&#8217;s C library
2398 POSIX regular expression support, or using the built-in regular expression engine.
2399 The differences between these are described below.</p></div>
2400 <div class="paragraph"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<code>ARE</code>).</p></div>
2401 <div class="sect2">
2402 <h3 id="_posix_regular_expressions">POSIX Regular Expressions</h3>
2403 <div class="paragraph"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
2404 this support will be used by default. The type of regular expressions supported are
2405 Extended Regular Expressions (<code>ERE</code>) rather than Basic Regular Expressions (<code>BRE</code>).
2406 See REG_EXTENDED in the documentation.</p></div>
2407 <div class="paragraph"><p>Using the system-supported POSIX regular expressions will typically
2408 make for the smallest code size, but some features such as UTF-8
2409 and <code>\w</code>, <code>\d</code>, <code>\s</code> are not supported, and null characters
2410 in strings are not supported.</p></div>
2411 <div class="paragraph"><p>See regex(3) and regex(7) for full details.</p></div>
2412 </div>
2413 <div class="sect2">
2414 <h3 id="_jim_built_in_regular_expressions">Jim built-in Regular Expressions</h3>
2415 <div class="paragraph"><p>The Jim built-in regular expression engine may be selected with <code>./configure --with-jim-regexp</code>
2416 or it will be selected automatically if UTF-8 support is enabled.</p></div>
2417 <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
2418 and POSIX are highlighted below.</p></div>
2419 <div class="olist arabic"><ol class="arabic">
2420 <li>
2422 UTF-8 strings and patterns are both supported
2423 </p>
2424 </li>
2425 <li>
2427 All Tcl character classes are supported (e.g. <code>[:alnum:]</code>, <code>[:digit:]</code>, <code>[:space:]</code>), but&#8230;
2428 </p>
2429 </li>
2430 <li>
2432 Character classes apply to ASCII characters only
2433 </p>
2434 </li>
2435 <li>
2437 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>
2438 </p>
2439 </li>
2440 <li>
2442 Supported constraint escapes: <code>\m</code> = <code>\&lt;</code> = start of word, <code>\M</code> = <code>\&gt;</code> = end of word
2443 </p>
2444 </li>
2445 <li>
2447 Backslash escapes may be used within regular expressions, such as <code>\n</code> = newline, <code>\uNNNN</code> = unicode
2448 </p>
2449 </li>
2450 <li>
2452 Partially supported constraint escapes: <code>\A</code> = start of string, <code>\Z</code> = end of string
2453 </p>
2454 </li>
2455 <li>
2457 Support for the <code>?</code> non-greedy quantifier. e.g. <code>*?</code>
2458 </p>
2459 </li>
2460 <li>
2462 Support for non-capturing parentheses <code>(?:&#8230;)</code>
2463 </p>
2464 </li>
2465 <li>
2467 Jim Tcl considers that both patterns and strings end at a null character (<code>\x00</code>)
2468 </p>
2469 </li>
2470 </ol></div>
2471 </div>
2472 </div>
2473 </div>
2474 <div class="sect1">
2475 <h2 id="_command_results">COMMAND RESULTS</h2>
2476 <div class="sectionbody">
2477 <div class="paragraph"><p>Each command produces two results: a code and a string. The
2478 code indicates whether the command completed successfully or not,
2479 and the string gives additional information. The valid codes are
2480 defined in jim.h, and are:</p></div>
2481 <div class="dlist"><dl>
2482 <dt class="hdlist1">
2483 <code>JIM_OK(0)</code>
2484 </dt>
2485 <dd>
2487 This is the normal return code, and indicates that the command completed
2488 successfully. The string gives the command&#8217;s return value.
2489 </p>
2490 </dd>
2491 <dt class="hdlist1">
2492 <code>JIM_ERR(1)</code>
2493 </dt>
2494 <dd>
2496 Indicates that an error occurred; the string gives a message describing
2497 the error.
2498 </p>
2499 </dd>
2500 <dt class="hdlist1">
2501 <code>JIM_RETURN(2)</code>
2502 </dt>
2503 <dd>
2505 Indicates that the <a href="#_return"><strong><code>return</code></strong></a> command has been invoked, and that the
2506 current procedure (or top-level command or <a href="#_source"><strong><code>source</code></strong></a> command)
2507 should return immediately. The
2508 string gives the return value for the procedure or command.
2509 </p>
2510 </dd>
2511 <dt class="hdlist1">
2512 <code>JIM_BREAK(3)</code>
2513 </dt>
2514 <dd>
2516 Indicates that the <a href="#_break"><strong><code>break</code></strong></a> command has been invoked, so the
2517 innermost loop should abort immediately. The string should always
2518 be empty.
2519 </p>
2520 </dd>
2521 <dt class="hdlist1">
2522 <code>JIM_CONTINUE(4)</code>
2523 </dt>
2524 <dd>
2526 Indicates that the <a href="#_continue"><strong><code>continue</code></strong></a> command has been invoked, so the
2527 innermost loop should go on to the next iteration. The string
2528 should always be empty.
2529 </p>
2530 </dd>
2531 <dt class="hdlist1">
2532 <code>JIM_SIGNAL(5)</code>
2533 </dt>
2534 <dd>
2536 Indicates that a signal was caught while executing a commands.
2537 The string contains the name of the signal caught.
2538 See the <a href="#_signal"><strong><code>signal</code></strong></a> and <a href="#_catch"><strong><code>catch</code></strong></a> commands.
2539 </p>
2540 </dd>
2541 <dt class="hdlist1">
2542 <code>JIM_EXIT(6)</code>
2543 </dt>
2544 <dd>
2546 Indicates that the command called the <a href="#_exit"><strong><code>exit</code></strong></a> command.
2547 The string contains the exit code.
2548 </p>
2549 </dd>
2550 </dl></div>
2551 <div class="paragraph"><p>Tcl programmers do not normally need to think about return codes,
2552 since <code>JIM_OK</code> is almost always returned. If anything else is returned
2553 by a command, then the Tcl interpreter immediately stops processing
2554 commands and returns to its caller. If there are several nested
2555 invocations of the Tcl interpreter in progress, then each nested
2556 command will usually return the error to its caller, until eventually
2557 the error is reported to the top-level application code. The
2558 application will then display the error message for the user.</p></div>
2559 <div class="paragraph"><p>In a few cases, some commands will handle certain <a href="#_error"><strong><code>error</code></strong></a> conditions
2560 themselves and not return them upwards. For example, the <a href="#_for"><strong><code>for</code></strong></a>
2561 command checks for the <code>JIM_BREAK</code> code; if it occurs, then <a href="#_for"><strong><code>for</code></strong></a>
2562 stops executing the body of the loop and returns <code>JIM_OK</code> to its
2563 caller. The <a href="#_for"><strong><code>for</code></strong></a> command also handles <code>JIM_CONTINUE</code> codes and the
2564 procedure interpreter handles <code>JIM_RETURN</code> codes. The <a href="#_catch"><strong><code>catch</code></strong></a>
2565 command allows Tcl programs to catch errors and handle them without
2566 aborting command interpretation any further.</p></div>
2567 <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
2568 return codes and names.</p></div>
2569 </div>
2570 </div>
2571 <div class="sect1">
2572 <h2 id="_procedures">PROCEDURES</h2>
2573 <div class="sectionbody">
2574 <div class="paragraph"><p>Tcl allows you to extend the command interface by defining
2575 procedures. A Tcl procedure can be invoked just like any other Tcl
2576 command (it has a name and it receives one or more arguments).
2577 The only difference is that its body isn&#8217;t a piece of C code linked
2578 into the program; it is a string containing one or more other
2579 Tcl commands.</p></div>
2580 <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>
2581 <div class="paragraph"><p><code><strong>proc</strong> <em>name arglist ?statics? body</em></code></p></div>
2582 <div class="paragraph"><p>The new command is named <code><em>name</em></code>, and it replaces any existing command
2583 there may have been by that name. Whenever the new command is
2584 invoked, the contents of <code><em>body</em></code> will be executed by the Tcl
2585 interpreter.</p></div>
2586 <div class="paragraph"><p><code><em>arglist</em></code> specifies the formal arguments to the procedure.
2587 It consists of a list, possibly empty, of the following
2588 argument specifiers:</p></div>
2589 <div class="dlist"><dl>
2590 <dt class="hdlist1">
2591 <code>name</code>
2592 </dt>
2593 <dd>
2595 Required Argument - A simple argument name.
2596 </p>
2597 </dd>
2598 <dt class="hdlist1">
2599 <code>{name default}</code>
2600 </dt>
2601 <dd>
2603 Optional Argument - A two-element list consisting of the
2604 argument name, followed by the default value, which will
2605 be used if the corresponding argument is not supplied.
2606 </p>
2607 </dd>
2608 <dt class="hdlist1">
2609 <code>&amp;name</code>
2610 </dt>
2611 <dd>
2613 Reference Argument - The caller is expected to pass the name of
2614 an existing variable. An implicit <code><a href="#_upvar"><strong><code>upvar</code></strong></a> 1 origname name</code> is done
2615 to make the variable available in the proc scope.
2616 </p>
2617 </dd>
2618 <dt class="hdlist1">
2619 <code><strong>args</strong></code>
2620 </dt>
2621 <dd>
2623 Variable Argument - The special name <code><em>args</em></code>, which is
2624 assigned all remaining arguments (including none) as a list. The
2625 variable argument may only be specified once. Note that
2626 the syntax <code>{args newname}</code> may be used to retain the special
2627 behaviour of <code><em>args</em></code> with a different local name. In this case,
2628 the variable is named <code><em>newname</em></code> rather than <code><em>args</em></code>.
2629 </p>
2630 </dd>
2631 </dl></div>
2632 <div class="paragraph"><p>When the command is invoked, a local variable will be created for each of
2633 the formal arguments to the procedure; its value will be the value
2634 of corresponding argument in the invoking command or the argument&#8217;s
2635 default value.</p></div>
2636 <div class="paragraph"><p>Arguments with default values need not be specified in a procedure
2637 invocation. However, there must be enough actual arguments for all
2638 required arguments, and there must not be any extra actual arguments
2639 (unless the Variable Argument is specified).</p></div>
2640 <div class="paragraph"><p>Actual arguments are assigned to formal arguments as in left-to-right
2641 order with the following precedence.</p></div>
2642 <div class="olist arabic"><ol class="arabic">
2643 <li>
2645 Required Arguments (including Reference Arguments)
2646 </p>
2647 </li>
2648 <li>
2650 Optional Arguments
2651 </p>
2652 </li>
2653 <li>
2655 Variable Argument
2656 </p>
2657 </li>
2658 </ol></div>
2659 <div class="paragraph"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2660 <div class="literalblock">
2661 <div class="content">
2662 <pre><code>proc p {{a A} args b {c C} d} {...}</code></pre>
2663 </div></div>
2664 <div class="paragraph"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2665 The following table shows how various numbers of arguments are assigned.
2666 Values marked as <code>-</code> are assigned the default value.</p></div>
2667 <div class="tableblock">
2668 <table rules="all"
2669 width="40%"
2670 frame="hsides"
2671 cellspacing="0" cellpadding="4">
2672 <col width="16%" />
2673 <col width="16%" />
2674 <col width="16%" />
2675 <col width="16%" />
2676 <col width="16%" />
2677 <col width="16%" />
2678 <thead>
2679 <tr>
2680 <th align="left" valign="top">Number of arguments</th>
2681 <th align="left" valign="top">a</th>
2682 <th align="left" valign="top">args</th>
2683 <th align="left" valign="top">b</th>
2684 <th align="left" valign="top">c</th>
2685 <th align="left" valign="top">d</th>
2686 </tr>
2687 </thead>
2688 <tbody>
2689 <tr>
2690 <td align="left" valign="top"><p class="table">2</p></td>
2691 <td align="left" valign="top"><p class="table">-</p></td>
2692 <td align="left" valign="top"><p class="table">-</p></td>
2693 <td align="left" valign="top"><p class="table">1</p></td>
2694 <td align="left" valign="top"><p class="table">-</p></td>
2695 <td align="left" valign="top"><p class="table">2</p></td>
2696 </tr>
2697 <tr>
2698 <td align="left" valign="top"><p class="table">3</p></td>
2699 <td align="left" valign="top"><p class="table">1</p></td>
2700 <td align="left" valign="top"><p class="table">-</p></td>
2701 <td align="left" valign="top"><p class="table">2</p></td>
2702 <td align="left" valign="top"><p class="table">-</p></td>
2703 <td align="left" valign="top"><p class="table">3</p></td>
2704 </tr>
2705 <tr>
2706 <td align="left" valign="top"><p class="table">4</p></td>
2707 <td align="left" valign="top"><p class="table">1</p></td>
2708 <td align="left" valign="top"><p class="table">-</p></td>
2709 <td align="left" valign="top"><p class="table">2</p></td>
2710 <td align="left" valign="top"><p class="table">3</p></td>
2711 <td align="left" valign="top"><p class="table">4</p></td>
2712 </tr>
2713 <tr>
2714 <td align="left" valign="top"><p class="table">5</p></td>
2715 <td align="left" valign="top"><p class="table">1</p></td>
2716 <td align="left" valign="top"><p class="table">2</p></td>
2717 <td align="left" valign="top"><p class="table">3</p></td>
2718 <td align="left" valign="top"><p class="table">4</p></td>
2719 <td align="left" valign="top"><p class="table">5</p></td>
2720 </tr>
2721 <tr>
2722 <td align="left" valign="top"><p class="table">6</p></td>
2723 <td align="left" valign="top"><p class="table">1</p></td>
2724 <td align="left" valign="top"><p class="table">2,3</p></td>
2725 <td align="left" valign="top"><p class="table">4</p></td>
2726 <td align="left" valign="top"><p class="table">5</p></td>
2727 <td align="left" valign="top"><p class="table">6</p></td>
2728 </tr>
2729 </tbody>
2730 </table>
2731 </div>
2732 <div class="paragraph"><p>When <code><em>body</em></code> is being executed, variable names normally refer to local
2733 variables, which are created automatically when referenced and deleted
2734 when the procedure returns. One local variable is automatically created
2735 for each of the procedure&#8217;s arguments. Global variables can be
2736 accessed by invoking the <a href="#_global"><strong><code>global</code></strong></a> command or via the <code>::</code> prefix.</p></div>
2737 <div class="sect2">
2738 <h3 id="_new_in_jim">New in Jim</h3>
2739 <div class="paragraph"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2740 These variables scoped to the procedure and initialised at procedure definition.
2741 Either from the static variable definition, or from the enclosing scope.</p></div>
2742 <div class="paragraph"><p>Consider the following example:</p></div>
2743 <div class="literalblock">
2744 <div class="content">
2745 <pre><code>jim&gt; set a 1
2746 jim&gt; proc a {} {a {b 2}} {
2747 set c 1
2748 puts "$a $b $c"
2749 incr a
2750 incr b
2751 incr c
2753 jim&gt; a
2754 1 2 1
2755 jim&gt; a
2756 2 3 1</code></pre>
2757 </div></div>
2758 <div class="paragraph"><p>The static variable <code><em>a</em></code> has no initialiser, so it is initialised from
2759 the enclosing scope with the value 1. (Note that it is an error if there
2760 is no variable with the same name in the enclosing scope). However <code><em>b</em></code>
2761 has an initialiser, so it is initialised to 2.</p></div>
2762 <div class="paragraph"><p>Unlike a local variable, the value of a static variable is retained across
2763 invocations of the procedure.</p></div>
2764 <div class="paragraph"><p>See the <a href="#_proc"><strong><code>proc</code></strong></a> command for information on how to define procedures
2765 and what happens when they are invoked. See also NAMESPACES.</p></div>
2766 </div>
2767 </div>
2768 </div>
2769 <div class="sect1">
2770 <h2 id="_variables_scalars_and_arrays">VARIABLES - SCALARS AND ARRAYS</h2>
2771 <div class="sectionbody">
2772 <div class="paragraph"><p>Tcl allows the definition of variables and the use of their values
2773 either through <em>$</em>-style variable substitution, the <a href="#_set"><strong><code>set</code></strong></a>
2774 command, or a few other mechanisms.</p></div>
2775 <div class="paragraph"><p>Variables need not be declared: a new variable will automatically
2776 be created each time a new variable name is used.</p></div>
2777 <div class="paragraph"><p>Tcl supports two types of variables: scalars and arrays.
2778 A scalar variable has a single value, whereas an array variable
2779 can have any number of elements, each with a name (called
2780 its <em>index</em>) and a value.</p></div>
2781 <div class="paragraph"><p>Array indexes may be arbitrary strings; they need not be numeric.
2782 Parentheses are used refer to array elements in Tcl commands.
2783 For example, the command</p></div>
2784 <div class="literalblock">
2785 <div class="content">
2786 <pre><code>set x(first) 44</code></pre>
2787 </div></div>
2788 <div class="paragraph"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2789 so that its new value is <em>44</em>.</p></div>
2790 <div class="paragraph"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2791 that contain multiple concatenated values.
2792 For example, the commands</p></div>
2793 <div class="literalblock">
2794 <div class="content">
2795 <pre><code>set a(2,3) 1
2796 set a(3,6) 2</code></pre>
2797 </div></div>
2798 <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>
2799 <div class="paragraph"><p>In general, array elements may be used anywhere in Tcl that scalar
2800 variables may be used.</p></div>
2801 <div class="paragraph"><p>If an array is defined with a particular name, then there may
2802 not be a scalar variable with the same name.</p></div>
2803 <div class="paragraph"><p>Similarly, if there is a scalar variable with a particular
2804 name then it is not possible to make array references to the
2805 variable.</p></div>
2806 <div class="paragraph"><p>To convert a scalar variable to an array or vice versa, remove
2807 the existing variable with the <a href="#_unset"><strong><code>unset</code></strong></a> command.</p></div>
2808 <div class="paragraph"><p>The <a href="#_array"><strong><code>array</code></strong></a> command provides several features for dealing
2809 with arrays, such as querying the names of all the elements of
2810 the array and converting between an array and a list.</p></div>
2811 <div class="paragraph"><p>Variables may be either global or local. If a variable
2812 name is used when a procedure isn&#8217;t being executed, then it
2813 automatically refers to a global variable. Variable names used
2814 within a procedure normally refer to local variables associated with that
2815 invocation of the procedure. Local variables are deleted whenever
2816 a procedure exits. Either <a href="#_global"><strong><code>global</code></strong></a> command may be used to request
2817 that a name refer to a global variable for the duration of the current
2818 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2819 may be explicitly scoped with the <code>::</code> prefix. For example</p></div>
2820 <div class="literalblock">
2821 <div class="content">
2822 <pre><code>set a 1
2823 set b 2
2824 proc p {} {
2825 set c 3
2826 global a</code></pre>
2827 </div></div>
2828 <div class="literalblock">
2829 <div class="content">
2830 <pre><code> puts "$a $::b $c"
2832 p</code></pre>
2833 </div></div>
2834 <div class="paragraph"><p>will output:</p></div>
2835 <div class="literalblock">
2836 <div class="content">
2837 <pre><code>1 2 3</code></pre>
2838 </div></div>
2839 </div>
2840 </div>
2841 <div class="sect1">
2842 <h2 id="_arrays_as_lists_in_jim">ARRAYS AS LISTS IN JIM</h2>
2843 <div class="sectionbody">
2844 <div class="paragraph"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2845 number of elements) and an array value. This is similar to the way Tcl
2846 can convert between a string and a list.</p></div>
2847 <div class="paragraph"><p>For example:</p></div>
2848 <div class="literalblock">
2849 <div class="content">
2850 <pre><code>set a {1 one 2 two}
2851 puts $a(2)</code></pre>
2852 </div></div>
2853 <div class="paragraph"><p>will output:</p></div>
2854 <div class="literalblock">
2855 <div class="content">
2856 <pre><code>two</code></pre>
2857 </div></div>
2858 <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
2859 exist or is empty.</p></div>
2860 <div class="paragraph"><p>The reverse is also true where an array will be converted into
2861 a list.</p></div>
2862 <div class="literalblock">
2863 <div class="content">
2864 <pre><code>set a(1) one; set a(2) two
2865 puts $a</code></pre>
2866 </div></div>
2867 <div class="paragraph"><p>will output:</p></div>
2868 <div class="literalblock">
2869 <div class="content">
2870 <pre><code>1 one 2 two</code></pre>
2871 </div></div>
2872 </div>
2873 </div>
2874 <div class="sect1">
2875 <h2 id="_dictionary_values">DICTIONARY VALUES</h2>
2876 <div class="sectionbody">
2877 <div class="paragraph"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2878 of this command. Dictionaries provide efficient access to key-value
2879 pairs, just like arrays, but dictionaries are pure values. This
2880 means that you can pass them to a procedure just as a list or a
2881 string. Tcl dictionaries are therefore much more like Tcl lists,
2882 except that they represent a mapping from keys to values, rather
2883 than an ordered sequence.</p></div>
2884 <div class="paragraph"><p>You can nest dictionaries, so that the value for a particular key
2885 consists of another dictionary. That way you can elegantly build
2886 complicated data structures, such as hierarchical databases. You
2887 can also combine dictionaries with other Tcl data structures. For
2888 instance, you can build a list of dictionaries that themselves
2889 contain lists.</p></div>
2890 <div class="paragraph"><p>Dictionaries are values that contain an efficient, order-preserving
2891 mapping from arbitrary keys to arbitrary values. Each key in the
2892 dictionary maps to a single value. They have a textual format that
2893 is exactly that of any list with an even number of elements, with
2894 each mapping in the dictionary being represented as two items in
2895 the list. When a command takes a dictionary and produces a new
2896 dictionary based on it (either returning it or writing it back into
2897 the variable that the starting dictionary was read from) the new
2898 dictionary will have the same order of keys, modulo any deleted
2899 keys and with new keys added on to the end. When a string is
2900 interpreted as a dictionary and it would otherwise have duplicate
2901 keys, only the last value for a particular key is used; the others
2902 are ignored, meaning that, "apple banana" and "apple carrot apple
2903 banana" are equivalent dictionaries (with different string
2904 representations).</p></div>
2905 <div class="paragraph"><p>Note that in Jim, arrays are implemented as dictionaries.
2906 Thus automatic conversion between lists and dictionaries applies
2907 as it does for arrays.</p></div>
2908 <div class="literalblock">
2909 <div class="content">
2910 <pre><code>jim&gt; dict set a 1 one
2911 1 one
2912 jim&gt; dict set a 2 two
2913 1 one 2 two
2914 jim&gt; puts $a
2915 1 one 2 two
2916 jim&gt; puts $a(2)
2918 jim&gt; dict set a 3 T three
2919 1 one 2 two 3 {T three}</code></pre>
2920 </div></div>
2921 <div class="paragraph"><p>See the <a href="#_dict"><strong><code>dict</code></strong></a> command for more details.</p></div>
2922 </div>
2923 </div>
2924 <div class="sect1">
2925 <h2 id="_namespaces">NAMESPACES</h2>
2926 <div class="sectionbody">
2927 <div class="paragraph"><p>Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
2928 including a number of 3rd party components. While there is less need for namespaces
2929 in Jim Tcl (which does not strive to support large applications), it is convenient to
2930 provide a subset of the support for namespaces to easy porting code from Tcl.</p></div>
2931 <div class="paragraph"><p>Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
2932 purposes. This feature is currently experimental. See README.namespaces for more information
2933 and the documentation of the <a href="#_namespace"><strong><code>namespace</code></strong></a> command.</p></div>
2934 </div>
2935 </div>
2936 <div class="sect1">
2937 <h2 id="_garbage_collection_references_lambda_function">GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION</h2>
2938 <div class="sectionbody">
2939 <div class="paragraph"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
2940 These are described briefly below.</p></div>
2941 <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>
2942 <div class="sect2">
2943 <h3 id="_references">References</h3>
2944 <div class="paragraph"><p>A reference can be thought of as holding a value with one level of indirection,
2945 where the value may be garbage collected when unreferenced.
2946 Consider the following example:</p></div>
2947 <div class="literalblock">
2948 <div class="content">
2949 <pre><code>jim&gt; set r [ref "One String" test]
2950 &lt;reference.&lt;test___&gt;.00000000000000000000&gt;
2951 jim&gt; getref $r
2952 One String</code></pre>
2953 </div></div>
2954 <div class="paragraph"><p>The operation <a href="#_ref"><strong><code>ref</code></strong></a> creates a references to the value specified by the
2955 first argument. (The second argument is a "type" used for documentation purposes).</p></div>
2956 <div class="paragraph"><p>The operation <a href="#_getref"><strong><code>getref</code></strong></a> is the dereferencing operation which retrieves the value
2957 stored in the reference.</p></div>
2958 <div class="literalblock">
2959 <div class="content">
2960 <pre><code>jim&gt; setref $r "New String"
2961 New String
2962 jim&gt; getref $r
2963 New String</code></pre>
2964 </div></div>
2965 <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
2966 is no longer accessible by any reference, it will eventually be automatically be garbage
2967 collected.</p></div>
2968 </div>
2969 <div class="sect2">
2970 <h3 id="_garbage_collection">Garbage Collection</h3>
2971 <div class="paragraph"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
2972 automatically as necessary.</p></div>
2973 <div class="paragraph"><p>With the introduction of references, it is possible to create values whose lifetime
2974 transcend their scope. To support this, case, the Jim system will periodically identify
2975 and discard objects which are no longer accessible by any reference.</p></div>
2976 <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
2977 with a finalizer:</p></div>
2978 <div class="literalblock">
2979 <div class="content">
2980 <pre><code>jim&gt; proc f {ref value} { puts "Finaliser called for $ref,$value" }
2981 jim&gt; set r [ref "One String" test f]
2982 &lt;reference.&lt;test___&gt;.00000000000
2983 jim&gt; collect
2985 jim&gt; set r ""
2986 jim&gt; collect
2987 Finaliser called for &lt;reference.&lt;test___&gt;.00000000000,One String
2988 1</code></pre>
2989 </div></div>
2990 <div class="paragraph"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
2991 contained a reference to the value, the garbage collector discarded
2992 the value (after calling the finalizer).</p></div>
2993 <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>
2994 <div class="literalblock">
2995 <div class="content">
2996 <pre><code>jim&gt; finalize $r
2998 jim&gt; finalize $r newf
2999 newf</code></pre>
3000 </div></div>
3001 </div>
3002 <div class="sect2">
3003 <h3 id="_lambda_function">Lambda Function</h3>
3004 <div class="paragraph"><p>Jim provides a garbage collected <a href="#_lambda"><strong><code>lambda</code></strong></a> function. This is a procedure
3005 which is able to create an anonymous procedure. Consider:</p></div>
3006 <div class="literalblock">
3007 <div class="content">
3008 <pre><code>jim&gt; set f [lambda {a} {{x 0}} { incr x $a }]
3009 jim&gt; $f 1
3011 jim&gt; $f 2
3013 jim&gt; set f ""</code></pre>
3014 </div></div>
3015 <div class="paragraph"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
3016 which is incremented by the supplied value and the result returned.</p></div>
3017 <div class="paragraph"><p>Once the procedure name is no longer accessible, it will automatically be deleted
3018 when the garbage collector runs.</p></div>
3019 <div class="paragraph"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
3020 <div class="literalblock">
3021 <div class="content">
3022 <pre><code>jim&gt; rename $f ""</code></pre>
3023 </div></div>
3024 </div>
3025 </div>
3026 </div>
3027 <div class="sect1">
3028 <h2 id="_utf_8_and_unicode">UTF-8 AND UNICODE</h2>
3029 <div class="sectionbody">
3030 <div class="paragraph"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
3031 then most string-related commands become UTF-8 aware. These include,
3032 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
3033 <a href="#_format"><strong><code>format</code></strong></a>.</p></div>
3034 <div class="paragraph"><p>UTF-8 encoding has many advantages, but one of the complications is that
3035 characters can take a variable number of bytes. Thus the addition of
3036 <a href="#_string"><strong><code>string</code></strong></a> <code>bytelength</code> which returns the number of bytes in a string,
3037 while <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> returns the number of characters.</p></div>
3038 <div class="paragraph"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
3039 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>
3040 <div class="paragraph"><p>Note that even if UTF-8 support is not enabled, the <code>\uNNNN</code> and related syntax
3041 is still available to embed UTF-8 sequences.</p></div>
3042 <div class="paragraph"><p>Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +<em>U+1FFFFF</em>.</p></div>
3043 <div class="sect2">
3044 <h3 id="_string_matching">String Matching</h3>
3045 <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
3046 pattern matching rules. These commands support UTF-8. For example:</p></div>
3047 <div class="literalblock">
3048 <div class="content">
3049 <pre><code>string match a\[\ua0-\ubf\]b "a\u00a3b"</code></pre>
3050 </div></div>
3051 </div>
3052 <div class="sect2">
3053 <h3 id="_format_and_scan">format and scan</h3>
3054 <div class="paragraph"><p><code>format %c</code> allows a unicode codepoint to be be encoded. For example, the following will return
3055 a string with two bytes and one character. The same as <code>\ub5</code></p></div>
3056 <div class="literalblock">
3057 <div class="content">
3058 <pre><code>format %c 0xb5</code></pre>
3059 </div></div>
3060 <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
3061 return a string with three characters, not three bytes.</p></div>
3062 <div class="literalblock">
3063 <div class="content">
3064 <pre><code>format %.3s \ub5\ub6\ub7\ub8</code></pre>
3065 </div></div>
3066 <div class="paragraph"><p>Similarly, <code>scan &#8230; %c</code> allows a UTF-8 to be decoded to a unicode codepoint. The following will set
3067 <code><em>a</em></code> to 181 (0xb5) and <code><em>b</em></code> to 65 (0x41).</p></div>
3068 <div class="literalblock">
3069 <div class="content">
3070 <pre><code>scan \u00b5A %c%c a b</code></pre>
3071 </div></div>
3072 <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>
3073 </div>
3074 <div class="sect2">
3075 <h3 id="_string_classes">String Classes</h3>
3076 <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
3077 will return 0, even though the string may be considered to be alphabetic.</p></div>
3078 <div class="literalblock">
3079 <div class="content">
3080 <pre><code>string is alpha \ub5Test</code></pre>
3081 </div></div>
3082 <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>
3083 </div>
3084 <div class="sect2">
3085 <h3 id="_case_mapping_and_conversion">Case Mapping and Conversion</h3>
3086 <div class="paragraph"><p>Jim provides a simplified unicode case mapping. This means that case conversion
3087 and comparison will not increase or decrease the number of characters in a string.
3088 (Although it may change the number of bytes).</p></div>
3089 <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.
3090 Any character which is not a letter or has no uppercase equivalent is left unchanged.
3091 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>
3092 <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>
3093 and <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-nocase</code> fold both strings to uppercase before comparison.</p></div>
3094 </div>
3095 <div class="sect2">
3096 <h3 id="_invalid_utf_8_sequences">Invalid UTF-8 Sequences</h3>
3097 <div class="paragraph"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
3098 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
3099 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
3100 <div class="paragraph"><p>In these situations, the offending bytes are treated as single characters. For example,
3101 the following returns 2.</p></div>
3102 <div class="literalblock">
3103 <div class="content">
3104 <pre><code>string bytelength \xff\xff</code></pre>
3105 </div></div>
3106 </div>
3107 <div class="sect2">
3108 <h3 id="_regular_expressions_2">Regular Expressions</h3>
3109 <div class="paragraph"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
3110 selected which supports UTF-8 strings and patterns.</p></div>
3111 <div class="paragraph"><p>See REGULAR EXPRESSIONS</p></div>
3112 </div>
3113 </div>
3114 </div>
3115 <div class="sect1">
3116 <h2 id="_built_in_commands">BUILT-IN COMMANDS</h2>
3117 <div class="sectionbody">
3118 <div class="paragraph"><p>The Tcl library provides the following built-in commands, which will
3119 be available in any application using Tcl. In addition to these
3120 built-in commands, there may be additional commands defined by each
3121 application, plus commands defined as Tcl procedures.</p></div>
3122 <div class="paragraph"><p>In the command syntax descriptions below, words in <code><strong>boldface</strong></code> are
3123 literals that you type verbatim to Tcl.</p></div>
3124 <div class="paragraph"><p>Words in <code><em>italics</em></code> are meta-symbols; they serve as names for any of
3125 a range of values that you can type.</p></div>
3126 <div class="paragraph"><p>Optional arguments or groups of arguments are indicated by enclosing them
3127 in <code>?question-marks?</code>.</p></div>
3128 <div class="paragraph"><p>Ellipses (<code>...</code>) indicate that any number of additional
3129 arguments or groups of arguments may appear, in the same format
3130 as the preceding argument(s).</p></div>
3131 <div class="sect2">
3132 <h3 id="CommandIndex">Command Index</h3>
3133 <div class="tableblock">
3134 <table rules="none"
3135 width="100%"
3136 frame="void"
3137 cellspacing="0" cellpadding="4">
3138 <col width="12%" />
3139 <col width="12%" />
3140 <col width="12%" />
3141 <col width="12%" />
3142 <col width="12%" />
3143 <col width="12%" />
3144 <col width="12%" />
3145 <col width="12%" />
3146 <tbody>
3147 <tr>
3148 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>after</code></strong></a></p></td>
3149 <td align="left" valign="top"><p class="table"><a href="#_aio"><strong><code>aio</code></strong></a></p></td>
3150 <td align="left" valign="top"><p class="table"><a href="#_alarm"><strong><code>alarm</code></strong></a></p></td>
3151 <td align="left" valign="top"><p class="table"><a href="#_alias"><strong><code>alias</code></strong></a></p></td>
3152 <td align="left" valign="top"><p class="table"><a href="#_append"><strong><code>append</code></strong></a></p></td>
3153 <td align="left" valign="top"><p class="table"><a href="#_apply"><strong><code>apply</code></strong></a></p></td>
3154 <td align="left" valign="top"><p class="table"><a href="#_array"><strong><code>array</code></strong></a></p></td>
3155 <td align="left" valign="top"><p class="table"><a href="#_binary"><strong><code>binary</code></strong></a></p></td>
3156 </tr>
3157 <tr>
3158 <td align="left" valign="top"><p class="table"><a href="#_break"><strong><code>break</code></strong></a></p></td>
3159 <td align="left" valign="top"><p class="table"><a href="#_case"><strong><code>case</code></strong></a></p></td>
3160 <td align="left" valign="top"><p class="table"><a href="#_catch"><strong><code>catch</code></strong></a></p></td>
3161 <td align="left" valign="top"><p class="table"><a href="#_cd"><strong><code>cd</code></strong></a></p></td>
3162 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>class</code></strong></a></p></td>
3163 <td align="left" valign="top"><p class="table"><a href="#_clock"><strong><code>clock</code></strong></a></p></td>
3164 <td align="left" valign="top"><p class="table"><a href="#_close"><strong><code>close</code></strong></a></p></td>
3165 <td align="left" valign="top"><p class="table"><a href="#_collect"><strong><code>collect</code></strong></a></p></td>
3166 </tr>
3167 <tr>
3168 <td align="left" valign="top"><p class="table"><a href="#_concat"><strong><code>concat</code></strong></a></p></td>
3169 <td align="left" valign="top"><p class="table"><a href="#_continue"><strong><code>continue</code></strong></a></p></td>
3170 <td align="left" valign="top"><p class="table"><a href="#_curry"><strong><code>curry</code></strong></a></p></td>
3171 <td align="left" valign="top"><p class="table"><a href="#_dict"><strong><code>dict</code></strong></a></p></td>
3172 <td align="left" valign="top"><p class="table"><a href="#_env"><strong><code>env</code></strong></a></p></td>
3173 <td align="left" valign="top"><p class="table"><a href="#_eof"><strong><code>eof</code></strong></a></p></td>
3174 <td align="left" valign="top"><p class="table"><a href="#_error"><strong><code>error</code></strong></a></p></td>
3175 <td align="left" valign="top"><p class="table"><a href="#_eval"><strong><code>eval</code></strong></a></p></td>
3176 </tr>
3177 <tr>
3178 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>eventloop</code></strong></a></p></td>
3179 <td align="left" valign="top"><p class="table"><a href="#_exec"><strong><code>exec</code></strong></a></p></td>
3180 <td align="left" valign="top"><p class="table"><a href="#_exists"><strong><code>exists</code></strong></a></p></td>
3181 <td align="left" valign="top"><p class="table"><a href="#_exit"><strong><code>exit</code></strong></a></p></td>
3182 <td align="left" valign="top"><p class="table"><a href="#_expr"><strong><code>expr</code></strong></a></p></td>
3183 <td align="left" valign="top"><p class="table"><a href="#_fconfigure"><strong><code>fconfigure</code></strong></a></p></td>
3184 <td align="left" valign="top"><p class="table"><a href="#_file"><strong><code>file</code></strong></a></p></td>
3185 <td align="left" valign="top"><p class="table"><a href="#_finalize"><strong><code>finalize</code></strong></a></p></td>
3186 </tr>
3187 <tr>
3188 <td align="left" valign="top"><p class="table"><a href="#_flush"><strong><code>flush</code></strong></a></p></td>
3189 <td align="left" valign="top"><p class="table"><a href="#_for"><strong><code>for</code></strong></a></p></td>
3190 <td align="left" valign="top"><p class="table"><a href="#_foreach"><strong><code>foreach</code></strong></a></p></td>
3191 <td align="left" valign="top"><p class="table"><a href="#_format"><strong><code>format</code></strong></a></p></td>
3192 <td align="left" valign="top"><p class="table"><a href="#_getref"><strong><code>getref</code></strong></a></p></td>
3193 <td align="left" valign="top"><p class="table"><a href="#_gets"><strong><code>gets</code></strong></a></p></td>
3194 <td align="left" valign="top"><p class="table"><a href="#_glob"><strong><code>glob</code></strong></a></p></td>
3195 <td align="left" valign="top"><p class="table"><a href="#_global"><strong><code>global</code></strong></a></p></td>
3196 </tr>
3197 <tr>
3198 <td align="left" valign="top"><p class="table"><a href="#_history"><strong><code>history</code></strong></a></p></td>
3199 <td align="left" valign="top"><p class="table"><a href="#_if"><strong><code>if</code></strong></a></p></td>
3200 <td align="left" valign="top"><p class="table"><a href="#_incr"><strong><code>incr</code></strong></a></p></td>
3201 <td align="left" valign="top"><p class="table"><a href="#_info"><strong><code>info</code></strong></a></p></td>
3202 <td align="left" valign="top"><p class="table"><a href="#_interp"><strong><code>interp</code></strong></a></p></td>
3203 <td align="left" valign="top"><p class="table"><a href="#_join"><strong><code>join</code></strong></a></p></td>
3204 <td align="left" valign="top"><p class="table"><a href="#_kill"><strong><code>kill</code></strong></a></p></td>
3205 <td align="left" valign="top"><p class="table"><a href="#_lambda"><strong><code>lambda</code></strong></a></p></td>
3206 </tr>
3207 <tr>
3208 <td align="left" valign="top"><p class="table"><a href="#_lappend"><strong><code>lappend</code></strong></a></p></td>
3209 <td align="left" valign="top"><p class="table"><a href="#_lassign"><strong><code>lassign</code></strong></a></p></td>
3210 <td align="left" valign="top"><p class="table"><a href="#_lindex"><strong><code>lindex</code></strong></a></p></td>
3211 <td align="left" valign="top"><p class="table"><a href="#_linsert"><strong><code>linsert</code></strong></a></p></td>
3212 <td align="left" valign="top"><p class="table"><a href="#_list"><strong><code>list</code></strong></a></p></td>
3213 <td align="left" valign="top"><p class="table"><a href="#_llength"><strong><code>llength</code></strong></a></p></td>
3214 <td align="left" valign="top"><p class="table"><a href="#_lmap"><strong><code>lmap</code></strong></a></p></td>
3215 <td align="left" valign="top"><p class="table"><a href="#_load"><strong><code>load</code></strong></a></p></td>
3216 </tr>
3217 <tr>
3218 <td align="left" valign="top"><p class="table"><a href="#_local"><strong><code>local</code></strong></a></p></td>
3219 <td align="left" valign="top"><p class="table"><a href="#_loop"><strong><code>loop</code></strong></a></p></td>
3220 <td align="left" valign="top"><p class="table"><a href="#_lrange"><strong><code>lrange</code></strong></a></p></td>
3221 <td align="left" valign="top"><p class="table"><a href="#_lrepeat"><strong><code>lrepeat</code></strong></a></p></td>
3222 <td align="left" valign="top"><p class="table"><a href="#_lreplace"><strong><code>lreplace</code></strong></a></p></td>
3223 <td align="left" valign="top"><p class="table"><a href="#_lreverse"><strong><code>lreverse</code></strong></a></p></td>
3224 <td align="left" valign="top"><p class="table"><a href="#_lsearch"><strong><code>lsearch</code></strong></a></p></td>
3225 <td align="left" valign="top"><p class="table"><a href="#_lset"><strong><code>lset</code></strong></a></p></td>
3226 </tr>
3227 <tr>
3228 <td align="left" valign="top"><p class="table"><a href="#_lsort"><strong><code>lsort</code></strong></a></p></td>
3229 <td align="left" valign="top"><p class="table"><a href="#_namespace"><strong><code>namespace</code></strong></a></p></td>
3230 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>oo</code></strong></a></p></td>
3231 <td align="left" valign="top"><p class="table"><a href="#_open"><strong><code>open</code></strong></a></p></td>
3232 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.fork</code></strong></a></p></td>
3233 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.gethostname</code></strong></a></p></td>
3234 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.getids</code></strong></a></p></td>
3235 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.uptime</code></strong></a></p></td>
3236 </tr>
3237 <tr>
3238 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.wait</code></strong></a></p></td>
3239 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3240 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3241 <td align="left" valign="top"><p class="table"><a href="#_package"><strong><code>package</code></strong></a></p></td>
3242 <td align="left" valign="top"><p class="table"><a href="#_pid"><strong><code>pid</code></strong></a></p></td>
3243 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>posix</code></strong></a></p></td>
3244 <td align="left" valign="top"><p class="table"><a href="#_proc"><strong><code>proc</code></strong></a></p></td>
3245 <td align="left" valign="top"><p class="table"><a href="#_puts"><strong><code>puts</code></strong></a></p></td>
3246 </tr>
3247 <tr>
3248 <td align="left" valign="top"><p class="table"><a href="#_pwd"><strong><code>pwd</code></strong></a></p></td>
3249 <td align="left" valign="top"><p class="table"><a href="#_rand"><strong><code>rand</code></strong></a></p></td>
3250 <td align="left" valign="top"><p class="table"><a href="#_range"><strong><code>range</code></strong></a></p></td>
3251 <td align="left" valign="top"><p class="table"><a href="#_read"><strong><code>read</code></strong></a></p></td>
3252 <td align="left" valign="top"><p class="table"><a href="#_ref"><strong><code>ref</code></strong></a></p></td>
3253 <td align="left" valign="top"><p class="table"><a href="#_regexp"><strong><code>regexp</code></strong></a></p></td>
3254 <td align="left" valign="top"><p class="table"><a href="#_regsub"><strong><code>regsub</code></strong></a></p></td>
3255 <td align="left" valign="top"><p class="table"><a href="#_rename"><strong><code>rename</code></strong></a></p></td>
3256 </tr>
3257 <tr>
3258 <td align="left" valign="top"><p class="table"><a href="#_return"><strong><code>return</code></strong></a></p></td>
3259 <td align="left" valign="top"><p class="table"><a href="#_scan"><strong><code>scan</code></strong></a></p></td>
3260 <td align="left" valign="top"><p class="table"><a href="#_seek"><strong><code>seek</code></strong></a></p></td>
3261 <td align="left" valign="top"><p class="table"><a href="#_set"><strong><code>set</code></strong></a></p></td>
3262 <td align="left" valign="top"><p class="table"><a href="#_setref"><strong><code>setref</code></strong></a></p></td>
3263 <td align="left" valign="top"><p class="table"><a href="#_signal"><strong><code>signal</code></strong></a></p></td>
3264 <td align="left" valign="top"><p class="table"><a href="#_sleep"><strong><code>sleep</code></strong></a></p></td>
3265 <td align="left" valign="top"><p class="table"><a href="#_socket"><strong><code>socket</code></strong></a></p></td>
3266 </tr>
3267 <tr>
3268 <td align="left" valign="top"><p class="table"><a href="#_source"><strong><code>source</code></strong></a></p></td>
3269 <td align="left" valign="top"><p class="table"><a href="#_split"><strong><code>split</code></strong></a></p></td>
3270 <td align="left" valign="top"><p class="table"><a href="#_stackdump"><strong><code>stackdump</code></strong></a></p></td>
3271 <td align="left" valign="top"><p class="table"><a href="#_stacktrace"><strong><code>stacktrace</code></strong></a></p></td>
3272 <td align="left" valign="top"><p class="table"><a href="#_string"><strong><code>string</code></strong></a></p></td>
3273 <td align="left" valign="top"><p class="table"><a href="#_subst"><strong><code>subst</code></strong></a></p></td>
3274 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>super</code></strong></a></p></td>
3275 <td align="left" valign="top"><p class="table"><a href="#_switch"><strong><code>switch</code></strong></a></p></td>
3276 </tr>
3277 <tr>
3278 <td align="left" valign="top"><p class="table"><a href="#_syslog"><strong><code>syslog</code></strong></a></p></td>
3279 <td align="left" valign="top"><p class="table"><a href="#_tailcall"><strong><code>tailcall</code></strong></a></p></td>
3280 <td align="left" valign="top"><p class="table"><a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a></p></td>
3281 <td align="left" valign="top"><p class="table"><a href="#_tell"><strong><code>tell</code></strong></a></p></td>
3282 <td align="left" valign="top"><p class="table"><a href="#_throw"><strong><code>throw</code></strong></a></p></td>
3283 <td align="left" valign="top"><p class="table"><a href="#_time"><strong><code>time</code></strong></a></p></td>
3284 <td align="left" valign="top"><p class="table"><a href="#_tree"><strong><code>tree</code></strong></a></p></td>
3285 <td align="left" valign="top"><p class="table"><a href="#_try"><strong><code>try</code></strong></a></p></td>
3286 </tr>
3287 <tr>
3288 <td align="left" valign="top"><p class="table"><a href="#_unknown"><strong><code>unknown</code></strong></a></p></td>
3289 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>unpack</code></strong></a></p></td>
3290 <td align="left" valign="top"><p class="table"><a href="#_unset"><strong><code>unset</code></strong></a></p></td>
3291 <td align="left" valign="top"><p class="table"><a href="#_upcall"><strong><code>upcall</code></strong></a></p></td>
3292 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>update</code></strong></a></p></td>
3293 <td align="left" valign="top"><p class="table"><a href="#_uplevel"><strong><code>uplevel</code></strong></a></p></td>
3294 <td align="left" valign="top"><p class="table"><a href="#_upvar"><strong><code>upvar</code></strong></a></p></td>
3295 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>vwait</code></strong></a></p></td>
3296 </tr>
3297 <tr>
3298 <td align="left" valign="top"><p class="table"><a href="#_while"><strong><code>while</code></strong></a></p></td>
3299 <td align="left" valign="top"><p class="table"><a href="#_zlib"><strong><code>zlib</code></strong></a></p></td>
3300 <td align="left" valign="top"><p class="table"></p></td>
3301 <td align="left" valign="top"><p class="table"></p></td>
3302 <td align="left" valign="top"><p class="table"></p></td>
3303 <td align="left" valign="top"><p class="table"></p></td>
3304 <td align="left" valign="top"><p class="table"></p></td>
3305 <td align="left" valign="top"><p class="table"></p></td>
3306 </tr>
3307 </tbody>
3308 </table>
3309 </div>
3310 </div>
3311 <div class="sect2">
3312 <h3 id="_alarm">alarm</h3>
3313 <div class="paragraph"><p><code><strong>alarm</strong> <em>seconds</em></code></p></div>
3314 <div class="paragraph"><p>Delivers the <code>SIGALRM</code> signal to the process after the given
3315 number of seconds. If the platform supports <em>ualarm(3)</em> then
3316 the argument may be a floating point value. Otherwise it must
3317 be an integer.</p></div>
3318 <div class="paragraph"><p>Note that unless a signal handler for <code>SIGALRM</code> has been installed
3319 (see <a href="#_signal"><strong><code>signal</code></strong></a>), the process will exit on this signal.</p></div>
3320 </div>
3321 <div class="sect2">
3322 <h3 id="_alias">alias</h3>
3323 <div class="paragraph"><p><code><strong>alias</strong> <em>name args...</em></code></p></div>
3324 <div class="paragraph"><p>Creates a single word alias (command) for one or more words. For example,
3325 the following creates an alias for the command <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>.</p></div>
3326 <div class="literalblock">
3327 <div class="content">
3328 <pre><code>alias e info exists
3329 if {[e var]} {
3331 }</code></pre>
3332 </div></div>
3333 <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>
3334 <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>
3335 </div>
3336 <div class="sect2">
3337 <h3 id="_append">append</h3>
3338 <div class="paragraph"><p><code><strong>append</strong> <em>varName value ?value value &#8230;?</em></code></p></div>
3339 <div class="paragraph"><p>Append all of the <code><em>value</em></code> arguments to the current value
3340 of variable <code><em>varName</em></code>. If <code><em>varName</em></code> doesn&#8217;t exist,
3341 it is given a value equal to the concatenation of all the
3342 <code><em>value</em></code> arguments.</p></div>
3343 <div class="paragraph"><p>This command provides an efficient way to build up long
3344 variables incrementally.
3345 For example, "<a href="#_append"><strong><code>append</code></strong></a> <code>a $b</code>" is much more efficient than
3346 "<a href="#_set"><strong><code>set</code></strong></a> <code>a $a$b</code>" if <code>$a</code> is long.</p></div>
3347 </div>
3348 <div class="sect2">
3349 <h3 id="_apply">apply</h3>
3350 <div class="paragraph"><p><code><strong>apply</strong> <em>lambdaExpr ?arg1 arg2 ...?</em></code></p></div>
3351 <div class="paragraph"><p>The command <a href="#_apply"><strong><code>apply</code></strong></a> provides for anonymous procedure calls,
3352 similar to <a href="#_lambda"><strong><code>lambda</code></strong></a>, but without command name being created, even temporarily.</p></div>
3353 <div class="paragraph"><p>The function <code><em>lambdaExpr</em></code> is a two element list <code>{args body}</code>
3354 or a three element list <code>{args body namespace}</code>. The first element
3355 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>
3356 </div>
3357 <div class="sect2">
3358 <h3 id="_array">array</h3>
3359 <div class="paragraph"><p><code><strong>array</strong> <em>option arrayName ?arg...?</em></code></p></div>
3360 <div class="paragraph"><p>This command performs one of several operations on the
3361 variable given by <code><em>arrayName</em></code>.</p></div>
3362 <div class="paragraph"><p>Note that in general, if the named array does not exist, the <code><em>array</em></code> command behaves
3363 as though the array exists but is empty.</p></div>
3364 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3365 command. The legal <code><em>options</em></code> (which may be abbreviated) are:</p></div>
3366 <div class="dlist"><dl>
3367 <dt class="hdlist1">
3368 <code><strong>array exists</strong> <em>arrayName</em></code>
3369 </dt>
3370 <dd>
3372 Returns 1 if arrayName is an array variable, 0 if there is
3373 no variable by that name. This command is essentially
3374 identical to <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>
3375 </p>
3376 </dd>
3377 <dt class="hdlist1">
3378 <code><strong>array get</strong> <em>arrayName ?pattern?</em></code>
3379 </dt>
3380 <dd>
3382 Returns a list containing pairs of elements. The first
3383 element in each pair is the name of an element in arrayName
3384 and the second element of each pair is the value of the
3385 array element. The order of the pairs is undefined. If
3386 pattern is not specified, then all of the elements of the
3387 array are included in the result. If pattern is specified,
3388 then only those elements whose names match pattern (using
3389 the matching rules of string match) are included. If arrayName
3390 isn&#8217;t the name of an array variable, or if the array contains
3391 no elements, then an empty list is returned.
3392 </p>
3393 </dd>
3394 <dt class="hdlist1">
3395 <code><strong>array names</strong> <em>arrayName ?pattern?</em></code>
3396 </dt>
3397 <dd>
3399 Returns a list containing the names of all of the elements
3400 in the array that match pattern. If pattern is omitted then
3401 the command returns all of the element names in the array.
3402 If pattern is specified, then only those elements whose
3403 names match pattern (using the matching rules of string
3404 match) are included. If there are no (matching) elements
3405 in the array, or if arrayName isn&#8217;t the name of an array
3406 variable, then an empty string is returned.
3407 </p>
3408 </dd>
3409 <dt class="hdlist1">
3410 <code><strong>array set</strong> <em>arrayName list</em></code>
3411 </dt>
3412 <dd>
3414 Sets the values of one or more elements in arrayName. list
3415 must have a form like that returned by array get, consisting
3416 of an even number of elements. Each odd-numbered element
3417 in list is treated as an element name within arrayName, and
3418 the following element in list is used as a new value for
3419 that array element. If the variable arrayName does not
3420 already exist and list is empty, arrayName is created with
3421 an empty array value.
3422 </p>
3423 </dd>
3424 <dt class="hdlist1">
3425 <code><strong>array size</strong> <em>arrayName</em></code>
3426 </dt>
3427 <dd>
3429 Returns the number of elements in the array. If arrayName
3430 isn&#8217;t the name of an array then 0 is returned.
3431 </p>
3432 </dd>
3433 <dt class="hdlist1">
3434 <code><strong>array unset</strong> <em>arrayName ?pattern?</em></code>
3435 </dt>
3436 <dd>
3438 Unsets all of the elements in the array that match pattern
3439 (using the matching rules of string match). If arrayName
3440 isn&#8217;t the name of an array variable or there are no matching
3441 elements in the array, no error will be raised. If pattern
3442 is omitted and arrayName is an array variable, then the
3443 command unsets the entire array. The command always returns
3444 an empty string.
3445 </p>
3446 </dd>
3447 </dl></div>
3448 </div>
3449 <div class="sect2">
3450 <h3 id="_break">break</h3>
3451 <div class="paragraph"><p><code><strong>break</strong></code></p></div>
3452 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command
3453 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
3454 to signal the innermost containing loop command to return immediately.</p></div>
3455 </div>
3456 <div class="sect2">
3457 <h3 id="_case">case</h3>
3458 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? <em>patList body ?patList body &#8230;?</em></code></p></div>
3459 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? {<em>patList body ?patList body &#8230;?</em>}</code></p></div>
3460 <div class="paragraph"><p><strong>Note</strong> that the <a href="#_switch"><strong><code>switch</code></strong></a> command should generally be preferred unless compatibility
3461 with Tcl 6.x is desired.</p></div>
3462 <div class="paragraph"><p>Match <code><em>string</em></code> against each of the <code><em>patList</em></code> arguments
3463 in order. If one matches, then evaluate the following <code><em>body</em></code> argument
3464 by passing it recursively to the Tcl interpreter, and return the result
3465 of that evaluation. Each <code><em>patList</em></code> argument consists of a single
3466 pattern or list of patterns. Each pattern may contain any of the wild-cards
3467 described under <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.</p></div>
3468 <div class="paragraph"><p>If a <code><em>patList</em></code> argument is <code>default</code>, the corresponding body will be
3469 evaluated if no <code><em>patList</em></code> matches <code><em>string</em></code>. If no <code><em>patList</em></code> argument
3470 matches <code><em>string</em></code> and no default is given, then the <a href="#_case"><strong><code>case</code></strong></a> command returns
3471 an empty string.</p></div>
3472 <div class="paragraph"><p>Two syntaxes are provided.</p></div>
3473 <div class="paragraph"><p>The first uses a separate argument for each of the patterns and commands;
3474 this form is convenient if substitutions are desired on some of the
3475 patterns or commands.</p></div>
3476 <div class="paragraph"><p>The second form places all of the patterns and commands together into
3477 a single argument; the argument must have proper list structure, with
3478 the elements of the list being the patterns and commands.</p></div>
3479 <div class="paragraph"><p>The second form makes it easy to construct multi-line case commands,
3480 since the braces around the whole list make it unnecessary to include a
3481 backslash at the end of each line.</p></div>
3482 <div class="paragraph"><p>Since the <code><em>patList</em></code> arguments are in braces in the second form,
3483 no command or variable substitutions are performed on them; this makes
3484 the behaviour of the second form different than the first form in some
3485 cases.</p></div>
3486 <div class="paragraph"><p>Below are some examples of <a href="#_case"><strong><code>case</code></strong></a> commands:</p></div>
3487 <div class="literalblock">
3488 <div class="content">
3489 <pre><code>case abc in {a b} {format 1} default {format 2} a* {format 3}</code></pre>
3490 </div></div>
3491 <div class="paragraph"><p>will return <em>3</em>,</p></div>
3492 <div class="literalblock">
3493 <div class="content">
3494 <pre><code>case a in {
3495 {a b} {format 1}
3496 default {format 2}
3497 a* {format 3}
3498 }</code></pre>
3499 </div></div>
3500 <div class="paragraph"><p>will return <em>1</em>, and</p></div>
3501 <div class="literalblock">
3502 <div class="content">
3503 <pre><code>case xyz {
3504 {a b}
3505 {format 1}
3506 default
3507 {format 2}
3509 {format 3}
3510 }</code></pre>
3511 </div></div>
3512 <div class="paragraph"><p>will return <em>2</em>.</p></div>
3513 </div>
3514 <div class="sect2">
3515 <h3 id="_catch">catch</h3>
3516 <div class="paragraph"><p><code><strong>catch</strong> ?-?no?<em>code ...</em>? ?--? <em>command ?resultVarName? ?optionsVarName?</em></code></p></div>
3517 <div class="paragraph"><p>The <a href="#_catch"><strong><code>catch</code></strong></a> command may be used to prevent errors from aborting
3518 command interpretation. <a href="#_catch"><strong><code>catch</code></strong></a> evaluates <code><em>command</em></code>, and returns a
3519 <code>JIM_OK</code> code, regardless of any errors that might occur while
3520 executing <code><em>command</em></code> (with the possible exception of <code>JIM_SIGNAL</code> -
3521 see below).</p></div>
3522 <div class="paragraph"><p>The return value from <a href="#_catch"><strong><code>catch</code></strong></a> is a decimal string giving the code
3523 returned by the Tcl interpreter after executing <code><em>command</em></code>. This
3524 will be <em>0</em> (<code>JIM_OK</code>) if there were no errors in <code><em>command</em></code>; otherwise
3525 it will have a non-zero value corresponding to one of the exceptional
3526 return codes (see jim.h for the definitions of code values, or the
3527 <a href="#_info"><strong><code>info</code></strong></a> <code>returncodes</code> command).</p></div>
3528 <div class="paragraph"><p>If the <code><em>resultVarName</em></code> argument is given, then it gives the name
3529 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to the
3530 string returned from <code><em>command</em></code> (either a result or an error message).</p></div>
3531 <div class="paragraph"><p>If the <code><em>optionsVarName</em></code> argument is given, then it gives the name
3532 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to a
3533 dictionary. For any return code other than <code>JIM_RETURN</code>, the value
3534 for the key <code>-code</code> will be set to the return code. For <code>JIM_RETURN</code>
3535 it will be set to the code given in <a href="#_return"><strong><code>return</code></strong></a> <code>-code</code>. Additionally,
3536 for the return code <code>JIM_ERR</code>, the value of the key <code>-errorinfo</code>
3537 will contain the current stack trace (the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code>),
3538 the value of the key <code>-errorcode</code> will contain the
3539 same value as the global variable $::errorCode, and the value of
3540 the key <code>-level</code> will be the current return level (see <a href="#_return"><strong><code>return</code></strong></a> <code>-level</code>).
3541 This can be useful to rethrow an error:</p></div>
3542 <div class="literalblock">
3543 <div class="content">
3544 <pre><code>if {[catch {...} msg opts]} {
3545 ...maybe do something with the error...
3546 incr opts(-level)
3547 return {*}$opts $msg
3548 }</code></pre>
3549 </div></div>
3550 <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>.
3551 The set of codes which will be caught may be modified by specifying the one more codes before
3552 <code><em>command</em></code>.</p></div>
3553 <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>
3554 <div class="literalblock">
3555 <div class="content">
3556 <pre><code>catch -exit -nobreak -nocontinue -- { ... }</code></pre>
3557 </div></div>
3558 <div class="paragraph"><p>The use of <code>--</code> is optional. It signifies that no more return code options follow.</p></div>
3559 <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
3560 (stored in <code><em>resultVarName</em></code>) is name of the signal caught.</p></div>
3561 </div>
3562 <div class="sect2">
3563 <h3 id="_cd">cd</h3>
3564 <div class="paragraph"><p><code><strong>cd</strong> <em>dirName</em></code></p></div>
3565 <div class="paragraph"><p>Change the current working directory to <code><em>dirName</em></code>.</p></div>
3566 <div class="paragraph"><p>Returns an empty string.</p></div>
3567 <div class="paragraph"><p>This command can potentially be disruptive to an application, so it may
3568 be removed in some applications.</p></div>
3569 </div>
3570 <div class="sect2">
3571 <h3 id="_clock">clock</h3>
3572 <div class="dlist"><dl>
3573 <dt class="hdlist1">
3574 <code><strong>clock seconds</strong></code>
3575 </dt>
3576 <dd>
3578 Returns the current time as seconds since the epoch.
3579 </p>
3580 </dd>
3581 <dt class="hdlist1">
3582 <code><strong>clock clicks</strong></code>
3583 </dt>
3584 <dd>
3586 Returns the current time in &#8216;clicks&#8217;.
3587 </p>
3588 </dd>
3589 <dt class="hdlist1">
3590 <code><strong>clock microseconds</strong></code>
3591 </dt>
3592 <dd>
3594 Returns the current time in microseconds.
3595 </p>
3596 </dd>
3597 <dt class="hdlist1">
3598 <code><strong>clock milliseconds</strong></code>
3599 </dt>
3600 <dd>
3602 Returns the current time in milliseconds.
3603 </p>
3604 </dd>
3605 <dt class="hdlist1">
3606 <code><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em></code>
3607 </dt>
3608 <dd>
3610 Format the given time (seconds since the epoch) according to the given
3611 format. See strftime(3) for supported formats.
3612 If no format is supplied, "%c" is used.
3613 </p>
3614 </dd>
3615 <dt class="hdlist1">
3616 <code><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em></code>
3617 </dt>
3618 <dd>
3620 Scan the given time string using the given format string.
3621 See strptime(3) for supported formats.
3622 </p>
3623 </dd>
3624 </dl></div>
3625 </div>
3626 <div class="sect2">
3627 <h3 id="_close">close</h3>
3628 <div class="paragraph"><p><code><strong>close</strong> <em>fileId</em></code></p></div>
3629 <div class="paragraph"><p><code><em>fileId</em> <strong>close</strong></code></p></div>
3630 <div class="paragraph"><p>Closes the file given by <code><em>fileId</em></code>.
3631 <code><em>fileId</em></code> must be the return value from a previous invocation
3632 of the <a href="#_open"><strong><code>open</code></strong></a> command; after this command, it should not be
3633 used anymore.</p></div>
3634 </div>
3635 <div class="sect2">
3636 <h3 id="_collect">collect</h3>
3637 <div class="paragraph"><p><code><strong>collect</strong></code></p></div>
3638 <div class="paragraph"><p>Normally reference garbage collection is automatically performed periodically.
3639 However it may be run immediately with the <a href="#_collect"><strong><code>collect</code></strong></a> command.</p></div>
3640 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
3641 </div>
3642 <div class="sect2">
3643 <h3 id="_concat">concat</h3>
3644 <div class="paragraph"><p><code><strong>concat</strong> <em>arg ?arg ...?</em></code></p></div>
3645 <div class="paragraph"><p>This command treats each argument as a list and concatenates them
3646 into a single list. It permits any number of arguments. For example,
3647 the command</p></div>
3648 <div class="literalblock">
3649 <div class="content">
3650 <pre><code>concat a b {c d e} {f {g h}}</code></pre>
3651 </div></div>
3652 <div class="paragraph"><p>will return</p></div>
3653 <div class="literalblock">
3654 <div class="content">
3655 <pre><code>a b c d e f {g h}</code></pre>
3656 </div></div>
3657 <div class="paragraph"><p>as its result.</p></div>
3658 </div>
3659 <div class="sect2">
3660 <h3 id="_continue">continue</h3>
3661 <div class="paragraph"><p><code><strong>continue</strong></code></p></div>
3662 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command such
3663 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
3664 signal the innermost containing loop command to skip the remainder of
3665 the loop&#8217;s body but continue with the next iteration of the loop.</p></div>
3666 </div>
3667 <div class="sect2">
3668 <h3 id="_curry">curry</h3>
3669 <div class="paragraph"><p><code><strong>alias</strong> <em>args...</em></code></p></div>
3670 <div class="paragraph"><p>Similar to <a href="#_alias"><strong><code>alias</code></strong></a> except it creates an anonymous procedure (lambda) instead of
3671 a named procedure.</p></div>
3672 <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>
3673 <div class="literalblock">
3674 <div class="content">
3675 <pre><code>set e [local curry info exists]
3676 if {[$e var]} {
3678 }</code></pre>
3679 </div></div>
3680 <div class="paragraph"><p><a href="#_curry"><strong><code>curry</code></strong></a> returns the name of the procedure.</p></div>
3681 <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>
3682 </div>
3683 <div class="sect2">
3684 <h3 id="_dict">dict</h3>
3685 <div class="paragraph"><p><code><strong>dict</strong> <em>option ?arg...?</em></code></p></div>
3686 <div class="paragraph"><p>Performs one of several operations on dictionary values.</p></div>
3687 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3688 command. The legal <code><em>options</em></code> are:</p></div>
3689 <div class="dlist"><dl>
3690 <dt class="hdlist1">
3691 <code><strong>dict create</strong> <em>?key value ...?</em></code>
3692 </dt>
3693 <dd>
3695 Create and return a new dictionary value that contains each of
3696 the key/value mappings listed as arguments (keys and values
3697 alternating, with each key being followed by its associated
3698 value.)
3699 </p>
3700 </dd>
3701 <dt class="hdlist1">
3702 <code><strong>dict exists</strong> <em>dictionary key ?key ...?</em></code>
3703 </dt>
3704 <dd>
3706 Returns a boolean value indicating whether the given key (or path
3707 of keys through a set of nested dictionaries) exists in the given
3708 dictionary value. This returns a true value exactly when <a href="#_dict"><strong><code>dict</code></strong></a> <code>get</code>
3709 on that path will succeed.
3710 </p>
3711 </dd>
3712 <dt class="hdlist1">
3713 <code><strong>dict get</strong> <em>dictionary ?key ...?</em></code>
3714 </dt>
3715 <dd>
3717 Given a dictionary value (first argument) and a key (second argument),
3718 this will retrieve the value for that key. Where several keys are
3719 supplied, the behaviour of the command shall be as if the result
3720 of "<a href="#_dict"><strong><code>dict</code></strong></a> <code>get $dictVal $key</code>" was passed as the first argument to
3721 dict get with the remaining arguments as second (and possibly
3722 subsequent) arguments. This facilitates lookups in nested dictionaries.
3723 If no keys are provided, dict would return a list containing pairs
3724 of elements in a manner similar to array get. That is, the first
3725 element of each pair would be the key and the second element would
3726 be the value for that key. It is an error to attempt to retrieve
3727 a value for a key that is not present in the dictionary.
3728 </p>
3729 </dd>
3730 <dt class="hdlist1">
3731 <code><strong>dict keys</strong> <em>dictionary ?pattern?</em></code>
3732 </dt>
3733 <dd>
3735 Returns a list of the keys in the dictionary.
3736 If pattern is specified, then only those keys whose
3737 names match <code><em>pattern</em></code> (using the matching rules of string
3738 match) are included.
3739 </p>
3740 </dd>
3741 <dt class="hdlist1">
3742 <code><strong>dict merge</strong> ?<em>dictionary ...</em>?</code>
3743 </dt>
3744 <dd>
3746 Return a dictionary that contains the contents of each of the
3747 <code><em>dictionary</em></code> arguments. Where two (or more) dictionaries
3748 contain a mapping for the same key, the resulting dictionary
3749 maps that key to the value according to the last dictionary on
3750 the command line containing a mapping for that key.
3751 </p>
3752 </dd>
3753 <dt class="hdlist1">
3754 <code><strong>dict set</strong> <em>dictionaryName key ?key ...? value</em></code>
3755 </dt>
3756 <dd>
3758 This operation takes the <code><em>name</em></code> of a variable containing a dictionary
3759 value and places an updated dictionary value in that variable
3760 containing a mapping from the given key to the given value. When
3761 multiple keys are present, this operation creates or updates a chain
3762 of nested dictionaries.
3763 </p>
3764 </dd>
3765 <dt class="hdlist1">
3766 <code><strong>dict size</strong> <em>dictionary</em></code>
3767 </dt>
3768 <dd>
3770 Return the number of key/value mappings in the given dictionary value.
3771 </p>
3772 </dd>
3773 <dt class="hdlist1">
3774 <code><strong>dict unset</strong> <em>dictionaryName key ?key ...? value</em></code>
3775 </dt>
3776 <dd>
3778 This operation (the companion to <a href="#_dict"><strong><code>dict</code></strong></a> <code>set</code>) takes the name of a
3779 variable containing a dictionary value and places an updated
3780 dictionary value in that variable that does not contain a mapping
3781 for the given key. Where multiple keys are present, this describes
3782 a path through nested dictionaries to the mapping to remove. At
3783 least one key must be specified, but the last key on the key-path
3784 need not exist. All other components on the path must exist.
3785 </p>
3786 </dd>
3787 <dt class="hdlist1">
3788 <code><strong>dict with</strong> <em>dictionaryName key ?key ...? script</em></code>
3789 </dt>
3790 <dd>
3792 Execute the Tcl script in <code><em>script</em></code> with the value for each
3793 key in <code><em>dictionaryName</em></code> mapped to a variable with the same
3794 name. Where one or more keys are given, these indicate a chain
3795 of nested dictionaries, with the innermost dictionary being the
3796 one opened out for the execution of body. Making <code><em>dictionaryName</em></code>
3797 unreadable will make the updates to the dictionary be discarded,
3798 and this also happens if the contents of <code><em>dictionaryName</em></code> are
3799 adjusted so that the chain of dictionaries no longer exists.
3800 The result of <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> is (unless some kind of error occurs)
3801 the result of the evaluation of body.
3802 </p>
3803 </dd>
3804 <dt class="hdlist1">
3806 </dt>
3807 <dd>
3809 The variables are mapped in the scope enclosing the <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code>;
3810 it is recommended that this command only be used in a local
3811 scope (procedure). Because of this, the variables set by
3812 <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> will continue to exist after the command finishes (unless
3813 explicitly unset). Note that changes to the contents of <code><em>dictionaryName</em></code>
3814 only happen when <code><em>script</em></code> terminates.
3815 </p>
3816 </dd>
3817 </dl></div>
3818 <div class="paragraph"><p><code><strong>dict for, values, incr, append, lappend, update, info, replace</strong></code> to be documented&#8230;</p></div>
3819 </div>
3820 <div class="sect2">
3821 <h3 id="_env">env</h3>
3822 <div class="paragraph"><p><code><strong>env</strong> <em>?name? ?default?</em></code></p></div>
3823 <div class="paragraph"><p>If <code><em>name</em></code> is supplied, returns the value of <code><em>name</em></code> from the initial
3824 environment (see getenv(3)). An error is returned if <code><em>name</em></code> does not
3825 exist in the environment, unless <code><em>default</em></code> is supplied - in which case
3826 that value is returned instead.</p></div>
3827 <div class="paragraph"><p>If no arguments are supplied, returns a list of all environment variables
3828 and their values as <code>{name value ...}</code></p></div>
3829 <div class="paragraph"><p>See also the global variable <code>::env</code></p></div>
3830 </div>
3831 <div class="sect2">
3832 <h3 id="_eof">eof</h3>
3833 <div class="paragraph"><p><code><strong>eof</strong> <em>fileId</em></code></p></div>
3834 <div class="paragraph"><p><code><em>fileId</em> <strong>eof</strong></code></p></div>
3835 <div class="paragraph"><p>Returns 1 if an end-of-file condition has occurred on <code><em>fileId</em></code>,
3836 0 otherwise.</p></div>
3837 <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>,
3838 or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one of the
3839 standard I/O channels.</p></div>
3840 </div>
3841 <div class="sect2">
3842 <h3 id="_error">error</h3>
3843 <div class="paragraph"><p><code><strong>error</strong> <em>message ?stacktrace?</em></code></p></div>
3844 <div class="paragraph"><p>Returns a <code>JIM_ERR</code> code, which causes command interpretation to be
3845 unwound. <code><em>message</em></code> is a string that is returned to the application
3846 to indicate what went wrong.</p></div>
3847 <div class="paragraph"><p>If the <code><em>stacktrace</em></code> argument is provided and is non-empty,
3848 it is used to initialize the stacktrace.</p></div>
3849 <div class="paragraph"><p>This feature is most useful in conjunction with the <a href="#_catch"><strong><code>catch</code></strong></a> command:
3850 if a caught error cannot be handled successfully, <code><em>stacktrace</em></code> can be used
3851 to return a stack trace reflecting the original point of occurrence
3852 of the error:</p></div>
3853 <div class="literalblock">
3854 <div class="content">
3855 <pre><code>catch {...} errMsg
3857 error $errMsg [info stacktrace]</code></pre>
3858 </div></div>
3859 <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>
3860 </div>
3861 <div class="sect2">
3862 <h3 id="_errorinfo">errorInfo</h3>
3863 <div class="paragraph"><p><code><strong>errorInfo</strong> <em>error ?stacktrace?</em></code></p></div>
3864 <div class="paragraph"><p>Returns a human-readable representation of the given error message and stack trace.
3865 Typical usage is:</p></div>
3866 <div class="literalblock">
3867 <div class="content">
3868 <pre><code>if {[catch {...} error]} {
3869 puts stderr [errorInfo $error [info stacktrace]]
3870 exit 1
3871 }</code></pre>
3872 </div></div>
3873 <div class="paragraph"><p>See also <a href="#_error"><strong><code>error</code></strong></a>.</p></div>
3874 </div>
3875 <div class="sect2">
3876 <h3 id="_eval">eval</h3>
3877 <div class="paragraph"><p><code><strong>eval</strong> <em>arg ?arg...?</em></code></p></div>
3878 <div class="paragraph"><p><a href="#_eval"><strong><code>eval</code></strong></a> takes one or more arguments, which together comprise a Tcl
3879 command (or collection of Tcl commands separated by newlines in the
3880 usual way). <a href="#_eval"><strong><code>eval</code></strong></a> concatenates all its arguments in the same
3881 fashion as the <a href="#_concat"><strong><code>concat</code></strong></a> command, passes the concatenated string to the
3882 Tcl interpreter recursively, and returns the result of that
3883 evaluation (or any error generated by it).</p></div>
3884 </div>
3885 <div class="sect2">
3886 <h3 id="_exec">exec</h3>
3887 <div class="paragraph"><p><code><strong>exec</strong> <em>arg ?arg...?</em></code></p></div>
3888 <div class="paragraph"><p>This command treats its arguments as the specification
3889 of one or more UNIX commands to execute as subprocesses.
3890 The commands take the form of a standard shell pipeline;
3891 <code>|</code> arguments separate commands in the
3892 pipeline and cause standard output of the preceding command
3893 to be piped into standard input of the next command (or <code>|&amp;</code> for
3894 both standard output and standard error).</p></div>
3895 <div class="paragraph"><p>Under normal conditions the result of the <a href="#_exec"><strong><code>exec</code></strong></a> command
3896 consists of the standard output produced by the last command
3897 in the pipeline followed by the standard error output.</p></div>
3898 <div class="paragraph"><p>If any of the commands writes to its standard error file,
3899 then this will be included in the result after the standard output
3900 of the last command.</p></div>
3901 <div class="paragraph"><p>Note that unlike Tcl, data written to standard error does not cause
3902 <a href="#_exec"><strong><code>exec</code></strong></a> to return an error.</p></div>
3903 <div class="paragraph"><p>If any of the commands in the pipeline exit abnormally or
3904 are killed or suspended, then <a href="#_exec"><strong><code>exec</code></strong></a> will return an error.
3905 If no standard error output was produced, or is redirected,
3906 the error message will include the normal result, as above,
3907 followed by error messages describing the abnormal terminations.</p></div>
3908 <div class="paragraph"><p>If any standard error output was produced, these abnormal termination
3909 messages are suppressed.</p></div>
3910 <div class="paragraph"><p>If the last character of the result or error message
3911 is a newline then that character is deleted from the result
3912 or error message for consistency with normal
3913 Tcl return values.</p></div>
3914 <div class="paragraph"><p>An <code><em>arg</em></code> may have one of the following special forms:</p></div>
3915 <div class="dlist"><dl>
3916 <dt class="hdlist1">
3917 <code>&gt;filename</code>
3918 </dt>
3919 <dd>
3921 The standard output of the last command in the pipeline
3922 is redirected to the file. In this situation <a href="#_exec"><strong><code>exec</code></strong></a>
3923 will normally return an empty string.
3924 </p>
3925 </dd>
3926 <dt class="hdlist1">
3927 <code>&gt;&gt;filename</code>
3928 </dt>
3929 <dd>
3931 As above, but append to the file.
3932 </p>
3933 </dd>
3934 <dt class="hdlist1">
3935 <code>&gt;@fileId</code>
3936 </dt>
3937 <dd>
3939 The standard output of the last command in the pipeline is
3940 redirected to the given (writable) file descriptor (e.g. stdout,
3941 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>
3942 will normally return an empty string.
3943 </p>
3944 </dd>
3945 <dt class="hdlist1">
3946 <code>2&gt;filename</code>
3947 </dt>
3948 <dd>
3950 The standard error of the last command in the pipeline
3951 is redirected to the file.
3952 </p>
3953 </dd>
3954 <dt class="hdlist1">
3955 <code>2&gt;&gt;filename</code>
3956 </dt>
3957 <dd>
3959 As above, but append to the file.
3960 </p>
3961 </dd>
3962 <dt class="hdlist1">
3963 <code>2&gt;@fileId</code>
3964 </dt>
3965 <dd>
3967 The standard error of the last command in the pipeline is
3968 redirected to the given (writable) file descriptor.
3969 </p>
3970 </dd>
3971 <dt class="hdlist1">
3972 <code>2&gt;@1</code>
3973 </dt>
3974 <dd>
3976 The standard error of the last command in the pipeline is
3977 redirected to the same file descriptor as the standard output.
3978 </p>
3979 </dd>
3980 <dt class="hdlist1">
3981 <code>&gt;&amp;filename</code>
3982 </dt>
3983 <dd>
3985 Both the standard output and standard error of the last command
3986 in the pipeline is redirected to the file.
3987 </p>
3988 </dd>
3989 <dt class="hdlist1">
3990 <code>&gt;&gt;&amp;filename</code>
3991 </dt>
3992 <dd>
3994 As above, but append to the file.
3995 </p>
3996 </dd>
3997 <dt class="hdlist1">
3998 <code>&lt;filename</code>
3999 </dt>
4000 <dd>
4002 The standard input of the first command in the pipeline
4003 is taken from the file.
4004 </p>
4005 </dd>
4006 <dt class="hdlist1">
4007 <code>&lt;&lt;string</code>
4008 </dt>
4009 <dd>
4011 The standard input of the first command is taken as the
4012 given immediate value.
4013 </p>
4014 </dd>
4015 <dt class="hdlist1">
4016 <code>&lt;@fileId</code>
4017 </dt>
4018 <dd>
4020 The standard input of the first command in the pipeline
4021 is taken from the given (readable) file descriptor.
4022 </p>
4023 </dd>
4024 </dl></div>
4025 <div class="paragraph"><p>If there is no redirection of standard input, standard error
4026 or standard output, these are connected to the corresponding
4027 input or output of the application.</p></div>
4028 <div class="paragraph"><p>If the last <code><em>arg</em></code> is <code>&amp;</code> then the command will be
4029 executed in background.
4030 In this case the standard output from the last command
4031 in the pipeline will
4032 go to the application&#8217;s standard output unless
4033 redirected in the command, and error output from all
4034 the commands in the pipeline will go to the application&#8217;s
4035 standard error file. The return value of exec in this case
4036 is a list of process ids (pids) in the pipeline.</p></div>
4037 <div class="paragraph"><p>Each <code><em>arg</em></code> becomes one word for a command, except for
4038 <code>|</code>, <code>&lt;</code>, <code>&lt;&lt;</code>, <code>&gt;</code>, and <code>&amp;</code> arguments, and the
4039 arguments that follow <code>&lt;</code>, <code>&lt;&lt;</code>, and <code>&gt;</code>.</p></div>
4040 <div class="paragraph"><p>The first word in each command is taken as the command name;
4041 the directories in the PATH environment variable are searched for
4042 an executable by the given name.</p></div>
4043 <div class="paragraph"><p>No <a href="#_glob"><strong><code>glob</code></strong></a> expansion or other shell-like substitutions
4044 are performed on the arguments to commands.</p></div>
4045 <div class="paragraph"><p>If the command fails, the global $::errorCode (and the -errorcode
4046 option in <a href="#_catch"><strong><code>catch</code></strong></a>) will be set to a list, as follows:</p></div>
4047 <div class="dlist"><dl>
4048 <dt class="hdlist1">
4049 <code><strong>CHILDKILLED</strong> <em>pid sigName msg</em></code>
4050 </dt>
4051 <dd>
4053 This format is used when a child process has been killed
4054 because of a signal. The pid element will be the process&#8217;s
4055 identifier (in decimal). The sigName element will be the
4056 symbolic name of the signal that caused the process to
4057 terminate; it will be one of the names from the include
4058 file signal.h, such as SIGPIPE. The msg element will be a
4059 short human-readable message describing the signal, such
4060 as "write on pipe with no readers" for SIGPIPE.
4061 </p>
4062 </dd>
4063 <dt class="hdlist1">
4064 <code><strong>CHILDSUSP</strong> <em>pid sigName msg</em></code>
4065 </dt>
4066 <dd>
4068 This format is used when a child process has been suspended
4069 because of a signal. The pid element will be the process&#8217;s
4070 identifier, in decimal. The sigName element will be the
4071 symbolic name of the signal that caused the process to
4072 suspend; this will be one of the names from the include
4073 file signal.h, such as SIGTTIN. The msg element will be a
4074 short human-readable message describing the signal, such
4075 as "background tty read" for SIGTTIN.
4076 </p>
4077 </dd>
4078 <dt class="hdlist1">
4079 <code><strong>CHILDSTATUS</strong> <em>pid code</em></code>
4080 </dt>
4081 <dd>
4083 This format is used when a child process has exited with a
4084 non-zero exit status. The pid element will be the process&#8217;s
4085 identifier (in decimal) and the code element will be the
4086 exit code returned by the process (also in decimal).
4087 </p>
4088 </dd>
4089 </dl></div>
4090 <div class="paragraph"><p>The environment for the executed command is set from $::env (unless
4091 this variable is unset, in which case the original environment is used).</p></div>
4092 </div>
4093 <div class="sect2">
4094 <h3 id="_exists">exists</h3>
4095 <div class="paragraph"><p><code><strong>exists ?-var|-proc|-command|-alias?</strong> <em>name</em></code></p></div>
4096 <div class="paragraph"><p>Checks the existence of the given variable, procedure, command
4097 or alias respectively and returns 1 if it exists or 0 if not. This command
4098 provides a more simplified/convenient version of <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>,
4099 <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>
4100 <div class="paragraph"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
4101 </div>
4102 <div class="sect2">
4103 <h3 id="_exit">exit</h3>
4104 <div class="paragraph"><p><code><strong>exit</strong> <em>?returnCode?</em></code></p></div>
4105 <div class="paragraph"><p>Terminate the process, returning <code><em>returnCode</em></code> to the
4106 parent as the exit status.</p></div>
4107 <div class="paragraph"><p>If <code><em>returnCode</em></code> isn&#8217;t specified then it defaults
4108 to 0.</p></div>
4109 <div class="paragraph"><p>Note that exit can be caught with <a href="#_catch"><strong><code>catch</code></strong></a>.</p></div>
4110 </div>
4111 <div class="sect2">
4112 <h3 id="_expr">expr</h3>
4113 <div class="paragraph"><p><code><strong>expr</strong> <em>arg</em></code></p></div>
4114 <div class="paragraph"><p>Calls the expression processor to evaluate <code><em>arg</em></code>, and returns
4115 the result as a string. See the section EXPRESSIONS above.</p></div>
4116 <div class="paragraph"><p>Note that Jim supports a shorthand syntax for <a href="#_expr"><strong><code>expr</code></strong></a> as <code>$(...)</code>
4117 The following two are identical.</p></div>
4118 <div class="literalblock">
4119 <div class="content">
4120 <pre><code>set x [expr {3 * 2 + 1}]
4121 set x $(3 * 2 + 1)</code></pre>
4122 </div></div>
4123 </div>
4124 <div class="sect2">
4125 <h3 id="_file">file</h3>
4126 <div class="paragraph"><p><code><strong>file</strong> <em>option name ?arg...?</em></code></p></div>
4127 <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>
4128 <div class="paragraph"><p><code><em>option</em></code> indicates what to do with the file name. Any unique
4129 abbreviation for <code><em>option</em></code> is acceptable. The valid options are:</p></div>
4130 <div class="dlist"><dl>
4131 <dt class="hdlist1">
4132 <code><strong>file atime</strong> <em>name</em></code>
4133 </dt>
4134 <dd>
4136 Return a decimal string giving the time at which file <code><em>name</em></code>
4137 was last accessed. The time is measured in the standard UNIX
4138 fashion as seconds from a fixed starting time (often January 1, 1970).
4139 If the file doesn&#8217;t exist or its access time cannot be queried then an
4140 error is generated.
4141 </p>
4142 </dd>
4143 <dt class="hdlist1">
4144 <code><strong>file copy ?-force?</strong> <em>source target</em></code>
4145 </dt>
4146 <dd>
4148 Copies file <code><em>source</em></code> to file <code><em>target</em></code>. The source file must exist.
4149 The target file must not exist, unless <code>-force</code> is specified.
4150 </p>
4151 </dd>
4152 <dt class="hdlist1">
4153 <code><strong>file delete ?-force? ?--?</strong> <em>name...</em></code>
4154 </dt>
4155 <dd>
4157 Deletes file or directory <code><em>name</em></code>. If the file or directory doesn&#8217;t exist, nothing happens.
4158 If it can&#8217;t be deleted, an error is generated. Non-empty directories will not be deleted
4159 unless the <code>-force</code> options is given. In this case no errors will be generated, even
4160 if the file/directory can&#8217;t be deleted. Use <code><em>--</em></code> if there is any possibility of
4161 the first name being <code><em>-force</em></code>.
4162 </p>
4163 </dd>
4164 <dt class="hdlist1">
4165 <code><strong>file dirname</strong> <em>name</em></code>
4166 </dt>
4167 <dd>
4169 Return all of the characters in <code><em>name</em></code> up to but not including
4170 the last slash character. If there are no slashes in <code><em>name</em></code>
4171 then return <code>.</code> (a single dot). If the last slash in <code><em>name</em></code> is its first
4172 character, then return <code>/</code>.
4173 </p>
4174 </dd>
4175 <dt class="hdlist1">
4176 <code><strong>file executable</strong> <em>name</em></code>
4177 </dt>
4178 <dd>
4180 Return <em>1</em> if file <code><em>name</em></code> is executable by
4181 the current user, <em>0</em> otherwise.
4182 </p>
4183 </dd>
4184 <dt class="hdlist1">
4185 <code><strong>file exists</strong> <em>name</em></code>
4186 </dt>
4187 <dd>
4189 Return <em>1</em> if file <code><em>name</em></code> exists and the current user has
4190 search privileges for the directories leading to it, <em>0</em> otherwise.
4191 </p>
4192 </dd>
4193 <dt class="hdlist1">
4194 <code><strong>file extension</strong> <em>name</em></code>
4195 </dt>
4196 <dd>
4198 Return all of the characters in <code><em>name</em></code> after and including the
4199 last dot in <code><em>name</em></code>. If there is no dot in <code><em>name</em></code> then return
4200 the empty string.
4201 </p>
4202 </dd>
4203 <dt class="hdlist1">
4204 <code><strong>file isdirectory</strong> <em>name</em></code>
4205 </dt>
4206 <dd>
4208 Return <em>1</em> if file <code><em>name</em></code> is a directory,
4209 <em>0</em> otherwise.
4210 </p>
4211 </dd>
4212 <dt class="hdlist1">
4213 <code><strong>file isfile</strong> <em>name</em></code>
4214 </dt>
4215 <dd>
4217 Return <em>1</em> if file <code><em>name</em></code> is a regular file,
4218 <em>0</em> otherwise.
4219 </p>
4220 </dd>
4221 <dt class="hdlist1">
4222 <code><strong>file join</strong> <em>arg...</em></code>
4223 </dt>
4224 <dd>
4226 Joins multiple path components. Note that if any components is
4227 an absolute path, the preceding components are ignored.
4228 Thus <code>"<a href="#_file"><strong><code>file</code></strong></a> join /tmp /root"</code> returns <code>"/root"</code>.
4229 </p>
4230 </dd>
4231 <dt class="hdlist1">
4232 <code><strong>file link</strong> ?<strong>-hard|-symbolic</strong>? <em>newname target</em></code>
4233 </dt>
4234 <dd>
4236 Creates a hard link (default) or symbolic link from <code><em>newname</em></code> to <code><em>target</em></code>.
4237 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>
4238 and also of <code>ln</code>, but this is compatible with Tcl.
4239 An error is returned if <code><em>target</em></code> doesn&#8217;t exist or <code><em>newname</em></code> already exists.
4240 </p>
4241 </dd>
4242 <dt class="hdlist1">
4243 <code><strong>file lstat</strong> <em>name varName</em></code>
4244 </dt>
4245 <dd>
4247 Same as <em>stat</em> option (see below) except uses the <code><em>lstat</em></code>
4248 kernel call instead of <code><em>stat</em></code>. This means that if <code><em>name</em></code>
4249 refers to a symbolic link the information returned in <code><em>varName</em></code>
4250 is for the link rather than the file it refers to. On systems that
4251 don&#8217;t support symbolic links this option behaves exactly the same
4252 as the <em>stat</em> option.
4253 </p>
4254 </dd>
4255 <dt class="hdlist1">
4256 <code><strong>file mkdir</strong> <em>dir1 ?dir2...?</em></code>
4257 </dt>
4258 <dd>
4260 Creates each directory specified. For each pathname <code><em>dir</em></code> specified,
4261 this command will create all non-existing parent directories
4262 as well as <code><em>dir</em></code> itself. If an existing directory is specified,
4263 then no action is taken and no error is returned. Trying to
4264 overwrite an existing file with a directory will result in an
4265 error. Arguments are processed in the order specified, halting
4266 at the first error, if any.
4267 </p>
4268 </dd>
4269 <dt class="hdlist1">
4270 <code><strong>file mtime</strong> <em>name ?time?</em></code>
4271 </dt>
4272 <dd>
4274 Return a decimal string giving the time at which file <code><em>name</em></code>
4275 was last modified. The time is measured in the standard UNIX
4276 fashion as seconds from a fixed starting time (often January 1, 1970).
4277 If the file doesn&#8217;t exist or its modified time cannot be queried then an
4278 error is generated. If <code><em>time</em></code> is given, sets the modification time
4279 of the file to the given value.
4280 </p>
4281 </dd>
4282 <dt class="hdlist1">
4283 <code><strong>file normalize</strong> <em>name</em></code>
4284 </dt>
4285 <dd>
4287 Return the normalized path of <code><em>name</em></code>. See <em>realpath(3)</em>.
4288 </p>
4289 </dd>
4290 <dt class="hdlist1">
4291 <code><strong>file owned</strong> <em>name</em></code>
4292 </dt>
4293 <dd>
4295 Return <em>1</em> if file <code><em>name</em></code> is owned by the current user,
4296 <em>0</em> otherwise.
4297 </p>
4298 </dd>
4299 <dt class="hdlist1">
4300 <code><strong>file readable</strong> <em>name</em></code>
4301 </dt>
4302 <dd>
4304 Return <em>1</em> if file <code><em>name</em></code> is readable by
4305 the current user, <em>0</em> otherwise.
4306 </p>
4307 </dd>
4308 <dt class="hdlist1">
4309 <code><strong>file readlink</strong> <em>name</em></code>
4310 </dt>
4311 <dd>
4313 Returns the value of the symbolic link given by <code><em>name</em></code> (i.e. the
4314 name of the file it points to). If
4315 <code><em>name</em></code> isn&#8217;t a symbolic link or its value cannot be read, then
4316 an error is returned. On systems that don&#8217;t support symbolic links
4317 this option is undefined.
4318 </p>
4319 </dd>
4320 <dt class="hdlist1">
4321 <code><strong>file rename</strong> ?<strong>-force</strong>? <em>oldname</em> <em>newname</em></code>
4322 </dt>
4323 <dd>
4325 Renames the file from the old name to the new name.
4326 If <code><em>newname</em></code> already exists, an error is returned unless <code><em>-force</em></code> is
4327 specified.
4328 </p>
4329 </dd>
4330 <dt class="hdlist1">
4331 <code><strong>file rootname</strong> <em>name</em></code>
4332 </dt>
4333 <dd>
4335 Return all of the characters in <code><em>name</em></code> up to but not including
4336 the last <em>.</em> character in the name. If <code><em>name</em></code> doesn&#8217;t contain
4337 a dot, then return <code><em>name</em></code>.
4338 </p>
4339 </dd>
4340 <dt class="hdlist1">
4341 <code><strong>file size</strong> <em>name</em></code>
4342 </dt>
4343 <dd>
4345 Return a decimal string giving the size of file <code><em>name</em></code> in bytes.
4346 If the file doesn&#8217;t exist or its size cannot be queried then an
4347 error is generated.
4348 </p>
4349 </dd>
4350 <dt class="hdlist1">
4351 <code><strong>file stat</strong> <em>name ?varName?</em></code>
4352 </dt>
4353 <dd>
4355 Invoke the <em>stat</em> kernel call on <code><em>name</em></code>, and return the result
4356 as a dictionary with the following keys: <em>atime</em>,
4357 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
4358 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>.
4359 Each element except <em>type</em> is a decimal string with the value of
4360 the corresponding field from the <em>stat</em> return structure; see the
4361 manual entry for <em>stat</em> for details on the meanings of the values.
4362 The <em>type</em> element gives the type of the file in the same form
4363 returned by the command <a href="#_file"><strong><code>file</code></strong></a> <code>type</code>.
4364 If <code><em>varName</em></code> is specified, it is taken to be the name of an array
4365 variable and the values are also stored into the array.
4366 </p>
4367 </dd>
4368 <dt class="hdlist1">
4369 <code><strong>file tail</strong> <em>name</em></code>
4370 </dt>
4371 <dd>
4373 Return all of the characters in <code><em>name</em></code> after the last slash.
4374 If <code><em>name</em></code> contains no slashes then return <code><em>name</em></code>.
4375 </p>
4376 </dd>
4377 <dt class="hdlist1">
4378 <code><strong>file tempfile</strong> <em>?template?</em></code>
4379 </dt>
4380 <dd>
4382 Creates and returns the name of a unique temporary file. If <code><em>template</em></code> is omitted, a
4383 default template will be used to place the file in /tmp. See <em>mkstemp(3)</em> for
4384 the format of the template and security concerns.
4385 </p>
4386 </dd>
4387 <dt class="hdlist1">
4388 <code><strong>file type</strong> <em>name</em></code>
4389 </dt>
4390 <dd>
4392 Returns a string giving the type of file <code><em>name</em></code>, which will be
4393 one of <code>file</code>, <code>directory</code>, <code>characterSpecial</code>,
4394 <code>blockSpecial</code>, <code>fifo</code>, <code>link</code>, or <code>socket</code>.
4395 </p>
4396 </dd>
4397 <dt class="hdlist1">
4398 <code><strong>file writable</strong> <em>name</em></code>
4399 </dt>
4400 <dd>
4402 Return <em>1</em> if file <code><em>name</em></code> is writable by
4403 the current user, <em>0</em> otherwise.
4404 </p>
4405 </dd>
4406 </dl></div>
4407 <div class="paragraph"><p>The <a href="#_file"><strong><code>file</code></strong></a> commands that return 0/1 results are often used in
4408 conditional or looping commands, for example:</p></div>
4409 <div class="literalblock">
4410 <div class="content">
4411 <pre><code>if {![file exists foo]} {
4412 error {bad file name}
4413 } else {
4415 }</code></pre>
4416 </div></div>
4417 </div>
4418 <div class="sect2">
4419 <h3 id="_finalize">finalize</h3>
4420 <div class="paragraph"><p><code><strong>finalize</strong> <em>reference ?command?</em></code></p></div>
4421 <div class="paragraph"><p>If <code><em>command</em></code> is omitted, returns the finalizer command for the given reference.</p></div>
4422 <div class="paragraph"><p>Otherwise, sets a new finalizer command for the given reference. <code><em>command</em></code> may be
4423 the empty string to remove the current finalizer.</p></div>
4424 <div class="paragraph"><p>The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
4425 command.</p></div>
4426 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
4427 </div>
4428 <div class="sect2">
4429 <h3 id="_flush">flush</h3>
4430 <div class="paragraph"><p><code><strong>flush</strong> <em>fileId</em></code></p></div>
4431 <div class="paragraph"><p><code><em>fileId</em> <strong>flush</strong></code></p></div>
4432 <div class="paragraph"><p>Flushes any output that has been buffered for <code><em>fileId</em></code>. <code><em>fileId</em></code> must
4433 have been the return value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
4434 <code>stdout</code> or <code>stderr</code> to access one of the standard I/O streams; it must
4435 refer to a file that was opened for writing. This command returns an
4436 empty string.</p></div>
4437 </div>
4438 <div class="sect2">
4439 <h3 id="_for">for</h3>
4440 <div class="paragraph"><p><code><strong>for</strong> <em>start test next body</em></code></p></div>
4441 <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.
4442 The <code><em>start</em></code>, <code><em>next</em></code>, and <code><em>body</em></code> arguments must be Tcl command strings,
4443 and <code><em>test</em></code> is an expression string.</p></div>
4444 <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>.
4445 Then it repeatedly evaluates <code><em>test</em></code> as an expression; if the result is
4446 non-zero it invokes the Tcl interpreter on <code><em>body</em></code>, then invokes the Tcl
4447 interpreter on <code><em>next</em></code>, then repeats the loop. The command terminates
4448 when <code><em>test</em></code> evaluates to 0.</p></div>
4449 <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
4450 commands in the current execution of <code><em>body</em></code> are skipped; processing
4451 continues by invoking the Tcl interpreter on <code><em>next</em></code>, then evaluating
4452 <code><em>test</em></code>, and so on.</p></div>
4453 <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>
4454 command will return immediately.</p></div>
4455 <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
4456 statements in C.</p></div>
4457 <div class="paragraph"><p><a href="#_for"><strong><code>for</code></strong></a> returns an empty string.</p></div>
4458 </div>
4459 <div class="sect2">
4460 <h3 id="_foreach">foreach</h3>
4461 <div class="paragraph"><p><code><strong>foreach</strong> <em>varName list body</em></code></p></div>
4462 <div class="paragraph"><p><code><strong>foreach</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
4463 <div class="paragraph"><p>In this command, <code><em>varName</em></code> is the name of a variable, <code><em>list</em></code>
4464 is a list of values to assign to <code><em>varName</em></code>, and <code><em>body</em></code> is a
4465 collection of Tcl commands.</p></div>
4466 <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
4467 the contents of the field to <code><em>varName</em></code> (as if the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4468 had been used to extract the field), then calls the Tcl interpreter to
4469 execute <code><em>body</em></code>.</p></div>
4470 <div class="paragraph"><p>If instead of being a simple name, <code><em>varList</em></code> is used, multiple assignments
4471 are made each time through the loop, one for each element of <code><em>varList</em></code>.</p></div>
4472 <div class="paragraph"><p>For example, if there are two elements in <code><em>varList</em></code> and six elements in
4473 the list, the loop will be executed three times.</p></div>
4474 <div class="paragraph"><p>If the length of the list doesn&#8217;t evenly divide by the number of elements
4475 in <code><em>varList</em></code>, the value of the remaining variables in the last iteration
4476 of the loop are undefined.</p></div>
4477 <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>,
4478 with the same effect as in the <a href="#_for"><strong><code>for</code></strong></a> command.</p></div>
4479 <div class="paragraph"><p><a href="#_foreach"><strong><code>foreach</code></strong></a> returns an empty string.</p></div>
4480 </div>
4481 <div class="sect2">
4482 <h3 id="_format">format</h3>
4483 <div class="paragraph"><p><code><strong>format</strong> <em>formatString ?arg ...?</em></code></p></div>
4484 <div class="paragraph"><p>This command generates a formatted string in the same way as the
4485 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
4486 implementation). <code><em>formatString</em></code> indicates how to format
4487 the result, using <code>%</code> fields as in <em>sprintf</em>, and the additional
4488 arguments, if any, provide values to be substituted into the result.</p></div>
4489 <div class="paragraph"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
4490 man page for details. Each <code><em>arg</em></code> must match the expected type
4491 from the <code>%</code> field in <code><em>formatString</em></code>; the <a href="#_format"><strong><code>format</code></strong></a> command
4492 converts each argument to the correct type (floating, integer, etc.)
4493 before passing it to <em>sprintf</em> for formatting.</p></div>
4494 <div class="paragraph"><p>The only unusual conversion is for <code>%c</code>; in this case the argument
4495 must be a decimal string, which will then be converted to the corresponding
4496 ASCII (or UTF-8) character value.</p></div>
4497 <div class="paragraph"><p>In addition, Jim Tcl provides basic support for conversion to binary with <code>%b</code>.</p></div>
4498 <div class="paragraph"><p><a href="#_format"><strong><code>format</code></strong></a> does backslash substitution on its <code><em>formatString</em></code>
4499 argument, so backslash sequences in <code><em>formatString</em></code> will be handled
4500 correctly even if the argument is in braces.</p></div>
4501 <div class="paragraph"><p>The return value from <a href="#_format"><strong><code>format</code></strong></a> is the formatted string.</p></div>
4502 </div>
4503 <div class="sect2">
4504 <h3 id="_getref">getref</h3>
4505 <div class="paragraph"><p><code><strong>getref</strong> <em>reference</em></code></p></div>
4506 <div class="paragraph"><p>Returns the string associated with <code><em>reference</em></code>. The reference must
4507 be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a> command.</p></div>
4508 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
4509 </div>
4510 <div class="sect2">
4511 <h3 id="_gets">gets</h3>
4512 <div class="paragraph"><p><code><strong>gets</strong> <em>fileId ?varName?</em></code></p></div>
4513 <div class="paragraph"><p><code><em>fileId</em> <strong>gets</strong> <em>?varName?</em></code></p></div>
4514 <div class="paragraph"><p>Reads the next line from the file given by <code><em>fileId</em></code> and discards
4515 the terminating newline character.</p></div>
4516 <div class="paragraph"><p>If <code><em>varName</em></code> is specified, then the line is placed in the variable
4517 by that name and the return value is a count of the number of characters
4518 read (not including the newline).</p></div>
4519 <div class="paragraph"><p>If the end of the file is reached before reading
4520 any characters then -1 is returned and <code><em>varName</em></code> is set to an
4521 empty string.</p></div>
4522 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified then the return value will be
4523 the line (minus the newline character) or an empty string if
4524 the end of the file is reached before reading any characters.</p></div>
4525 <div class="paragraph"><p>An empty string will also be returned if a line contains no characters
4526 except the newline, so <a href="#_eof"><strong><code>eof</code></strong></a> may have to be used to determine
4527 what really happened.</p></div>
4528 <div class="paragraph"><p>If the last character in the file is not a newline character, then
4529 <a href="#_gets"><strong><code>gets</code></strong></a> behaves as if there were an additional newline character
4530 at the end of the file.</p></div>
4531 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous
4532 call to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened
4533 for reading.</p></div>
4534 </div>
4535 <div class="sect2">
4536 <h3 id="_glob">glob</h3>
4537 <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>
4538 <div class="paragraph"><p>This command performs filename globbing, using csh rules. The returned
4539 value from <a href="#_glob"><strong><code>glob</code></strong></a> is the list of expanded filenames.</p></div>
4540 <div class="paragraph"><p>If <code>-nocomplain</code> is specified as the first argument then an empty
4541 list may be returned; otherwise an error is returned if the expanded
4542 list is empty. The <code>-nocomplain</code> argument must be provided
4543 exactly: an abbreviation will not be accepted.</p></div>
4544 <div class="paragraph"><p>If <code>-directory</code> is given, the <code><em>dir</em></code> is understood to contain a
4545 directory name to search in. This allows globbing inside directories
4546 whose names may contain glob-sensitive characters. The returned names
4547 include the directory name unless <code><em>-tails</em></code> is specified.</p></div>
4548 <div class="paragraph"><p>If <code><em>-tails</em></code> is specified, along with <code>-directory</code>, the returned names
4549 are relative to the given directory.</p></div>
4550 </div>
4551 <div class="sect2">
4552 <h3 id="_global">global</h3>
4553 <div class="paragraph"><p><code><strong>global</strong> <em>varName ?varName ...?</em></code></p></div>
4554 <div class="paragraph"><p>This command is ignored unless a Tcl procedure is being interpreted.
4555 If so, then it declares each given <code><em>varName</em></code> to be a global variable
4556 rather than a local one. For the duration of the current procedure
4557 (and only while executing in the current procedure), any reference to
4558 <code><em>varName</em></code> will be bound to a global variable instead
4559 of a local one.</p></div>
4560 <div class="paragraph"><p>An alternative to using <a href="#_global"><strong><code>global</code></strong></a> is to use the <code>::</code> prefix
4561 to explicitly name a variable in the global scope.</p></div>
4562 </div>
4563 <div class="sect2">
4564 <h3 id="_if">if</h3>
4565 <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>
4566 <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
4567 that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument). The value of the expression must
4568 be numeric; if it is non-zero then <code><em>body1</em></code> is executed by passing it to
4569 the Tcl interpreter.</p></div>
4570 <div class="paragraph"><p>Otherwise <code><em>expr2</em></code> is evaluated as an expression and if it is non-zero
4571 then <code><em>body2</em></code> is executed, and so on.</p></div>
4572 <div class="paragraph"><p>If none of the expressions evaluates to non-zero then <code><em>bodyN</em></code> is executed.</p></div>
4573 <div class="paragraph"><p>The <code>then</code> and <code>else</code> arguments are optional "noise words" to make the
4574 command easier to read.</p></div>
4575 <div class="paragraph"><p>There may be any number of <code>elseif</code> clauses, including zero. <code><em>bodyN</em></code>
4576 may also be omitted as long as <code>else</code> is omitted too.</p></div>
4577 <div class="paragraph"><p>The return value from the command is the result of the body script that
4578 was executed, or an empty string if none of the expressions was non-zero
4579 and there was no <code><em>bodyN</em></code>.</p></div>
4580 </div>
4581 <div class="sect2">
4582 <h3 id="_incr">incr</h3>
4583 <div class="paragraph"><p><code><strong>incr</strong> <em>varName ?increment?</em></code></p></div>
4584 <div class="paragraph"><p>Increment the value stored in the variable whose name is <code><em>varName</em></code>.
4585 The value of the variable must be integral.</p></div>
4586 <div class="paragraph"><p>If <code><em>increment</em></code> is supplied then its value (which must be an
4587 integer) is added to the value of variable <code><em>varName</em></code>; otherwise
4588 1 is added to <code><em>varName</em></code>.</p></div>
4589 <div class="paragraph"><p>The new value is stored as a decimal string in variable <code><em>varName</em></code>
4590 and also returned as result.</p></div>
4591 <div class="paragraph"><p>If the variable does not exist, the variable is implicitly created
4592 and set to <code>0</code> first.</p></div>
4593 </div>
4594 <div class="sect2">
4595 <h3 id="_info">info</h3>
4596 <div class="dlist"><dl>
4597 <dt class="hdlist1">
4598 <code><strong>info</strong> <em>option ?arg...?</em></code>
4599 </dt>
4600 <dd>
4602 Provide information about various internals to the Tcl interpreter.
4603 The legal <code><em>option</em></code>'s (which may be abbreviated) are:
4604 </p>
4605 </dd>
4606 <dt class="hdlist1">
4607 <code><strong>info args</strong> <em>procname</em></code>
4608 </dt>
4609 <dd>
4611 Returns a list containing the names of the arguments to procedure
4612 <code><em>procname</em></code>, in order. <code><em>procname</em></code> must be the name of a
4613 Tcl command procedure.
4614 </p>
4615 </dd>
4616 <dt class="hdlist1">
4617 <code><strong>info alias</strong> <em>command</em></code>
4618 </dt>
4619 <dd>
4621 <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
4622 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>
4623 </p>
4624 </dd>
4625 <dt class="hdlist1">
4626 <code><strong>info body</strong> <em>procname</em></code>
4627 </dt>
4628 <dd>
4630 Returns the body of procedure <code><em>procname</em></code>. <code><em>procname</em></code> must be
4631 the name of a Tcl command procedure.
4632 </p>
4633 </dd>
4634 <dt class="hdlist1">
4635 <code><strong>info channels</strong></code>
4636 </dt>
4637 <dd>
4639 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>
4640 </p>
4641 </dd>
4642 <dt class="hdlist1">
4643 <code><strong>info commands</strong> ?<em>pattern</em>?</code>
4644 </dt>
4645 <dd>
4647 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of names of all the
4648 Tcl commands, including both the built-in commands written in C and
4649 the command procedures defined using the <a href="#_proc"><strong><code>proc</code></strong></a> command.
4650 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4651 are returned. Matching is determined using the same rules as for
4652 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4653 </p>
4654 </dd>
4655 <dt class="hdlist1">
4656 <code><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</code>
4657 </dt>
4658 <dd>
4660 Returns 1 if <code><em>command</em></code> is a complete Tcl command in the sense of
4661 having no unclosed quotes, braces, brackets or array element names,
4662 If the command doesn&#8217;t appear to be complete then 0 is returned.
4663 This command is typically used in line-oriented input environments
4664 to allow users to type in commands that span multiple lines; if the
4665 command isn&#8217;t complete, the script can delay evaluating it until additional
4666 lines have been typed to complete the command. If <code><em>varName</em></code> is specified, the
4667 missing character is stored in the variable with that name.
4668 </p>
4669 </dd>
4670 <dt class="hdlist1">
4671 <code><strong>info exists</strong> <em>varName</em></code>
4672 </dt>
4673 <dd>
4675 Returns <em>1</em> if the variable named <code><em>varName</em></code> exists in the
4676 current context (either as a global or local variable), returns <em>0</em>
4677 otherwise.
4678 </p>
4679 </dd>
4680 <dt class="hdlist1">
4681 <code><strong>info frame</strong> ?<em>number</em>?</code>
4682 </dt>
4683 <dd>
4685 If <code><em>number</em></code> is not specified, this command returns a number
4686 which is the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> - the current stack frame level.
4687 If <code><em>number</em></code> is specified, then the result is a list consisting of the procedure,
4688 filename and line number for the procedure call at level <code><em>number</em></code> on the stack.
4689 If <code><em>number</em></code> is positive then it selects a particular stack level (1 refers
4690 to the top-most active procedure, 2 to the procedure it called, and
4691 so on); otherwise it gives a level relative to the current level
4692 (0 refers to the current procedure, -1 to its caller, and so on).
4693 The level has an identical meaning to <a href="#_info"><strong><code>info</code></strong></a> <code>level</code>.
4694 </p>
4695 </dd>
4696 <dt class="hdlist1">
4697 <code><strong>info globals</strong> ?<em>pattern</em>?</code>
4698 </dt>
4699 <dd>
4701 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4702 of currently-defined global variables.
4703 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4704 are returned. Matching is determined using the same rules as for
4705 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4706 </p>
4707 </dd>
4708 <dt class="hdlist1">
4709 <code><strong>info hostname</strong></code>
4710 </dt>
4711 <dd>
4713 An alias for <a href="#cmd_1"><strong><code>os.gethostname</code></strong></a> for compatibility with Tcl 6.x
4714 </p>
4715 </dd>
4716 <dt class="hdlist1">
4717 <code><strong>info level</strong> ?<em>number</em>?</code>
4718 </dt>
4719 <dd>
4721 If <code><em>number</em></code> is not specified, this command returns a number
4722 giving the stack level of the invoking procedure, or 0 if the
4723 command is invoked at top-level. If <code><em>number</em></code> is specified,
4724 then the result is a list consisting of the name and arguments for the
4725 procedure call at level <code><em>number</em></code> on the stack. If <code><em>number</em></code>
4726 is positive then it selects a particular stack level (1 refers
4727 to the top-most active procedure, 2 to the procedure it called, and
4728 so on); otherwise it gives a level relative to the current level
4729 (0 refers to the current procedure, -1 to its caller, and so on).
4730 See the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command for more information on what stack
4731 levels mean.
4732 </p>
4733 </dd>
4734 <dt class="hdlist1">
4735 <code><strong>info locals</strong> ?<em>pattern</em>?</code>
4736 </dt>
4737 <dd>
4739 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4740 of currently-defined local variables, including arguments to the
4741 current procedure, if any. Variables defined with the <a href="#_global"><strong><code>global</code></strong></a>
4742 and <a href="#_upvar"><strong><code>upvar</code></strong></a> commands will not be returned. If <code><em>pattern</em></code> is
4743 specified, only those names matching <code><em>pattern</em></code> are returned.
4744 Matching is determined using the same rules as for <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4745 </p>
4746 </dd>
4747 <dt class="hdlist1">
4748 <code><strong>info nameofexecutable</strong></code>
4749 </dt>
4750 <dd>
4752 Returns the name of the binary file from which the application
4753 was invoked. A full path will be returned, unless the path
4754 can&#8217;t be determined, in which case the empty string will be returned.
4755 </p>
4756 </dd>
4757 <dt class="hdlist1">
4758 <code><strong>info procs</strong> ?<em>pattern</em>?</code>
4759 </dt>
4760 <dd>
4762 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the
4763 names of Tcl command procedures.
4764 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4765 are returned. Matching is determined using the same rules as for
4766 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4767 </p>
4768 </dd>
4769 <dt class="hdlist1">
4770 <code><strong>info references</strong></code>
4771 </dt>
4772 <dd>
4774 Returns a list of all references which have not yet been garbage
4775 collected.
4776 </p>
4777 </dd>
4778 <dt class="hdlist1">
4779 <code><strong>info returncodes</strong> ?<em>code</em>?</code>
4780 </dt>
4781 <dd>
4783 Returns a list representing the mapping of standard return codes
4784 to names. e.g. <code>{0 ok 1 error 2 return ...}</code>. If a code is given,
4785 instead returns the name for the given code.
4786 </p>
4787 </dd>
4788 <dt class="hdlist1">
4789 <code><strong>info script</strong></code>
4790 </dt>
4791 <dd>
4793 If a Tcl script file is currently being evaluated (i.e. there is a
4794 call to <em>Jim_EvalFile</em> active or there is an active invocation
4795 of the <a href="#_source"><strong><code>source</code></strong></a> command), then this command returns the name
4796 of the innermost file being processed. Otherwise the command returns an
4797 empty string.
4798 </p>
4799 </dd>
4800 <dt class="hdlist1">
4801 <code><strong>info source</strong> <em>script ?filename line?</em></code>
4802 </dt>
4803 <dd>
4805 With a single argument, returns the original source location of the given script as a list of
4806 <code>{filename linenumber}</code>. If the source location can&#8217;t be determined, the
4807 list <code>{{} 0}</code> is returned. If <code><em>filename</em></code> and <code><em>line</em></code> are given, returns a copy
4808 of <code><em>script</em></code> with the associate source information. This can be useful to produce
4809 useful messages from <a href="#_eval"><strong><code>eval</code></strong></a>, etc. if the original source information may be lost.
4810 </p>
4811 </dd>
4812 <dt class="hdlist1">
4813 <code><strong>info stacktrace</strong></code>
4814 </dt>
4815 <dd>
4817 After an error is caught with <a href="#_catch"><strong><code>catch</code></strong></a>, returns the stack trace as a list
4818 of <code>{procedure filename line ...}</code>.
4819 </p>
4820 </dd>
4821 <dt class="hdlist1">
4822 <code><strong>info statics</strong> <em>procname</em></code>
4823 </dt>
4824 <dd>
4826 Returns a dictionary of the static variables of procedure
4827 <code><em>procname</em></code>. <code><em>procname</em></code> must be the name of a Tcl command
4828 procedure. An empty dictionary is returned if the procedure has
4829 no static variables.
4830 </p>
4831 </dd>
4832 <dt class="hdlist1">
4833 <code><strong>info version</strong></code>
4834 </dt>
4835 <dd>
4837 Returns the version number for this version of Jim in the form <code><strong>x.yy</strong></code>.
4838 </p>
4839 </dd>
4840 <dt class="hdlist1">
4841 <code><strong>info vars</strong> ?<em>pattern</em>?</code>
4842 </dt>
4843 <dd>
4845 If <code><em>pattern</em></code> isn&#8217;t specified,
4846 returns a list of all the names of currently-visible variables, including
4847 both locals and currently-visible globals.
4848 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4849 are returned. Matching is determined using the same rules as for
4850 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4851 </p>
4852 </dd>
4853 </dl></div>
4854 </div>
4855 <div class="sect2">
4856 <h3 id="_join">join</h3>
4857 <div class="paragraph"><p><code><strong>join</strong> <em>list ?joinString?</em></code></p></div>
4858 <div class="paragraph"><p>The <code><em>list</em></code> argument must be a valid Tcl list. This command returns the
4859 string formed by joining all of the elements of <code><em>list</em></code> together with
4860 <code><em>joinString</em></code> separating each adjacent pair of elements.</p></div>
4861 <div class="paragraph"><p>The <code><em>joinString</em></code> argument defaults to a space character.</p></div>
4862 </div>
4863 <div class="sect2">
4864 <h3 id="_kill">kill</h3>
4865 <div class="paragraph"><p><code><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></code></p></div>
4866 <div class="paragraph"><p>Sends the given signal to the process identified by <code><em>pid</em></code>.</p></div>
4867 <div class="paragraph"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4868 <div class="ulist"><ul>
4869 <li>
4871 <code>TERM</code>
4872 </p>
4873 </li>
4874 <li>
4876 <code>SIGTERM</code>
4877 </p>
4878 </li>
4879 <li>
4881 <code>-TERM</code>
4882 </p>
4883 </li>
4884 <li>
4886 <code>15</code>
4887 </p>
4888 </li>
4889 <li>
4891 <code>-15</code>
4892 </p>
4893 </li>
4894 </ul></div>
4895 <div class="paragraph"><p>The signal name may be in either upper or lower case.</p></div>
4896 <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>
4897 <div class="paragraph"><p>If no signal is specified, SIGTERM is used.</p></div>
4898 <div class="paragraph"><p>An error is raised if the signal could not be delivered.</p></div>
4899 </div>
4900 <div class="sect2">
4901 <h3 id="_lambda">lambda</h3>
4902 <div class="paragraph"><p><code><strong>lambda</strong> <em>args ?statics? body</em></code></p></div>
4903 <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
4904 creating a named procedure, it creates an anonymous procedure and returns
4905 the name of the procedure.</p></div>
4906 <div class="paragraph"><p>See <a href="#_proc"><strong><code>proc</code></strong></a> and GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
4907 </div>
4908 <div class="sect2">
4909 <h3 id="_lappend">lappend</h3>
4910 <div class="paragraph"><p><code><strong>lappend</strong> <em>varName value ?value value ...?</em></code></p></div>
4911 <div class="paragraph"><p>Treat the variable given by <code><em>varName</em></code> as a list and append each of
4912 the <code><em>value</em></code> arguments to that list as a separate element, with spaces
4913 between elements.</p></div>
4914 <div class="paragraph"><p>If <code><em>varName</em></code> doesn&#8217;t exist, it is created as a list with elements given
4915 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
4916 each <code><em>value</em></code> is appended as a list element rather than raw text.</p></div>
4917 <div class="paragraph"><p>This command provides a relatively efficient way to build up large lists.
4918 For example,</p></div>
4919 <div class="literalblock">
4920 <div class="content">
4921 <pre><code>lappend a $b</code></pre>
4922 </div></div>
4923 <div class="paragraph"><p>is much more efficient than</p></div>
4924 <div class="literalblock">
4925 <div class="content">
4926 <pre><code>set a [concat $a [list $b]]</code></pre>
4927 </div></div>
4928 <div class="paragraph"><p>when <code>$a</code> is long.</p></div>
4929 </div>
4930 <div class="sect2">
4931 <h3 id="_lassign">lassign</h3>
4932 <div class="paragraph"><p><code><strong>lassign</strong> <em>list varName ?varName ...?</em></code></p></div>
4933 <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
4934 the variables given by the <code><em>varName</em></code> arguments in order. If there are more variable names than
4935 list elements, the remaining variables are set to the empty string. If there are more list elements
4936 than variables, a list of unassigned elements is returned.</p></div>
4937 <div class="literalblock">
4938 <div class="content">
4939 <pre><code>jim&gt; lassign {1 2 3} a b; puts a=$a,b=$b
4941 a=1,b=2</code></pre>
4942 </div></div>
4943 </div>
4944 <div class="sect2">
4945 <h3 id="_local">local</h3>
4946 <div class="paragraph"><p><code><strong>local</strong> <em>cmd ?arg...?</em></code></p></div>
4947 <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
4948 be the name of an existing command, which is marked as having local scope.
4949 This means that when the current procedure exits, the specified
4950 command is deleted. This can be useful with <a href="#_lambda"><strong><code>lambda</code></strong></a>, local procedures or
4951 to automatically close a filehandle.</p></div>
4952 <div class="paragraph"><p>In addition, if a command already exists with the same name,
4953 the existing command will be kept rather than deleted, and may be called
4954 via <a href="#_upcall"><strong><code>upcall</code></strong></a>. The previous command will be restored when the current
4955 procedure exits. See <a href="#_upcall"><strong><code>upcall</code></strong></a> for more details.</p></div>
4956 <div class="paragraph"><p>In this example, a local procedure is created. Note that the procedure
4957 continues to have global scope while it is active.</p></div>
4958 <div class="literalblock">
4959 <div class="content">
4960 <pre><code>proc outer {} {
4961 # proc ... returns "inner" which is marked local
4962 local proc inner {} {
4963 # will be deleted when 'outer' exits
4964 }</code></pre>
4965 </div></div>
4966 <div class="literalblock">
4967 <div class="content">
4968 <pre><code> inner
4970 }</code></pre>
4971 </div></div>
4972 <div class="paragraph"><p>In this example, the lambda is deleted at the end of the procedure rather
4973 than waiting until garbage collection.</p></div>
4974 <div class="literalblock">
4975 <div class="content">
4976 <pre><code>proc outer {} {
4977 set x [lambda inner {args} {
4978 # will be deleted when 'outer' exits
4980 # Use 'function' here which simply returns $x
4981 local function $x</code></pre>
4982 </div></div>
4983 <div class="literalblock">
4984 <div class="content">
4985 <pre><code> $x ...
4987 }</code></pre>
4988 </div></div>
4989 </div>
4990 <div class="sect2">
4991 <h3 id="_loop">loop</h3>
4992 <div class="paragraph"><p><code><strong>loop</strong> <em>var first limit ?incr? body</em></code></p></div>
4993 <div class="paragraph"><p>Similar to <a href="#_for"><strong><code>for</code></strong></a> except simpler and possibly more efficient.
4994 With a positive increment, equivalent to:</p></div>
4995 <div class="literalblock">
4996 <div class="content">
4997 <pre><code>for {set var $first} {$var &lt; $limit} {incr var $incr} $body</code></pre>
4998 </div></div>
4999 <div class="paragraph"><p>If <code><em>incr</em></code> is not specified, 1 is used.
5000 Note that setting the loop variable inside the loop does not
5001 affect the loop count.</p></div>
5002 </div>
5003 <div class="sect2">
5004 <h3 id="_lindex">lindex</h3>
5005 <div class="paragraph"><p><code><strong>lindex</strong> <em>list ?index &#8230;?</em></code></p></div>
5006 <div class="paragraph"><p>Treats <code><em>list</em></code> as a Tcl list and returns element <code><em>index</em></code> from it
5007 (0 refers to the first element of the list).
5008 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
5009 <div class="paragraph"><p>In extracting the element, <code><em>lindex</em></code> observes the same rules concerning
5010 braces and quotes and backslashes as the Tcl command interpreter; however,
5011 variable substitution and command substitution do not occur.</p></div>
5012 <div class="paragraph"><p>If no index values are given, simply returns <code><em>list</em></code></p></div>
5013 <div class="paragraph"><p>If <code><em>index</em></code> is negative or greater than or equal to the number of elements
5014 in <code><em>list</em></code>, then an empty string is returned.</p></div>
5015 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
5016 used in turn to select an element from the previous indexing
5017 operation, allowing the script to select elements from sublists.</p></div>
5018 </div>
5019 <div class="sect2">
5020 <h3 id="_linsert">linsert</h3>
5021 <div class="paragraph"><p><code><strong>linsert</strong> <em>list index element ?element element ...?</em></code></p></div>
5022 <div class="paragraph"><p>This command produces a new list from <code><em>list</em></code> by inserting all
5023 of the <code><em>element</em></code> arguments just before the element <code><em>index</em></code>
5024 of <code><em>list</em></code>. Each <code><em>element</em></code> argument will become
5025 a separate element of the new list. If <code><em>index</em></code> is less than
5026 or equal to zero, then the new elements are inserted at the
5027 beginning of the list. If <code><em>index</em></code> is greater than or equal
5028 to the number of elements in the list, then the new elements are
5029 appended to the list.</p></div>
5030 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
5031 </div>
5032 <div class="sect2">
5033 <h3 id="_list">list</h3>
5034 <div class="paragraph"><p><code><strong>list</strong> <em>arg ?arg ...?</em></code></p></div>
5035 <div class="paragraph"><p>This command returns a list comprised of all the arguments, <code><em>arg</em></code>. Braces
5036 and backslashes get added as necessary, so that the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
5037 may be used on the result to re-extract the original arguments, and also
5038 so that <a href="#_eval"><strong><code>eval</code></strong></a> may be used to execute the resulting list, with
5039 <code><em>arg1</em></code> comprising the command&#8217;s name and the other args comprising
5040 its arguments. <a href="#_list"><strong><code>list</code></strong></a> produces slightly different results than
5041 <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
5042 the list, while <a href="#_list"><strong><code>list</code></strong></a> works directly from the original arguments.
5043 For example, the command</p></div>
5044 <div class="literalblock">
5045 <div class="content">
5046 <pre><code>list a b {c d e} {f {g h}}</code></pre>
5047 </div></div>
5048 <div class="paragraph"><p>will return</p></div>
5049 <div class="literalblock">
5050 <div class="content">
5051 <pre><code>a b {c d e} {f {g h}}</code></pre>
5052 </div></div>
5053 <div class="paragraph"><p>while <a href="#_concat"><strong><code>concat</code></strong></a> with the same arguments will return</p></div>
5054 <div class="literalblock">
5055 <div class="content">
5056 <pre><code>a b c d e f {g h}</code></pre>
5057 </div></div>
5058 </div>
5059 <div class="sect2">
5060 <h3 id="_llength">llength</h3>
5061 <div class="paragraph"><p><code><strong>llength</strong> <em>list</em></code></p></div>
5062 <div class="paragraph"><p>Treats <code><em>list</em></code> as a list and returns a decimal string giving
5063 the number of elements in it.</p></div>
5064 </div>
5065 <div class="sect2">
5066 <h3 id="_lset">lset</h3>
5067 <div class="paragraph"><p><code><strong>lset</strong> <em>varName ?index ..? newValue</em></code></p></div>
5068 <div class="paragraph"><p>Sets an element in a list.</p></div>
5069 <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
5070 as the name of a variable containing a Tcl list. It also accepts
5071 zero or more indices into the list. Finally, it accepts a new value
5072 for an element of varName. If no indices are presented, the command
5073 takes the form:</p></div>
5074 <div class="literalblock">
5075 <div class="content">
5076 <pre><code>lset varName newValue</code></pre>
5077 </div></div>
5078 <div class="paragraph"><p>In this case, newValue replaces the old value of the variable
5079 varName.</p></div>
5080 <div class="paragraph"><p>When presented with a single index, the <a href="#_lset"><strong><code>lset</code></strong></a> command
5081 treats the content of the varName variable as a Tcl list. It addresses
5082 the index&#8217;th element in it (0 refers to the first element of the
5083 list). When interpreting the list, <a href="#_lset"><strong><code>lset</code></strong></a> observes the same rules
5084 concerning braces and quotes and backslashes as the Tcl command
5085 interpreter; however, variable substitution and command substitution
5086 do not occur. The command constructs a new list in which the
5087 designated element is replaced with newValue. This new list is
5088 stored in the variable varName, and is also the return value from
5089 the <a href="#_lset"><strong><code>lset</code></strong></a> command.</p></div>
5090 <div class="paragraph"><p>If index is negative or greater than or equal to the number of
5091 elements in $varName, then an error occurs.</p></div>
5092 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
5093 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
5094 used in turn to address an element within a sublist designated by
5095 the previous indexing operation, allowing the script to alter
5096 elements in sublists. The command,</p></div>
5097 <div class="literalblock">
5098 <div class="content">
5099 <pre><code>lset a 1 2 newValue</code></pre>
5100 </div></div>
5101 <div class="paragraph"><p>replaces element 2 of sublist 1 with <code><em>newValue</em></code>.</p></div>
5102 <div class="paragraph"><p>The integer appearing in each index argument must be greater than
5103 or equal to zero. The integer appearing in each index argument must
5104 be strictly less than the length of the corresponding list. In other
5105 words, the <a href="#_lset"><strong><code>lset</code></strong></a> command cannot change the size of a list. If an
5106 index is outside the permitted range, an error is reported.</p></div>
5107 </div>
5108 <div class="sect2">
5109 <h3 id="_lmap">lmap</h3>
5110 <div class="paragraph"><p><code><strong>lmap</strong> <em>varName list body</em></code></p></div>
5111 <div class="paragraph"><p><code><strong>lmap</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
5112 <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>
5113 <div class="paragraph"><p>For example:</p></div>
5114 <div class="literalblock">
5115 <div class="content">
5116 <pre><code>jim&gt; lmap i {1 2 3 4 5} {expr $i*$i}
5117 1 4 9 16 25
5118 jim&gt; lmap a {1 2 3} b {A B C} {list $a $b}
5119 {1 A} {2 B} {3 C}</code></pre>
5120 </div></div>
5121 <div class="paragraph"><p>If the body invokes <a href="#_continue"><strong><code>continue</code></strong></a>, no value is added for this iteration.
5122 If the body invokes <a href="#_break"><strong><code>break</code></strong></a>, the loop ends and no more values are added.</p></div>
5123 </div>
5124 <div class="sect2">
5125 <h3 id="_load">load</h3>
5126 <div class="paragraph"><p><code><strong>load</strong> <em>filename</em></code></p></div>
5127 <div class="paragraph"><p>Loads the dynamic extension, <code><em>filename</em></code>. Generally the filename should have
5128 the extension <code>.so</code>. The initialisation function for the module must be based
5129 on the name of the file. For example loading <code>hwaccess.so</code> will invoke
5130 the initialisation function, <code>Jim_hwaccessInit</code>. Normally the <a href="#_load"><strong><code>load</code></strong></a> command
5131 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>
5132 </div>
5133 <div class="sect2">
5134 <h3 id="_lrange">lrange</h3>
5135 <div class="paragraph"><p><code><strong>lrange</strong> <em>list first last</em></code></p></div>
5136 <div class="paragraph"><p><code><em>list</em></code> must be a valid Tcl list. This command will return a new
5137 list consisting of elements <code><em>first</em></code> through <code><em>last</em></code>, inclusive.</p></div>
5138 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.</p></div>
5139 <div class="paragraph"><p>If <code><em>last</em></code> is greater than or equal to the number of elements
5140 in the list, then it is treated as if it were <code>end</code>.</p></div>
5141 <div class="paragraph"><p>If <code><em>first</em></code> is greater than <code><em>last</em></code> then an empty string
5142 is returned.</p></div>
5143 <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
5144 same result as <code>"<a href="#_lindex"><strong><code>lindex</code></strong></a> <em>list first</em>"</code> (although it often does
5145 for simple fields that aren&#8217;t enclosed in braces); it does, however,
5146 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>
5147 </div>
5148 <div class="sect2">
5149 <h3 id="_lreplace">lreplace</h3>
5150 <div class="paragraph"><p><code><strong>lreplace</strong> <em>list first last ?element element ...?</em></code></p></div>
5151 <div class="paragraph"><p>Returns a new list formed by replacing one or more elements of
5152 <code><em>list</em></code> with the <code><em>element</em></code> arguments.</p></div>
5153 <div class="paragraph"><p><code><em>first</em></code> gives the index in <code><em>list</em></code> of the first element
5154 to be replaced.</p></div>
5155 <div class="paragraph"><p>If <code><em>first</em></code> is less than zero then it refers to the first
5156 element of <code><em>list</em></code>; the element indicated by <code><em>first</em></code>
5157 must exist in the list.</p></div>
5158 <div class="paragraph"><p><code><em>last</em></code> gives the index in <code><em>list</em></code> of the last element
5159 to be replaced; it must be greater than or equal to <code><em>first</em></code>.</p></div>
5160 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.</p></div>
5161 <div class="paragraph"><p>The <code><em>element</em></code> arguments specify zero or more new arguments to
5162 be added to the list in place of those that were deleted.</p></div>
5163 <div class="paragraph"><p>Each <code><em>element</em></code> argument will become a separate element of
5164 the list.</p></div>
5165 <div class="paragraph"><p>If no <code><em>element</em></code> arguments are specified, then the elements
5166 between <code><em>first</em></code> and <code><em>last</em></code> are simply deleted.</p></div>
5167 </div>
5168 <div class="sect2">
5169 <h3 id="_lrepeat">lrepeat</h3>
5170 <div class="paragraph"><p><code><strong>lrepeat</strong> <em>number element1 ?element2 ...?</em></code></p></div>
5171 <div class="paragraph"><p>Build a list by repeating elements <code><em>number</em></code> times (which must be
5172 a positive integer).</p></div>
5173 <div class="literalblock">
5174 <div class="content">
5175 <pre><code>jim&gt; lrepeat 3 a b
5176 a b a b a b</code></pre>
5177 </div></div>
5178 </div>
5179 <div class="sect2">
5180 <h3 id="_lreverse">lreverse</h3>
5181 <div class="paragraph"><p><code><strong>lreverse</strong> <em>list</em></code></p></div>
5182 <div class="paragraph"><p>Returns the list in reverse order.</p></div>
5183 <div class="literalblock">
5184 <div class="content">
5185 <pre><code>jim&gt; lreverse {1 2 3}
5186 3 2 1</code></pre>
5187 </div></div>
5188 </div>
5189 <div class="sect2">
5190 <h3 id="_lsearch">lsearch</h3>
5191 <div class="paragraph"><p><code><strong>lsearch</strong> <em>?options? list pattern</em></code></p></div>
5192 <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
5193 command returns the index of the first matching element (unless the options <code>-all</code>, <code>-inline</code> or <code>-bool</code> are
5194 specified.) If not, the command returns -1. The option arguments indicates how the elements of
5195 the list are to be matched against pattern and must have one of the values below:</p></div>
5196 <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>
5197 <div class="dlist"><dl>
5198 <dt class="hdlist1">
5199 <code><strong>-exact</strong></code>
5200 </dt>
5201 <dd>
5203 <code><em>pattern</em></code> is a literal string that is compared for exact equality against each list element.
5204 This is the default.
5205 </p>
5206 </dd>
5207 <dt class="hdlist1">
5208 <code><strong>-glob</strong></code>
5209 </dt>
5210 <dd>
5212 <code><em>pattern</em></code> is a glob-style pattern which is matched against each list element using the same
5213 rules as the string match command.
5214 </p>
5215 </dd>
5216 <dt class="hdlist1">
5217 <code><strong>-regexp</strong></code>
5218 </dt>
5219 <dd>
5221 <code><em>pattern</em></code> is treated as a regular expression and matched against each list element using
5222 the rules described by <a href="#_regexp"><strong><code>regexp</code></strong></a>.
5223 </p>
5224 </dd>
5225 <dt class="hdlist1">
5226 <code><strong>-command</strong> <em>cmdname</em></code>
5227 </dt>
5228 <dd>
5230 <code><em>cmdname</em></code> is a command which is used to match the pattern against each element of the
5231 list. It is invoked as <code><em>cmdname</em> ?<strong>-nocase</strong>? <em>pattern listvalue</em></code> and should return 1
5232 for a match, or 0 for no match.
5233 </p>
5234 </dd>
5235 <dt class="hdlist1">
5236 <code><strong>-all</strong></code>
5237 </dt>
5238 <dd>
5240 Changes the result to be the list of all matching indices (or all matching values if
5241 <code>-inline</code> is specified as well). If indices are returned, the indices will be in numeric
5242 order. If values are returned, the order of the values will be the order of those values
5243 within the input list.
5244 </p>
5245 </dd>
5246 <dt class="hdlist1">
5247 <code><strong>-inline</strong></code>
5248 </dt>
5249 <dd>
5251 The matching value is returned instead of its index (or an empty string if no value
5252 matches). If <code>-all</code> is also specified, then the result of the command is the list of all
5253 values that matched. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5254 </p>
5255 </dd>
5256 <dt class="hdlist1">
5257 <code><strong>-bool</strong></code>
5258 </dt>
5259 <dd>
5261 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <code>-all</code> is also specified,
5262 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
5263 the corresponding element matches. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5264 </p>
5265 </dd>
5266 <dt class="hdlist1">
5267 <code><strong>-not</strong></code>
5268 </dt>
5269 <dd>
5271 This negates the sense of the match, returning the index (or value
5272 if <code>-inline</code> is specified) of the first non-matching value in the
5273 list. If <code>-bool</code> is also specified, the <em>0</em> will be returned if a
5274 match is found, or <em>1</em> otherwise. If <code>-all</code> is also specified,
5275 non-matches will be returned rather than matches.
5276 </p>
5277 </dd>
5278 <dt class="hdlist1">
5279 <code><strong>-nocase</strong></code>
5280 </dt>
5281 <dd>
5283 Causes comparisons to be handled in a case-insensitive manner.
5284 </p>
5285 </dd>
5286 </dl></div>
5287 </div>
5288 <div class="sect2">
5289 <h3 id="_lsort">lsort</h3>
5290 <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>
5291 <div class="paragraph"><p>Sort the elements of <code><em>list</em></code>, returning a new list in sorted order.
5292 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.</p></div>
5293 <div class="paragraph"><p>If <code>-nocase</code> is specified, comparisons are case-insensitive.</p></div>
5294 <div class="paragraph"><p>If <code>-integer</code> is specified, numeric sorting is used.</p></div>
5295 <div class="paragraph"><p>If <code>-real</code> is specified, floating point number sorting is used.</p></div>
5296 <div class="paragraph"><p>If <code>-command <em>cmdname</em></code> is specified, <code><em>cmdname</em></code> is treated as a command
5297 name. For each comparison, <code><em>cmdname $value1 $value2</code></em> is called which
5298 should compare the values and return an integer less than, equal
5299 to, or greater than zero if the <code><em>$value1</em></code> is to be considered less
5300 than, equal to, or greater than <code><em>$value2</em></code>, respectively.</p></div>
5301 <div class="paragraph"><p>If <code>-decreasing</code> is specified, the resulting list is in the opposite
5302 order to what it would be otherwise. <code>-increasing</code> is the default.</p></div>
5303 <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.
5304 Note that duplicates are determined relative to the comparison used in the sort. Thus if <code>-index 0</code> is used,
5305 <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>
5306 <div class="paragraph"><p>If <code>-index <em>listindex</em></code> is specified, each element of the list is treated as a list and
5307 the given index is extracted from the list for comparison. The list index may
5308 be any valid list index, such as <code>1</code>, <code>end</code> or <code>end-2</code>.</p></div>
5309 </div>
5310 <div class="sect2">
5311 <h3 id="_open">open</h3>
5312 <div class="paragraph"><p><code><strong>open</strong> <em>fileName ?access?</em></code></p></div>
5313 <div class="paragraph"><p><code><strong>open</strong> <em>|command-pipeline ?access?</em></code></p></div>
5314 <div class="paragraph"><p>Opens a file and returns an identifier
5315 that may be used in future invocations
5316 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>.
5317 <code><em>fileName</em></code> gives the name of the file to open.</p></div>
5318 <div class="paragraph"><p>The <code><em>access</em></code> argument indicates the way in which the file is to be accessed.
5319 It may have any of the following values:</p></div>
5320 <div class="dlist"><dl>
5321 <dt class="hdlist1">
5322 <code>r</code>
5323 </dt>
5324 <dd>
5326 Open the file for reading only; the file must already exist.
5327 </p>
5328 </dd>
5329 <dt class="hdlist1">
5330 <code>r</code>+
5331 </dt>
5332 <dd>
5334 Open the file for both reading and writing; the file must
5335 already exist.
5336 </p>
5337 </dd>
5338 <dt class="hdlist1">
5339 <code>w</code>
5340 </dt>
5341 <dd>
5343 Open the file for writing only. Truncate it if it exists. If it doesn&#8217;t
5344 exist, create a new file.
5345 </p>
5346 </dd>
5347 <dt class="hdlist1">
5348 <code>w</code>+
5349 </dt>
5350 <dd>
5352 Open the file for reading and writing. Truncate it if it exists.
5353 If it doesn&#8217;t exist, create a new file.
5354 </p>
5355 </dd>
5356 <dt class="hdlist1">
5357 <code>a</code>
5358 </dt>
5359 <dd>
5361 Open the file for writing only. The file must already exist, and the file
5362 is positioned so that new data is appended to the file.
5363 </p>
5364 </dd>
5365 <dt class="hdlist1">
5366 <code>a</code>+
5367 </dt>
5368 <dd>
5370 Open the file for reading and writing. If the file doesn&#8217;t
5371 exist, create a new empty file. Set the initial access position
5372 to the end of the file.
5373 </p>
5374 </dd>
5375 </dl></div>
5376 <div class="paragraph"><p><code><em>access</em></code> defaults to <em>r</em>.</p></div>
5377 <div class="paragraph"><p>If a file is opened for both reading and writing, then <a href="#_seek"><strong><code>seek</code></strong></a>
5378 must be invoked between a read and a write, or vice versa.</p></div>
5379 <div class="paragraph"><p>If the first character of <code><em>fileName</em></code> is "|" then the remaining
5380 characters of <code><em>fileName</em></code> are treated as a list of arguments that
5381 describe a command pipeline to invoke, in the same style as the
5382 arguments for exec. In this case, the channel identifier returned
5383 by open may be used to write to the command&#8217;s input pipe or read
5384 from its output pipe, depending on the value of <code><em>access</em></code>. If write-only
5385 access is used (e.g. <code><em>access</em></code> is <em>w</em>), then standard output for the
5386 pipeline is directed to the current standard output unless overridden
5387 by the command. If read-only access is used (e.g. <code><em>access</em></code> is r),
5388 standard input for the pipeline is taken from the current standard
5389 input unless overridden by the command.</p></div>
5390 <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
5391 forming the command pipeline.</p></div>
5392 <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>
5393 </div>
5394 <div class="sect2">
5395 <h3 id="_package">package</h3>
5396 <div class="paragraph"><p><code><strong>package provide</strong> <em>name ?version?</em></code></p></div>
5397 <div class="paragraph"><p>Indicates that the current script provides the package named <code><em>name</em></code>.
5398 If no version is specified, <em>1.0</em> is used.</p></div>
5399 <div class="paragraph"><p>Any script which provides a package may include this statement
5400 as the first statement, although it is not required.</p></div>
5401 <div class="paragraph"><p><code><strong>package require</strong> <em>name ?version?</em>*</code></p></div>
5402 <div class="paragraph"><p>Searches for the package with the given <code><em>name</em></code> by examining each path
5403 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
5404 or <em>$path/$name.tcl</em> as a script package.</p></div>
5405 <div class="paragraph"><p>The first such file which is found is considered to provide the package.
5406 (The version number is ignored).</p></div>
5407 <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,
5408 otherwise if <em>$name.tcl</em> exists it is loaded with the <a href="#_source"><strong><code>source</code></strong></a> command.</p></div>
5409 <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.
5410 No further attempt will be made to locate the file.</p></div>
5411 </div>
5412 <div class="sect2">
5413 <h3 id="_pid">pid</h3>
5414 <div class="paragraph"><p><code><strong>pid</strong></code></p></div>
5415 <div class="paragraph"><p><code><strong>pid</strong> <em>fileId</em></code></p></div>
5416 <div class="paragraph"><p>The first form returns the process identifier of the current process.</p></div>
5417 <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
5418 of the process ids forming the pipeline in the same form as <a href="#_exec"><strong><code>exec</code></strong></a> <code>... &amp;</code>.
5419 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
5420 the empty string is returned instead.</p></div>
5421 <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>
5422 </div>
5423 <div class="sect2">
5424 <h3 id="_proc">proc</h3>
5425 <div class="paragraph"><p><code><strong>proc</strong> <em>name args ?statics? body</em></code></p></div>
5426 <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>.
5427 When the new command is invoked, the contents of <code><em>body</em></code> will be executed.
5428 Tcl interpreter. <code><em>args</em></code> specifies the formal arguments to the procedure.
5429 If specified, <code><em>statics</em></code>, declares static variables which are bound to the
5430 procedure.</p></div>
5431 <div class="paragraph"><p>See PROCEDURES for detailed information about Tcl procedures.</p></div>
5432 <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>
5433 <div class="paragraph"><p>When a procedure is invoked, the procedure&#8217;s return value is the
5434 value specified in a <a href="#_return"><strong><code>return</code></strong></a> command. If the procedure doesn&#8217;t
5435 execute an explicit <a href="#_return"><strong><code>return</code></strong></a>, then its return value is the value
5436 of the last command executed in the procedure&#8217;s body.</p></div>
5437 <div class="paragraph"><p>If an error occurs while executing the procedure body, then the
5438 procedure-as-a-whole will return that same error.</p></div>
5439 </div>
5440 <div class="sect2">
5441 <h3 id="_puts">puts</h3>
5442 <div class="paragraph"><p><code><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></code></p></div>
5443 <div class="paragraph"><p><code><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></code></p></div>
5444 <div class="paragraph"><p>Writes the characters given by <code><em>string</em></code> to the file given
5445 by <code><em>fileId</em></code>. <code><em>fileId</em></code> must have been the return
5446 value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
5447 <code>stdout</code> or <code>stderr</code> to refer to one of the standard I/O
5448 channels; it must refer to a file that was opened for
5449 writing.</p></div>
5450 <div class="paragraph"><p>In the first form, if no <code><em>fileId</em></code> is specified then it defaults to <code>stdout</code>.
5451 <a href="#_puts"><strong><code>puts</code></strong></a> normally outputs a newline character after <code><em>string</em></code>,
5452 but this feature may be suppressed by specifying the <code>-nonewline</code>
5453 switch.</p></div>
5454 <div class="paragraph"><p>Output to files is buffered internally by Tcl; the <a href="#_flush"><strong><code>flush</code></strong></a>
5455 command may be used to force buffered characters to be output.</p></div>
5456 </div>
5457 <div class="sect2">
5458 <h3 id="_pwd">pwd</h3>
5459 <div class="paragraph"><p><code><strong>pwd</strong></code></p></div>
5460 <div class="paragraph"><p>Returns the path name of the current working directory.</p></div>
5461 </div>
5462 <div class="sect2">
5463 <h3 id="_rand">rand</h3>
5464 <div class="paragraph"><p><code><strong>rand</strong> <em>?min? ?max?</em></code></p></div>
5465 <div class="paragraph"><p>Returns a random integer between <code><em>min</em></code> (defaults to 0) and <code><em>max</em></code>
5466 (defaults to the maximum integer).</p></div>
5467 <div class="paragraph"><p>If only one argument is given, it is interpreted as <code><em>max</em></code>.</p></div>
5468 </div>
5469 <div class="sect2">
5470 <h3 id="_range">range</h3>
5471 <div class="paragraph"><p><code><strong>range</strong> <em>?start? end ?step?</em></code></p></div>
5472 <div class="paragraph"><p>Returns a list of integers starting at <code><em>start</em></code> (defaults to 0)
5473 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>
5474 <div class="literalblock">
5475 <div class="content">
5476 <pre><code>jim&gt; range 5
5477 0 1 2 3 4
5478 jim&gt; range 2 5
5479 2 3 4
5480 jim&gt; range 2 10 4
5482 jim&gt; range 7 4 -2
5483 7 5</code></pre>
5484 </div></div>
5485 </div>
5486 <div class="sect2">
5487 <h3 id="_read">read</h3>
5488 <div class="paragraph"><p><code><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></code></p></div>
5489 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</code></p></div>
5490 <div class="paragraph"><p><code><strong>read</strong> <em>fileId numBytes</em></code></p></div>
5491 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> <em>numBytes</em></code></p></div>
5492 <div class="paragraph"><p>In the first form, all of the remaining bytes are read from the file
5493 given by <code><em>fileId</em></code>; they are returned as the result of the command.
5494 If the <code>-nonewline</code> switch is specified then the last
5495 character of the file is discarded if it is a newline.</p></div>
5496 <div class="paragraph"><p>In the second form, the extra argument specifies how many bytes to read;
5497 exactly this many bytes will be read and returned, unless there are fewer than
5498 <code><em>numBytes</em></code> bytes left in the file; in this case, all the remaining
5499 bytes are returned.</p></div>
5500 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous call
5501 to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened for reading.</p></div>
5502 </div>
5503 <div class="sect2">
5504 <h3 id="_regexp">regexp</h3>
5505 <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>
5506 <div class="paragraph"><p>Determines whether the regular expression <code><em>exp</em></code> matches part or
5507 all of <code><em>string</em></code> and returns 1 if it does, 0 if it doesn&#8217;t.</p></div>
5508 <div class="paragraph"><p>See REGULAR EXPRESSIONS above for complete information on the
5509 syntax of <code><em>exp</em></code> and how it is matched against <code><em>string</em></code>.</p></div>
5510 <div class="paragraph"><p>If additional arguments are specified after <code><em>string</em></code> then they
5511 are treated as the names of variables to use to return
5512 information about which part(s) of <code><em>string</em></code> matched <code><em>exp</em></code>.
5513 <code><em>matchVar</em></code> will be set to the range of <code><em>string</em></code> that
5514 matched all of <code><em>exp</em></code>. The first <code><em>subMatchVar</em></code> will contain
5515 the characters in <code><em>string</em></code> that matched the leftmost parenthesized
5516 subexpression within <code><em>exp</em></code>, the next <code><em>subMatchVar</em></code> will
5517 contain the characters that matched the next parenthesized
5518 subexpression to the right in <code><em>exp</em></code>, and so on.</p></div>
5519 <div class="paragraph"><p>Normally, <code><em>matchVar</em></code> and the each <code><em>subMatchVar</em></code> are set to hold the
5520 matching characters from <a href="#_string"><strong><code>string</code></strong></a>, however see <code>-indices</code> and
5521 <code>-inline</code> below.</p></div>
5522 <div class="paragraph"><p>If there are more values for <code><em>subMatchVar</em></code> than parenthesized subexpressions
5523 within <code><em>exp</em></code>, or if a particular subexpression in <code><em>exp</em></code> doesn&#8217;t
5524 match the string (e.g. because it was in a portion of the expression
5525 that wasn&#8217;t matched), then the corresponding <code><em>subMatchVar</em></code> will be
5526 set to <code>"-1 -1"</code> if <code>-indices</code> has been specified or to an empty
5527 string otherwise.</p></div>
5528 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regexp</em></code></p></div>
5529 <div class="dlist"><dl>
5530 <dt class="hdlist1">
5531 <code><strong>-nocase</strong></code>
5532 </dt>
5533 <dd>
5535 Causes upper-case and lower-case characters to be treated as
5536 identical during the matching process.
5537 </p>
5538 </dd>
5539 <dt class="hdlist1">
5540 <code><strong>-line</strong></code>
5541 </dt>
5542 <dd>
5544 Use newline-sensitive matching. By default, newline
5545 is a completely ordinary character with no special meaning in
5546 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5547 and <code>.</code> never match newline, an <code></sup></code> anchor matches the null
5548 string after any newline in the string in addition to its normal
5549 function, and the <code>$</code> anchor matches the null string before any
5550 newline in the string in addition to its normal function.
5551 </p>
5552 </dd>
5553 <dt class="hdlist1">
5554 <code><strong>-indices</strong></code>
5555 </dt>
5556 <dd>
5558 Changes what is stored in the subMatchVars. Instead of
5559 storing the matching characters from string, each variable
5560 will contain a list of two decimal strings giving the indices
5561 in string of the first and last characters in the matching
5562 range of characters.
5563 </p>
5564 </dd>
5565 <dt class="hdlist1">
5566 <code><strong>-start</strong> <em>offset</em></code>
5567 </dt>
5568 <dd>
5570 Specifies a character index offset into the string at which to start
5571 matching the regular expression. If <code>-indices</code> is
5572 specified, the indices will be indexed starting from the
5573 absolute beginning of the input string. <code><em>offset</em></code> will be
5574 constrained to the bounds of the input string.
5575 </p>
5576 </dd>
5577 <dt class="hdlist1">
5578 <code><strong>-all</strong></code>
5579 </dt>
5580 <dd>
5582 Causes the regular expression to be matched as many times as possible
5583 in the string, returning the total number of matches found. If this
5584 is specified with match variables, they will contain information
5585 for the last match only.
5586 </p>
5587 </dd>
5588 <dt class="hdlist1">
5589 <code><strong>-inline</strong></code>
5590 </dt>
5591 <dd>
5593 Causes the command to return, as a list, the data that would otherwise
5594 be placed in match variables. When using <code>-inline</code>, match variables
5595 may not be specified. If used with <code>-all</code>, the list will be concatenated
5596 at each iteration, such that a flat list is always returned. For
5597 each match iteration, the command will append the overall match
5598 data, plus one element for each subexpression in the regular
5599 expression.
5600 </p>
5601 </dd>
5602 <dt class="hdlist1">
5603 <code><strong>--</strong></code>
5604 </dt>
5605 <dd>
5607 Marks the end of switches. The argument following this one will be
5608 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5609 </p>
5610 </dd>
5611 </dl></div>
5612 </div>
5613 <div class="sect2">
5614 <h3 id="_regsub">regsub</h3>
5615 <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>
5616 <div class="paragraph"><p>This command matches the regular expression <code><em>exp</em></code> against
5617 <code><em>string</em></code> using the rules described in REGULAR EXPRESSIONS
5618 above.</p></div>
5619 <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>
5620 with the substitutions detailed below, and returns the number of
5621 substitutions made (normally 1 unless <code>-all</code> is specified).
5622 This is 0 if there were no matches.</p></div>
5623 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified, the substituted string will be returned
5624 instead.</p></div>
5625 <div class="paragraph"><p>When copying <code><em>string</em></code>, the portion of <code><em>string</em></code> that
5626 matched <code><em>exp</em></code> is replaced with <code><em>subSpec</em></code>.
5627 If <code><em>subSpec</em></code> contains a <code>&amp;</code> or <code>\0</code>, then it is replaced
5628 in the substitution with the portion of <code><em>string</em></code> that
5629 matched <code><em>exp</em></code>.</p></div>
5630 <div class="paragraph"><p>If <code><em>subSpec</em></code> contains a <code>\n</code>, where <code><em>n</em></code> is a digit
5631 between 1 and 9, then it is replaced in the substitution with
5632 the portion of <code><em>string</em></code> that matched the <code><em>n</em></code>'-th
5633 parenthesized subexpression of <code><em>exp</em></code>.
5634 Additional backslashes may be used in <code><em>subSpec</em></code> to prevent special
5635 interpretation of <code>&amp;</code> or <code>\0</code> or <code>\n</code> or
5636 backslash.</p></div>
5637 <div class="paragraph"><p>The use of backslashes in <code><em>subSpec</em></code> tends to interact badly
5638 with the Tcl parser&#8217;s use of backslashes, so it&#8217;s generally
5639 safest to enclose <code><em>subSpec</em></code> in braces if it includes
5640 backslashes.</p></div>
5641 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regsub</em></code></p></div>
5642 <div class="dlist"><dl>
5643 <dt class="hdlist1">
5644 <code><strong>-nocase</strong></code>
5645 </dt>
5646 <dd>
5648 Upper-case characters in <code><em>string</em></code> are converted to lower-case
5649 before matching against <code><em>exp</em></code>; however, substitutions
5650 specified by <code><em>subSpec</em></code> use the original unconverted form
5651 of <code><em>string</em></code>.
5652 </p>
5653 </dd>
5654 <dt class="hdlist1">
5655 <code><strong>-all</strong></code>
5656 </dt>
5657 <dd>
5659 All ranges in <code><em>string</em></code> that match <code><em>exp</em></code> are found and substitution
5660 is performed for each of these ranges, rather than only the
5661 first. The <code>&amp;</code> and <code>\n</code> sequences are handled for
5662 each substitution using the information from the corresponding
5663 match.
5664 </p>
5665 </dd>
5666 <dt class="hdlist1">
5667 <code><strong>-line</strong></code>
5668 </dt>
5669 <dd>
5671 Use newline-sensitive matching. By default, newline
5672 is a completely ordinary character with no special meaning in
5673 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5674 and <code>.</code> never match newline, an <code></sup></code> anchor matches the null
5675 string after any newline in the string in addition to its normal
5676 function, and the <code>$</code> anchor matches the null string before any
5677 newline in the string in addition to its normal function.
5678 </p>
5679 </dd>
5680 <dt class="hdlist1">
5681 <code><strong>-start</strong> <em>offset</em></code>
5682 </dt>
5683 <dd>
5685 Specifies a character index offset into the string at which to
5686 start matching the regular expression. <code><em>offset</em></code> will be
5687 constrained to the bounds of the input string.
5688 </p>
5689 </dd>
5690 <dt class="hdlist1">
5691 <code><strong>--</strong></code>
5692 </dt>
5693 <dd>
5695 Marks the end of switches. The argument following this one will be
5696 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5697 </p>
5698 </dd>
5699 </dl></div>
5700 </div>
5701 <div class="sect2">
5702 <h3 id="_ref">ref</h3>
5703 <div class="paragraph"><p><code><strong>ref</strong> <em>string tag ?finalizer?</em></code></p></div>
5704 <div class="paragraph"><p>Create a new reference containing <code><em>string</em></code> of type <code><em>tag</em></code>.
5705 If <code><em>finalizer</em></code> is specified, it is a command which will be invoked
5706 when the a garbage collection cycle runs and this reference is
5707 no longer accessible.</p></div>
5708 <div class="paragraph"><p>The finalizer is invoked as:</p></div>
5709 <div class="literalblock">
5710 <div class="content">
5711 <pre><code>finalizer reference string</code></pre>
5712 </div></div>
5713 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
5714 </div>
5715 <div class="sect2">
5716 <h3 id="_rename">rename</h3>
5717 <div class="paragraph"><p><code><strong>rename</strong> <em>oldName newName</em></code></p></div>
5718 <div class="paragraph"><p>Rename the command that used to be called <code><em>oldName</em></code> so that it
5719 is now called <code><em>newName</em></code>. If <code><em>newName</em></code> is an empty string
5720 (e.g. {}) then <code><em>oldName</em></code> is deleted. The <a href="#_rename"><strong><code>rename</code></strong></a> command
5721 returns an empty string as result.</p></div>
5722 </div>
5723 <div class="sect2">
5724 <h3 id="_return">return</h3>
5725 <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>
5726 <div class="paragraph"><p>Return immediately from the current procedure (or top-level command
5727 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>
5728 is not specified, an empty string will be returned as result.</p></div>
5729 <div class="paragraph"><p>If <code>-code</code> is specified (as either a number or ok, error, break,
5730 continue, signal, return or exit), this code will be used instead
5731 of <code>JIM_OK</code>. This is generally useful when implementing flow of control
5732 commands.</p></div>
5733 <div class="paragraph"><p>If <code>-level</code> is specified and greater than 1, it has the effect of delaying
5734 the new return code from <code>-code</code>. This is useful when rethrowing an error
5735 from <a href="#_catch"><strong><code>catch</code></strong></a>. See the implementation of try/catch in tclcompat.tcl for
5736 an example of how this is done.</p></div>
5737 <div class="paragraph"><p>Note: The following options are only used when <code>-code</code> is JIM_ERR.</p></div>
5738 <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>)
5739 it is used to initialize the stacktrace.</p></div>
5740 <div class="paragraph"><p>If <code>-errorcode</code> is specified, it is used to set the global variable $::errorCode.</p></div>
5741 </div>
5742 <div class="sect2">
5743 <h3 id="_scan">scan</h3>
5744 <div class="paragraph"><p><code><strong>scan</strong> <em>string format varName1 ?varName2 ...?</em></code></p></div>
5745 <div class="paragraph"><p>This command parses fields from an input string in the same fashion
5746 as the C <em>sscanf</em> procedure. <code><em>string</em></code> gives the input to be parsed
5747 and <code><em>format</em></code> indicates how to parse it, using <em>%</em> fields as in
5748 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5749 man page for details. Each <code><em>varName</em></code> gives the name of a variable;
5750 when a field is scanned from <code><em>string</em></code>, the result is converted back
5751 into a string and assigned to the corresponding <code><em>varName</em></code>. The
5752 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5753 character value is converted to a decimal string, which is then
5754 assigned to the corresponding <code><em>varName</em></code>; no field width may be
5755 specified for this conversion.</p></div>
5756 </div>
5757 <div class="sect2">
5758 <h3 id="_seek">seek</h3>
5759 <div class="paragraph"><p><code><strong>seek</strong> <em>fileId offset ?origin?</em></code></p></div>
5760 <div class="paragraph"><p><code><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></code></p></div>
5761 <div class="paragraph"><p>Change the current access position for <code><em>fileId</em></code>.
5762 The <code><em>offset</em></code> and <code><em>origin</em></code> arguments specify the position at
5763 which the next read or write will occur for <code><em>fileId</em></code>.
5764 <code><em>offset</em></code> must be a number (which may be negative) and <code><em>origin</em></code>
5765 must be one of the following:</p></div>
5766 <div class="dlist"><dl>
5767 <dt class="hdlist1">
5768 <code><strong>start</strong></code>
5769 </dt>
5770 <dd>
5772 The new access position will be <code><em>offset</em></code> bytes from the start
5773 of the file.
5774 </p>
5775 </dd>
5776 <dt class="hdlist1">
5777 <code><strong>current</strong></code>
5778 </dt>
5779 <dd>
5781 The new access position will be <code><em>offset</em></code> bytes from the current
5782 access position; a negative <code><em>offset</em></code> moves the access position
5783 backwards in the file.
5784 </p>
5785 </dd>
5786 <dt class="hdlist1">
5787 <code><strong>end</strong></code>
5788 </dt>
5789 <dd>
5791 The new access position will be <code><em>offset</em></code> bytes from the end of
5792 the file. A negative <code><em>offset</em></code> places the access position before
5793 the end-of-file, and a positive <code><em>offset</em></code> places the access position
5794 after the end-of-file.
5795 </p>
5796 </dd>
5797 </dl></div>
5798 <div class="paragraph"><p>The <code><em>origin</em></code> argument defaults to <code>start</code>.</p></div>
5799 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
5800 <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
5801 of the standard I/O channels.</p></div>
5802 <div class="paragraph"><p>This command returns an empty string.</p></div>
5803 </div>
5804 <div class="sect2">
5805 <h3 id="_set">set</h3>
5806 <div class="paragraph"><p><code><strong>set</strong> <em>varName ?value?</em></code></p></div>
5807 <div class="paragraph"><p>Returns the value of variable <code><em>varName</em></code>.</p></div>
5808 <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>,
5809 creating a new variable if one doesn&#8217;t already exist, and return
5810 its value.</p></div>
5811 <div class="paragraph"><p>If <code><em>varName</em></code> contains an open parenthesis and ends with a
5812 close parenthesis, then it refers to an array element: the characters
5813 before the open parenthesis are the name of the array, and the characters
5814 between the parentheses are the index within the array.
5815 Otherwise <code><em>varName</em></code> refers to a scalar variable.</p></div>
5816 <div class="paragraph"><p>If no procedure is active, then <code><em>varName</em></code> refers to a global
5817 variable.</p></div>
5818 <div class="paragraph"><p>If a procedure is active, then <code><em>varName</em></code> refers to a parameter
5819 or local variable of the procedure, unless the <code><em>global</em></code> command
5820 has been invoked to declare <code><em>varName</em></code> to be global.</p></div>
5821 <div class="paragraph"><p>The <code>::</code> prefix may also be used to explicitly reference a variable
5822 in the global scope.</p></div>
5823 </div>
5824 <div class="sect2">
5825 <h3 id="_setref">setref</h3>
5826 <div class="paragraph"><p><code><strong>setref</strong> <em>reference string</em></code></p></div>
5827 <div class="paragraph"><p>Store a new string in <code><em>reference</em></code>, replacing the existing string.
5828 The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
5829 command.</p></div>
5830 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
5831 </div>
5832 <div class="sect2">
5833 <h3 id="_signal">signal</h3>
5834 <div class="paragraph"><p>Command for signal handling.</p></div>
5835 <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>
5836 <div class="paragraph"><p>Commands which return a list of signal names do so using the canonical form:
5837 "<code>SIGINT SIGTERM</code>".</p></div>
5838 <div class="dlist"><dl>
5839 <dt class="hdlist1">
5840 <code><strong>signal handle</strong> ?<em>signals ...</em>?</code>
5841 </dt>
5842 <dd>
5844 If no signals are given, returns a list of all signals which are currently
5845 being handled.
5846 If signals are specified, these are added to the list of signals currently
5847 being handled.
5848 </p>
5849 </dd>
5850 <dt class="hdlist1">
5851 <code><strong>signal ignore</strong> ?<em>signals ...</em>?</code>
5852 </dt>
5853 <dd>
5855 If no signals are given, returns a lists all signals which are currently
5856 being ignored.
5857 If signals are specified, these are added to the list of signals
5858 currently being ignored. These signals are still delivered, but
5859 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
5860 <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to determine which signals have occurred but
5861 been ignored.
5862 </p>
5863 </dd>
5864 <dt class="hdlist1">
5865 <code><strong>signal default</strong> ?<em>signals ...</em>?</code>
5866 </dt>
5867 <dd>
5869 If no signals are given, returns a lists all signals which are currently have
5870 the default behaviour.
5871 If signals are specified, these are added to the list of signals which have
5872 the default behaviour.
5873 </p>
5874 </dd>
5875 <dt class="hdlist1">
5876 <code><strong>signal check ?-clear?</strong> ?<em>signals ...</em>?</code>
5877 </dt>
5878 <dd>
5880 Returns a list of signals which have been delivered to the process
5881 but are <em>ignored</em>. If signals are specified, only that set of signals will
5882 be checked, otherwise all signals will be checked.
5883 If <code>-clear</code> is specified, any signals returned are removed and will not be
5884 returned by subsequent calls to <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> unless delivered again.
5885 </p>
5886 </dd>
5887 <dt class="hdlist1">
5888 <code><strong>signal throw</strong> ?<em>signal</em>?</code>
5889 </dt>
5890 <dd>
5892 Raises the given signal, which defaults to <code>SIGINT</code> if not specified.
5893 The behaviour is identical to:
5894 </p>
5895 <div class="literalblock">
5896 <div class="content">
5897 <pre><code>kill signal [pid]</code></pre>
5898 </div></div>
5899 </dd>
5900 </dl></div>
5901 <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
5902 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>
5903 to immediately abort execution when the signal is delivered. Alternatively, <a href="#_signal"><strong><code>signal</code></strong></a> <code>ignore</code>
5904 is used in conjunction with <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to handle signal synchronously. Consider the
5905 two examples below.</p></div>
5906 <div class="paragraph"><p>Prevent a processing from taking too long</p></div>
5907 <div class="literalblock">
5908 <div class="content">
5909 <pre><code>signal handle SIGALRM
5910 alarm 20
5911 try -signal {
5912 .. possibly long running process ..
5913 alarm 0
5914 } on signal {sig} {
5915 puts stderr "Process took too long"
5916 }</code></pre>
5917 </div></div>
5918 <div class="paragraph"><p>Handle SIGHUP to reconfigure:</p></div>
5919 <div class="literalblock">
5920 <div class="content">
5921 <pre><code>signal ignore SIGHUP
5922 while {1} {
5923 ... handle configuration/reconfiguration ...
5924 while {[signal check -clear SIGHUP] eq ""} {
5925 ... do processing ..
5927 # Received SIGHUP, so reconfigure
5928 }</code></pre>
5929 </div></div>
5930 </div>
5931 <div class="sect2">
5932 <h3 id="_sleep">sleep</h3>
5933 <div class="paragraph"><p><code><strong>sleep</strong> <em>seconds</em></code></p></div>
5934 <div class="paragraph"><p>Pauses for the given number of seconds, which may be a floating
5935 point value less than one to sleep for less than a second, or an
5936 integer to sleep for one or more seconds.</p></div>
5937 </div>
5938 <div class="sect2">
5939 <h3 id="_source">source</h3>
5940 <div class="paragraph"><p><code><strong>source</strong> <em>fileName</em></code></p></div>
5941 <div class="paragraph"><p>Read file <code><em>fileName</em></code> and pass the contents to the Tcl interpreter
5942 as a sequence of commands to execute in the normal fashion. The return
5943 value of <a href="#_source"><strong><code>source</code></strong></a> is the return value of the last command executed
5944 from the file. If an error occurs in executing the contents of the
5945 file, then the <a href="#_source"><strong><code>source</code></strong></a> command will return that error.</p></div>
5946 <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
5947 the file will be skipped and the <a href="#_source"><strong><code>source</code></strong></a> command will return
5948 normally with the result from the <a href="#_return"><strong><code>return</code></strong></a> command.</p></div>
5949 </div>
5950 <div class="sect2">
5951 <h3 id="_split">split</h3>
5952 <div class="paragraph"><p><code><strong>split</strong> <em>string ?splitChars?</em></code></p></div>
5953 <div class="paragraph"><p>Returns a list created by splitting <code><em>string</em></code> at each character
5954 that is in the <code><em>splitChars</em></code> argument.</p></div>
5955 <div class="paragraph"><p>Each element of the result list will consist of the
5956 characters from <code><em>string</em></code> between instances of the
5957 characters in <code><em>splitChars</em></code>.</p></div>
5958 <div class="paragraph"><p>Empty list elements will be generated if <code><em>string</em></code> contains
5959 adjacent characters in <code><em>splitChars</em></code>, or if the first or last
5960 character of <code><em>string</em></code> is in <code><em>splitChars</em></code>.</p></div>
5961 <div class="paragraph"><p>If <code><em>splitChars</em></code> is an empty string then each character of
5962 <code><em>string</em></code> becomes a separate element of the result list.</p></div>
5963 <div class="paragraph"><p><code><em>splitChars</em></code> defaults to the standard white-space characters.
5964 For example,</p></div>
5965 <div class="literalblock">
5966 <div class="content">
5967 <pre><code>split "comp.unix.misc" .</code></pre>
5968 </div></div>
5969 <div class="paragraph"><p>returns <code><em>"comp unix misc"</em></code> and</p></div>
5970 <div class="literalblock">
5971 <div class="content">
5972 <pre><code>split "Hello world" {}</code></pre>
5973 </div></div>
5974 <div class="paragraph"><p>returns <code><em>"H e l l o { } w o r l d"</em></code>.</p></div>
5975 </div>
5976 <div class="sect2">
5977 <h3 id="_stackdump">stackdump</h3>
5978 <div class="paragraph"><p><code><strong>stackdump</strong> <em>stacktrace</em></code></p></div>
5979 <div class="paragraph"><p>Creates a human readable representation of a stack trace.</p></div>
5980 </div>
5981 <div class="sect2">
5982 <h3 id="_stacktrace">stacktrace</h3>
5983 <div class="paragraph"><p><code><strong>stacktrace</strong></code></p></div>
5984 <div class="paragraph"><p>Returns a live stack trace as a list of <code>proc file line proc file line ...</code>.
5985 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
5986 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>
5987 <div class="paragraph"><p>See also <a href="#_stackdump"><strong><code>stackdump</code></strong></a>.</p></div>
5988 </div>
5989 <div class="sect2">
5990 <h3 id="_string">string</h3>
5991 <div class="paragraph"><p><code><strong>string</strong> <em>option arg ?arg ...?</em></code></p></div>
5992 <div class="paragraph"><p>Perform one of several string operations, depending on <code><em>option</em></code>.
5993 The legal options (which may be abbreviated) are:</p></div>
5994 <div class="dlist"><dl>
5995 <dt class="hdlist1">
5996 <code><strong>string bytelength</strong> <em>string</em></code>
5997 </dt>
5998 <dd>
6000 Returns the length of the string in bytes. This will return
6001 the same value as <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> if UTF-8 support is not enabled,
6002 or if the string is composed entirely of ASCII characters.
6003 See UTF-8 AND UNICODE.
6004 </p>
6005 </dd>
6006 <dt class="hdlist1">
6007 <code><strong>string byterange</strong> <em>string first last</em></code>
6008 </dt>
6009 <dd>
6011 Like <a href="#_string"><strong><code>string</code></strong></a> <code>range</code> except works on bytes rather than characters.
6012 These commands are identical if UTF-8 support is not enabled.
6013 </p>
6014 </dd>
6015 <dt class="hdlist1">
6016 <code><strong>string cat</strong> <em>?string1 string2 ...?</em></code>
6017 </dt>
6018 <dd>
6020 Concatenates the given strings into a single string.
6021 </p>
6022 </dd>
6023 <dt class="hdlist1">
6024 <code><strong>string compare ?-nocase?</strong> ?<strong>-length</strong> <em>len? string1 string2</em></code>
6025 </dt>
6026 <dd>
6028 Perform a character-by-character comparison of strings <code><em>string1</em></code> and
6029 <code><em>string2</em></code> in the same way as the C <em>strcmp</em> procedure. Return
6030 -1, 0, or 1, depending on whether <code><em>string1</em></code> is lexicographically
6031 less than, equal to, or greater than <code><em>string2</em></code>. If <code>-length</code>
6032 is specified, then only the first <code><em>len</em></code> characters are used
6033 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
6034 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6035 </p>
6036 </dd>
6037 <dt class="hdlist1">
6038 <code><strong>string equal ?-nocase?</strong> <em>?<strong>-length</strong> len?</em> <em>string1 string2</em></code>
6039 </dt>
6040 <dd>
6042 Returns 1 if the strings are equal, or 0 otherwise. If <code>-length</code>
6043 is specified, then only the first <code><em>len</em></code> characters are used
6044 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
6045 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6046 </p>
6047 </dd>
6048 <dt class="hdlist1">
6049 <code><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></code>
6050 </dt>
6051 <dd>
6053 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6054 the characters in <code><em>string1</em></code>. If found, return the index of the
6055 first character in the first such match within <code><em>string2</em></code>. If not
6056 found, return -1. If <code><em>firstIndex</em></code> is specified, matching will start
6057 from <code><em>firstIndex</em></code> of <code><em>string1</em></code>.
6058 </p>
6059 </dd>
6060 <dt class="hdlist1">
6062 </dt>
6063 <dd>
6065 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>firstIndex</em></code>.
6066 </p>
6067 </dd>
6068 <dt class="hdlist1">
6069 <code><strong>string index</strong> <em>string charIndex</em></code>
6070 </dt>
6071 <dd>
6073 Returns the <code><em>charIndex</em></code><em>th character of the <code>'string</em></code>
6074 argument. A <code><em>charIndex</em></code> of 0 corresponds to the first
6075 character of the string.
6076 If <code><em>charIndex</em></code> is less than 0 or greater than
6077 or equal to the length of the string then an empty string is
6078 returned.
6079 </p>
6080 </dd>
6081 <dt class="hdlist1">
6083 </dt>
6084 <dd>
6086 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>charIndex</em></code>.
6087 </p>
6088 </dd>
6089 <dt class="hdlist1">
6090 <code><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></code>
6091 </dt>
6092 <dd>
6094 Returns 1 if <code><em>string</em></code> is a valid member of the specified character
6095 class, otherwise returns 0. If <code>-strict</code> is specified, then an
6096 empty string returns 0, otherwise an empty string will return 1
6097 on any class. The following character classes are recognized
6098 (the class name can be abbreviated):
6099 </p>
6100 </dd>
6101 <dt class="hdlist1">
6103 </dt>
6104 <dd>
6105 <div class="dlist"><dl>
6106 <dt class="hdlist1">
6107 <code>alnum</code>
6108 </dt>
6109 <dd>
6111 Any alphabet or digit character.
6112 </p>
6113 </dd>
6114 <dt class="hdlist1">
6115 <code>alpha</code>
6116 </dt>
6117 <dd>
6119 Any alphabet character.
6120 </p>
6121 </dd>
6122 <dt class="hdlist1">
6123 <code>ascii</code>
6124 </dt>
6125 <dd>
6127 Any character with a value less than 128 (those that are in the 7-bit ascii range).
6128 </p>
6129 </dd>
6130 <dt class="hdlist1">
6131 <code>boolean</code>
6132 </dt>
6133 <dd>
6135 Any of the valid string formats for a boolean value in Tcl (0, false, no, off, 1, true, yes, on)
6136 </p>
6137 </dd>
6138 <dt class="hdlist1">
6139 <code>control</code>
6140 </dt>
6141 <dd>
6143 Any control character.
6144 </p>
6145 </dd>
6146 <dt class="hdlist1">
6147 <code>digit</code>
6148 </dt>
6149 <dd>
6151 Any digit character.
6152 </p>
6153 </dd>
6154 <dt class="hdlist1">
6155 <code>double</code>
6156 </dt>
6157 <dd>
6159 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
6160 In case of under/overflow in the value, 0 is returned.
6161 </p>
6162 </dd>
6163 <dt class="hdlist1">
6164 <code>graph</code>
6165 </dt>
6166 <dd>
6168 Any printing character, except space.
6169 </p>
6170 </dd>
6171 <dt class="hdlist1">
6172 <code>integer</code>
6173 </dt>
6174 <dd>
6176 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
6177 </p>
6178 </dd>
6179 <dt class="hdlist1">
6180 <code>lower</code>
6181 </dt>
6182 <dd>
6184 Any lower case alphabet character.
6185 </p>
6186 </dd>
6187 <dt class="hdlist1">
6188 <code>print</code>
6189 </dt>
6190 <dd>
6192 Any printing character, including space.
6193 </p>
6194 </dd>
6195 <dt class="hdlist1">
6196 <code>punct</code>
6197 </dt>
6198 <dd>
6200 Any punctuation character.
6201 </p>
6202 </dd>
6203 <dt class="hdlist1">
6204 <code>space</code>
6205 </dt>
6206 <dd>
6208 Any space character.
6209 </p>
6210 </dd>
6211 <dt class="hdlist1">
6212 <code>upper</code>
6213 </dt>
6214 <dd>
6216 Any upper case alphabet character.
6217 </p>
6218 </dd>
6219 <dt class="hdlist1">
6220 <code>xdigit</code>
6221 </dt>
6222 <dd>
6224 Any hexadecimal digit character ([0-9A-Fa-f]).
6225 </p>
6226 </dd>
6227 </dl></div>
6228 </dd>
6229 <dt class="hdlist1">
6231 </dt>
6232 <dd>
6234 Note that string classification does <code><em>not</em></code> respect UTF-8. See UTF-8 AND UNICODE
6235 </p>
6236 </dd>
6237 <dt class="hdlist1">
6239 </dt>
6240 <dd>
6242 Note that only <code><em>lowercase</em></code> boolean values are recognized (Tcl accepts any case).
6243 </p>
6244 </dd>
6245 <dt class="hdlist1">
6246 <code><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></code>
6247 </dt>
6248 <dd>
6250 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6251 the characters in <code><em>string1</em></code>. If found, return the index of the
6252 first character in the last such match within <code><em>string2</em></code>. If there
6253 is no match, then return -1. If <code><em>lastIndex</em></code> is specified, only characters
6254 up to <code><em>lastIndex</em></code> of <code><em>string2</em></code> will be considered in the match.
6255 </p>
6256 </dd>
6257 <dt class="hdlist1">
6259 </dt>
6260 <dd>
6262 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>lastIndex</em></code>.
6263 </p>
6264 </dd>
6265 <dt class="hdlist1">
6266 <code><strong>string length</strong> <em>string</em></code>
6267 </dt>
6268 <dd>
6270 Returns a decimal string giving the number of characters in <code><em>string</em></code>.
6271 If UTF-8 support is enabled, this may be different than the number of bytes.
6272 See UTF-8 AND UNICODE
6273 </p>
6274 </dd>
6275 <dt class="hdlist1">
6276 <code><strong>string map ?-nocase?</strong> <em>mapping string</em></code>
6277 </dt>
6278 <dd>
6280 Replaces substrings in <code><em>string</em></code> based on the key-value pairs in
6281 <code><em>mapping</em></code>, which is a list of <code>key value key value ...</code> as in the form
6282 returned by <a href="#_array"><strong><code>array</code></strong></a> <code>get</code>. Each instance of a key in the string will be
6283 replaced with its corresponding value. If <code>-nocase</code> is specified, then
6284 matching is done without regard to case differences. Both key and value may
6285 be multiple characters. Replacement is done in an ordered manner, so the
6286 key appearing first in the list will be checked first, and so on. <code><em>string</em></code> is
6287 only iterated over once, so earlier key replacements will have no affect for
6288 later key matches. For example,
6289 </p>
6290 <div class="literalblock">
6291 <div class="content">
6292 <pre><code>string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc</code></pre>
6293 </div></div>
6294 </dd>
6295 <dt class="hdlist1">
6297 </dt>
6298 <dd>
6300 will return the string <code>01321221</code>.
6301 </p>
6302 </dd>
6303 <dt class="hdlist1">
6305 </dt>
6306 <dd>
6308 Note that if an earlier key is a prefix of a later one, it will completely mask the later
6309 one. So if the previous example is reordered like this,
6310 </p>
6311 <div class="literalblock">
6312 <div class="content">
6313 <pre><code>string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc</code></pre>
6314 </div></div>
6315 </dd>
6316 <dt class="hdlist1">
6318 </dt>
6319 <dd>
6321 it will return the string <code>02c322c222c</code>.
6322 </p>
6323 </dd>
6324 <dt class="hdlist1">
6325 <code><strong>string match ?-nocase?</strong> <em>pattern string</em></code>
6326 </dt>
6327 <dd>
6329 See if <code><em>pattern</em></code> matches <code><em>string</em></code>; return 1 if it does, 0
6330 if it doesn&#8217;t. Matching is done in a fashion similar to that
6331 used by the C-shell. For the two strings to match, their contents
6332 must be identical except that the following special sequences
6333 may appear in <code><em>pattern</em></code>:
6334 </p>
6335 <div class="dlist"><dl>
6336 <dt class="hdlist1">
6337 <code>*</code>
6338 </dt>
6339 <dd>
6341 Matches any sequence of characters in <code><em>string</em></code>,
6342 including a null string.
6343 </p>
6344 </dd>
6345 <dt class="hdlist1">
6346 <code>?</code>
6347 </dt>
6348 <dd>
6350 Matches any single character in <code><em>string</em></code>.
6351 </p>
6352 </dd>
6353 <dt class="hdlist1">
6354 <code>[<em>chars</em>]</code>
6355 </dt>
6356 <dd>
6358 Matches any character in the set given by <code><em>chars</em></code>.
6359 If a sequence of the form <code><em>x-y</em></code> appears in <code><em>chars</em></code>,
6360 then any character between <code><em>x</em></code> and <code><em>y</em></code>, inclusive,
6361 will match.
6362 </p>
6363 </dd>
6364 <dt class="hdlist1">
6365 <code>\x</code>
6366 </dt>
6367 <dd>
6369 Matches the single character <code><em>x</em></code>. This provides a way of
6370 avoiding the special interpretation of the characters <code>\*?[]</code>
6371 in <code><em>pattern</em></code>.
6372 </p>
6373 </dd>
6374 </dl></div>
6375 </dd>
6376 <dt class="hdlist1">
6378 </dt>
6379 <dd>
6381 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6382 </p>
6383 </dd>
6384 <dt class="hdlist1">
6385 <code><strong>string range</strong> <em>string first last</em></code>
6386 </dt>
6387 <dd>
6389 Returns a range of consecutive characters from <code><em>string</em></code>, starting
6390 with the character whose index is <code><em>first</em></code> and ending with the
6391 character whose index is <code><em>last</em></code>. An index of 0 refers to the
6392 first character of the string.
6393 </p>
6394 </dd>
6395 <dt class="hdlist1">
6397 </dt>
6398 <dd>
6400 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.
6401 </p>
6402 </dd>
6403 <dt class="hdlist1">
6405 </dt>
6406 <dd>
6408 If <code><em>first</em></code> is less than zero then it is treated as if it were zero, and
6409 if <code><em>last</em></code> is greater than or equal to the length of the string then
6410 it is treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than
6411 <code><em>last</em></code> then an empty string is returned.
6412 </p>
6413 </dd>
6414 <dt class="hdlist1">
6415 <code><strong>string repeat</strong> <em>string count</em></code>
6416 </dt>
6417 <dd>
6419 Returns a new string consisting of <code><em>string</em></code> repeated <code><em>count</em></code> times.
6420 </p>
6421 </dd>
6422 <dt class="hdlist1">
6423 <code><strong>string replace</strong> <em>string first last ?newstring?</em></code>
6424 </dt>
6425 <dd>
6427 Removes a range of consecutive characters from <code><em>string</em></code>, starting
6428 with the character whose index is <code><em>first</em></code> and ending with the
6429 character whose index is <code><em>last</em></code>. If <code><em>newstring</em></code> is specified,
6430 then it is placed in the removed character range. If <code><em>first</em></code> is
6431 less than zero then it is treated as if it were zero, and if <code><em>last</em></code>
6432 is greater than or equal to the length of the string then it is
6433 treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than <code><em>last</em></code>
6434 or the length of the initial string, or <code><em>last</em></code> is less than 0,
6435 then the initial string is returned untouched.
6436 </p>
6437 </dd>
6438 <dt class="hdlist1">
6439 <code><strong>string reverse</strong> <em>string</em></code>
6440 </dt>
6441 <dd>
6443 Returns a string that is the same length as <code><em>string</em></code> but
6444 with its characters in the reverse order.
6445 </p>
6446 </dd>
6447 <dt class="hdlist1">
6448 <code><strong>string tolower</strong> <em>string</em></code>
6449 </dt>
6450 <dd>
6452 Returns a value equal to <code><em>string</em></code> except that all upper case
6453 letters have been converted to lower case.
6454 </p>
6455 </dd>
6456 <dt class="hdlist1">
6457 <code><strong>string totitle</strong> <em>string</em></code>
6458 </dt>
6459 <dd>
6461 Returns a value equal to <code><em>string</em></code> except that the first character
6462 is converted to title case (or upper case if there is no UTF-8 titlecase variant)
6463 and all remaining characters have been converted to lower case.
6464 </p>
6465 </dd>
6466 <dt class="hdlist1">
6467 <code><strong>string toupper</strong> <em>string</em></code>
6468 </dt>
6469 <dd>
6471 Returns a value equal to <code><em>string</em></code> except that all lower case
6472 letters have been converted to upper case.
6473 </p>
6474 </dd>
6475 <dt class="hdlist1">
6476 <code><strong>string trim</strong> <em>string ?chars?</em></code>
6477 </dt>
6478 <dd>
6480 Returns a value equal to <code><em>string</em></code> except that any leading
6481 or trailing characters from the set given by <code><em>chars</em></code> are
6482 removed.
6483 If <code><em>chars</em></code> is not specified then white space is removed
6484 (spaces, tabs, newlines, and carriage returns).
6485 </p>
6486 </dd>
6487 <dt class="hdlist1">
6488 <code><strong>string trimleft</strong> <em>string ?chars?</em></code>
6489 </dt>
6490 <dd>
6492 Returns a value equal to <code><em>string</em></code> except that any
6493 leading characters from the set given by <code><em>chars</em></code> are
6494 removed.
6495 If <code><em>chars</em></code> is not specified then white space is removed
6496 (spaces, tabs, newlines, and carriage returns).
6497 </p>
6498 </dd>
6499 <dt class="hdlist1">
6500 <code><strong>string trimright</strong> <em>string ?chars?</em></code>
6501 </dt>
6502 <dd>
6504 Returns a value equal to <code><em>string</em></code> except that any
6505 trailing characters from the set given by <code><em>chars</em></code> are
6506 removed.
6507 If <code><em>chars</em></code> is not specified then white space is removed
6508 (spaces, tabs, newlines, and carriage returns).
6509 Null characters are always removed.
6510 </p>
6511 </dd>
6512 </dl></div>
6513 </div>
6514 <div class="sect2">
6515 <h3 id="_subst">subst</h3>
6516 <div class="paragraph"><p><code><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></code></p></div>
6517 <div class="paragraph"><p>This command performs variable substitutions, command substitutions,
6518 and backslash substitutions on its string argument and returns the
6519 fully-substituted result. The substitutions are performed in exactly
6520 the same way as for Tcl commands. As a result, the string argument
6521 is actually substituted twice, once by the Tcl parser in the usual
6522 fashion for Tcl commands, and again by the subst command.</p></div>
6523 <div class="paragraph"><p>If any of the <code>-nobackslashes</code>, <code>-nocommands</code>, or <code>-novariables</code> are
6524 specified, then the corresponding substitutions are not performed.
6525 For example, if <code>-nocommands</code> is specified, no command substitution
6526 is performed: open and close brackets are treated as ordinary
6527 characters with no special interpretation.</p></div>
6528 <div class="paragraph"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
6529 special treatment to double quotes or curly braces. For example,
6530 the following script returns <code>xyz {44}</code>, not <code>xyz {$a}</code>.</p></div>
6531 <div class="literalblock">
6532 <div class="content">
6533 <pre><code>set a 44
6534 subst {xyz {$a}}</code></pre>
6535 </div></div>
6536 </div>
6537 <div class="sect2">
6538 <h3 id="_switch">switch</h3>
6539 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string pattern body ?pattern body ...?</em></code></p></div>
6540 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string {pattern body ?pattern body ...?}</em></code></p></div>
6541 <div class="paragraph"><p>The <a href="#_switch"><strong><code>switch</code></strong></a> command matches its string argument against each of
6542 the pattern arguments in order. As soon as it finds a pattern that
6543 matches string it evaluates the following body and returns the
6544 result of that evaluation. If the last pattern argument is default
6545 then it matches anything. If no pattern argument matches string and
6546 no default is given, then the <a href="#_switch"><strong><code>switch</code></strong></a> command returns an empty string.
6547 If the initial arguments to switch start with - then they are treated
6548 as options. The following options are currently supported:</p></div>
6549 <div class="dlist"><dl>
6550 <dt class="hdlist1">
6551 <code>-exact</code>
6552 </dt>
6553 <dd>
6555 Use exact matching when comparing string to a
6556 pattern. This is the default.
6557 </p>
6558 </dd>
6559 <dt class="hdlist1">
6560 <code>-glob</code>
6561 </dt>
6562 <dd>
6564 When matching string to the patterns, use glob-style
6565 matching (i.e. the same as implemented by the string
6566 match command).
6567 </p>
6568 </dd>
6569 <dt class="hdlist1">
6570 <code>-regexp</code>
6571 </dt>
6572 <dd>
6574 When matching string to the patterns, use regular
6575 expression matching (i.e. the same as implemented
6576 by the regexp command).
6577 </p>
6578 </dd>
6579 <dt class="hdlist1">
6580 <code>-command <em>commandname</em></code>
6581 </dt>
6582 <dd>
6584 When matching string to the patterns, use the given command, which
6585 must be a single word. The command is invoked as
6586 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
6587 and must return 1 if matched, or 0 if not.
6588 </p>
6589 </dd>
6590 <dt class="hdlist1">
6591 <code>--</code>
6592 </dt>
6593 <dd>
6595 Marks the end of options. The argument following
6596 this one will be treated as string even if it starts
6597 with a <code>-</code>.
6598 </p>
6599 </dd>
6600 </dl></div>
6601 <div class="paragraph"><p>Two syntaxes are provided for the pattern and body arguments. The
6602 first uses a separate argument for each of the patterns and commands;
6603 this form is convenient if substitutions are desired on some of the
6604 patterns or commands. The second form places all of the patterns
6605 and commands together into a single argument; the argument must
6606 have proper list structure, with the elements of the list being the
6607 patterns and commands. The second form makes it easy to construct
6608 multi-line <a href="#_switch"><strong><code>switch</code></strong></a> commands, since the braces around the whole list
6609 make it unnecessary to include a backslash at the end of each line.
6610 Since the pattern arguments are in braces in the second form, no
6611 command or variable substitutions are performed on them; this makes
6612 the behaviour of the second form different than the first form in
6613 some cases.</p></div>
6614 <div class="paragraph"><p>If a body is specified as <code>-</code> it means that the body for the next
6615 pattern should also be used as the body for this pattern (if the
6616 next pattern also has a body of <code>-</code> then the body after that is
6617 used, and so on). This feature makes it possible to share a single
6618 body among several patterns.</p></div>
6619 <div class="paragraph"><p>Below are some examples of <a href="#_switch"><strong><code>switch</code></strong></a> commands:</p></div>
6620 <div class="literalblock">
6621 <div class="content">
6622 <pre><code>switch abc a - b {format 1} abc {format 2} default {format 3}</code></pre>
6623 </div></div>
6624 <div class="paragraph"><p>will return 2,</p></div>
6625 <div class="literalblock">
6626 <div class="content">
6627 <pre><code>switch -regexp aaab {
6628 ^a.*b$ -
6629 b {format 1}
6630 a* {format 2}
6631 default {format 3}
6632 }</code></pre>
6633 </div></div>
6634 <div class="paragraph"><p>will return 1, and</p></div>
6635 <div class="literalblock">
6636 <div class="content">
6637 <pre><code>switch xyz {
6639 b {format 1}
6640 a* {format 2}
6641 default {format 3}
6642 }</code></pre>
6643 </div></div>
6644 <div class="paragraph"><p>will return 3.</p></div>
6645 </div>
6646 <div class="sect2">
6647 <h3 id="_tailcall">tailcall</h3>
6648 <div class="paragraph"><p><code><strong>tailcall</strong> <em>cmd ?arg...?</em></code></p></div>
6649 <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
6650 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
6651 <div class="paragraph"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
6652 <div class="literalblock">
6653 <div class="content">
6654 <pre><code>tailcall a b c</code></pre>
6655 </div></div>
6656 <div class="literalblock">
6657 <div class="content">
6658 <pre><code>return [uplevel 1 [list a b c]]</code></pre>
6659 </div></div>
6660 <div class="paragraph"><p><a href="#_tailcall"><strong><code>tailcall</code></strong></a> is useful as a dispatch mechanism:</p></div>
6661 <div class="literalblock">
6662 <div class="content">
6663 <pre><code>proc a {cmd args} {
6664 tailcall sub_$cmd {*}$args
6666 proc sub_cmd1 ...
6667 proc sub_cmd2 ...</code></pre>
6668 </div></div>
6669 </div>
6670 <div class="sect2">
6671 <h3 id="_tell">tell</h3>
6672 <div class="paragraph"><p><code><strong>tell</strong> <em>fileId</em></code></p></div>
6673 <div class="paragraph"><p><code><em>fileId</em> <strong>tell</strong></code></p></div>
6674 <div class="paragraph"><p>Returns a decimal string giving the current access position in
6675 <code><em>fileId</em></code>.</p></div>
6676 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
6677 <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
6678 of the standard I/O channels.</p></div>
6679 </div>
6680 <div class="sect2">
6681 <h3 id="_throw">throw</h3>
6682 <div class="paragraph"><p><code><strong>throw</strong> <em>code ?msg?</em></code></p></div>
6683 <div class="paragraph"><p>This command throws an exception (return) code along with an optional message.
6684 This command is mostly for convenient usage with <a href="#_try"><strong><code>try</code></strong></a>.</p></div>
6685 <div class="paragraph"><p>The command <code>throw break</code> is equivalent to <code>break</code>.
6686 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>
6687 </div>
6688 <div class="sect2">
6689 <h3 id="_time">time</h3>
6690 <div class="paragraph"><p><code><strong>time</strong> <em>command ?count?</em></code></p></div>
6691 <div class="paragraph"><p>This command will call the Tcl interpreter <code><em>count</em></code>
6692 times to execute <code><em>command</em></code> (or once if <code><em>count</em></code> isn&#8217;t
6693 specified). It will then return a string of the form</p></div>
6694 <div class="literalblock">
6695 <div class="content">
6696 <pre><code>503 microseconds per iteration</code></pre>
6697 </div></div>
6698 <div class="paragraph"><p>which indicates the average amount of time required per iteration,
6699 in microseconds.</p></div>
6700 <div class="paragraph"><p>Time is measured in elapsed time, not CPU time.</p></div>
6701 </div>
6702 <div class="sect2">
6703 <h3 id="_try">try</h3>
6704 <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>
6705 <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>
6706 <div class="paragraph"><p>This interpeter first evaluates <code><em>tryscript</em></code> under the effect of the catch
6707 options <code><em>catchopts</em></code> (e.g. <code>-signal -noexit --</code>, see <a href="#_catch"><strong><code>catch</code></strong></a>).</p></div>
6708 <div class="paragraph"><p>It then evaluates the script for the first matching <em>on</em> handler
6709 (there many be zero or more) based on the return code from the <a href="#_try"><strong><code>try</code></strong></a>
6710 section. For example a normal <code>JIM_ERR</code> error will be matched by
6711 an <em>on error</em> handler.</p></div>
6712 <div class="paragraph"><p>Finally, any <code><em>finalscript</em></code> is evaluated.</p></div>
6713 <div class="paragraph"><p>The result of this command is the result of <code><em>tryscript</em></code>, except in the
6714 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
6715 in which case the result is this new exception.</p></div>
6716 <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.)
6717 or as integers.</p></div>
6718 <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
6719 the matching handler.</p></div>
6720 <div class="paragraph"><p>For example:</p></div>
6721 <div class="literalblock">
6722 <div class="content">
6723 <pre><code>set f [open input]
6724 try -signal {
6725 process $f
6726 } on {continue break} {} {
6727 error "Unexpected break/continue"
6728 } on error {msg opts} {
6729 puts "Dealing with error"
6730 return {*}$opts $msg
6731 } on signal sig {
6732 puts "Got signal: $sig"
6733 } finally {
6734 $f close
6735 }</code></pre>
6736 </div></div>
6737 <div class="paragraph"><p>If break, continue or error are raised, they are dealt with by the matching
6738 handler.</p></div>
6739 <div class="paragraph"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6740 <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>
6741 </div>
6742 <div class="sect2">
6743 <h3 id="_unknown">unknown</h3>
6744 <div class="paragraph"><p><code><strong>unknown</strong> <em>cmdName ?arg arg &#8230;?</em></code></p></div>
6745 <div class="paragraph"><p>This command doesn&#8217;t actually exist as part of Tcl, but Tcl will
6746 invoke it if it does exist.</p></div>
6747 <div class="paragraph"><p>If the Tcl interpreter encounters a command name for which there
6748 is not a defined command, then Tcl checks for the existence of
6749 a command named <a href="#_unknown"><strong><code>unknown</code></strong></a>.</p></div>
6750 <div class="paragraph"><p>If there is no such command, then the interpreter returns an
6751 error.</p></div>
6752 <div class="paragraph"><p>If the <a href="#_unknown"><strong><code>unknown</code></strong></a> command exists, then it is invoked with
6753 arguments consisting of the fully-substituted name and arguments
6754 for the original non-existent command.</p></div>
6755 <div class="paragraph"><p>The <a href="#_unknown"><strong><code>unknown</code></strong></a> command typically does things like searching
6756 through library directories for a command procedure with the name
6757 <code><em>cmdName</em></code>, or expanding abbreviated command names to full-length,
6758 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6759 <div class="paragraph"><p>In some cases (such as expanding abbreviations) <a href="#_unknown"><strong><code>unknown</code></strong></a> will
6760 change the original command slightly and then (re-)execute it.
6761 The result of the <a href="#_unknown"><strong><code>unknown</code></strong></a> command is used as the result for
6762 the original non-existent command.</p></div>
6763 </div>
6764 <div class="sect2">
6765 <h3 id="_unset">unset</h3>
6766 <div class="paragraph"><p><code><strong>unset ?-nocomplain? ?--?</strong> <em>?name name &#8230;?</em></code></p></div>
6767 <div class="paragraph"><p>Remove variables.
6768 Each <code><em>name</em></code> is a variable name, specified in any of the
6769 ways acceptable to the <a href="#_set"><strong><code>set</code></strong></a> command.</p></div>
6770 <div class="paragraph"><p>If a <code><em>name</em></code> refers to an element of an array, then that
6771 element is removed without affecting the rest of the array.</p></div>
6772 <div class="paragraph"><p>If a <code><em>name</em></code> consists of an array name with no parenthesized
6773 index, then the entire array is deleted.</p></div>
6774 <div class="paragraph"><p>The <a href="#_unset"><strong><code>unset</code></strong></a> command returns an empty string as result.</p></div>
6775 <div class="paragraph"><p>An error occurs if any of the variables doesn&#8217;t exist, unless <em>-nocomplain</em>
6776 is specified. The <em>--</em> argument may be specified to stop option processing
6777 in case the variable name may be <em>-nocomplain</em>.</p></div>
6778 </div>
6779 <div class="sect2">
6780 <h3 id="_upcall">upcall</h3>
6781 <div class="paragraph"><p><code><strong>upcall</strong> <em>command ?args &#8230;?</em></code></p></div>
6782 <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
6783 the previous, hidden version of the same command.</p></div>
6784 <div class="paragraph"><p>If there is no previous definition of the command, an error is returned.</p></div>
6785 </div>
6786 <div class="sect2">
6787 <h3 id="_uplevel">uplevel</h3>
6788 <div class="paragraph"><p><code><strong>uplevel</strong> <em>?level? command ?command &#8230;?</em></code></p></div>
6789 <div class="paragraph"><p>All of the <code><em>command</em></code> arguments are concatenated as if they had
6790 been passed to <a href="#_concat"><strong><code>concat</code></strong></a>; the result is then evaluated in the
6791 variable context indicated by <code><em>level</em></code>. <a href="#_uplevel"><strong><code>uplevel</code></strong></a> returns
6792 the result of that evaluation. If <code><em>level</em></code> is an integer, then
6793 it gives a distance (up the procedure calling stack) to move before
6794 executing the command. If <code><em>level</em></code> consists of <code>#</code> followed by
6795 a number then the number gives an absolute level number. If <code><em>level</em></code>
6796 is omitted then it defaults to <code>1</code>. <code><em>level</em></code> cannot be
6797 defaulted if the first <code><em>command</em></code> argument starts with a digit or <code>#</code>.</p></div>
6798 <div class="paragraph"><p>For example, suppose that procedure <em>a</em> was invoked
6799 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6800 Suppose that <em>c</em> invokes the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command. If <code><em>level</em></code>
6801 is <code>1</code> or <code>#2</code> or omitted, then the command will be executed
6802 in the variable context of <em>b</em>. If <code><em>level</em></code> is <code>2</code> or <code>#1</code>
6803 then the command will be executed in the variable context of <em>a</em>.</p></div>
6804 <div class="paragraph"><p>If <code><em>level</em></code> is <em>3</em> or <code>#0</code> then the command will be executed
6805 at top-level (only global variables will be visible).
6806 The <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command causes the invoking procedure to disappear
6807 from the procedure calling stack while the command is being executed.
6808 In the above example, suppose <em>c</em> invokes the command</p></div>
6809 <div class="literalblock">
6810 <div class="content">
6811 <pre><code>uplevel 1 {set x 43; d}</code></pre>
6812 </div></div>
6813 <div class="paragraph"><p>where <em>d</em> is another Tcl procedure. The <a href="#_set"><strong><code>set</code></strong></a> command will
6814 modify the variable <em>x</em> in <em>b&#8217;s context, and 'd</em> will execute
6815 at level 3, as if called from <em>b</em>. If it in turn executes
6816 the command</p></div>
6817 <div class="literalblock">
6818 <div class="content">
6819 <pre><code>uplevel {set x 42}</code></pre>
6820 </div></div>
6821 <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&#8217;s
6822 context: the procedure 'c</em> does not appear to be on the call stack
6823 when <em>d</em> is executing. The command <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> may
6824 be used to obtain the level of the current procedure.</p></div>
6825 <div class="paragraph"><p><a href="#_uplevel"><strong><code>uplevel</code></strong></a> makes it possible to implement new control
6826 constructs as Tcl procedures (for example, <a href="#_uplevel"><strong><code>uplevel</code></strong></a> could
6827 be used to implement the <a href="#_while"><strong><code>while</code></strong></a> construct as a Tcl procedure).</p></div>
6828 </div>
6829 <div class="sect2">
6830 <h3 id="_upvar">upvar</h3>
6831 <div class="paragraph"><p><code><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar &#8230;?</em></code></p></div>
6832 <div class="paragraph"><p>This command arranges for one or more local variables in the current
6833 procedure to refer to variables in an enclosing procedure call or
6834 to global variables.</p></div>
6835 <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>
6836 command, and may be omitted if the first letter of the first <code><em>otherVar</em></code>
6837 isn&#8217;t <code>#</code> or a digit (it defaults to <em>1</em>).</p></div>
6838 <div class="paragraph"><p>For each <code><em>otherVar</em></code> argument, <a href="#_upvar"><strong><code>upvar</code></strong></a> makes the variable
6839 by that name in the procedure frame given by <code><em>level</em></code> (or at
6840 global level, if <code><em>level</em></code> is <code>#0</code>) accessible
6841 in the current procedure by the name given in the corresponding
6842 <code><em>myVar</em></code> argument.</p></div>
6843 <div class="paragraph"><p>The variable named by <code><em>otherVar</em></code> need not exist at the time of the
6844 call; it will be created the first time <code><em>myVar</em></code> is referenced, just like
6845 an ordinary variable.</p></div>
6846 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> may only be invoked from within procedures.</p></div>
6847 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> returns an empty string.</p></div>
6848 <div class="paragraph"><p>The <a href="#_upvar"><strong><code>upvar</code></strong></a> command simplifies the implementation of call-by-name
6849 procedure calling and also makes it easier to build new control constructs
6850 as Tcl procedures.
6851 For example, consider the following procedure:</p></div>
6852 <div class="literalblock">
6853 <div class="content">
6854 <pre><code>proc add2 name {
6855 upvar $name x
6856 set x [expr $x+2]
6857 }</code></pre>
6858 </div></div>
6859 <div class="paragraph"><p><em>add2</em> is invoked with an argument giving the name of a variable,
6860 and it adds two to the value of that variable.
6861 Although <em>add2</em> could have been implemented using <a href="#_uplevel"><strong><code>uplevel</code></strong></a>
6862 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>
6863 to access the variable in the caller&#8217;s procedure frame.</p></div>
6864 </div>
6865 <div class="sect2">
6866 <h3 id="_while">while</h3>
6867 <div class="paragraph"><p><code><strong>while</strong> <em>test body</em></code></p></div>
6868 <div class="paragraph"><p>The <code><em>while</em></code> command evaluates <code><em>test</em></code> as an expression
6869 (in the same way that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument).
6870 The value of the expression must be numeric; if it is non-zero
6871 then <code><em>body</em></code> is executed by passing it to the Tcl interpreter.</p></div>
6872 <div class="paragraph"><p>Once <code><em>body</em></code> has been executed then <code><em>test</em></code> is evaluated
6873 again, and the process repeats until eventually <code><em>test</em></code>
6874 evaluates to a zero numeric value. <a href="#_continue"><strong><code>continue</code></strong></a>
6875 commands may be executed inside <code><em>body</em></code> to terminate the current
6876 iteration of the loop, and <a href="#_break"><strong><code>break</code></strong></a>
6877 commands may be executed inside <code><em>body</em></code> to cause immediate
6878 termination of the <a href="#_while"><strong><code>while</code></strong></a> command.</p></div>
6879 <div class="paragraph"><p>The <a href="#_while"><strong><code>while</code></strong></a> command always returns an empty string.</p></div>
6880 </div>
6881 </div>
6882 </div>
6883 <div class="sect1">
6884 <h2 id="_optional_extensions">OPTIONAL-EXTENSIONS</h2>
6885 <div class="sectionbody">
6886 <div class="paragraph"><p>The following extensions may or may not be available depending upon
6887 what options were selected when Jim Tcl was built.</p></div>
6888 <div class="sect2">
6889 <h3 id="cmd_1">posix: os.fork, os.wait, os.gethostname, os.getids, os.uptime</h3>
6890 <div class="dlist"><dl>
6891 <dt class="hdlist1">
6892 <code><strong>os.fork</strong></code>
6893 </dt>
6894 <dd>
6896 Invokes <em>fork(2)</em> and returns the result.
6897 </p>
6898 </dd>
6899 <dt class="hdlist1">
6900 <code><strong>os.wait -nohang</strong> <em>pid</em></code>
6901 </dt>
6902 <dd>
6904 Invokes waitpid(2), with WNOHANG if <code>-nohang</code> is specified.
6905 Returns a list of 3 elements.
6906 </p>
6907 <div class="literalblock">
6908 <div class="content">
6909 <pre><code>{0 none 0} if -nohang is specified, and the process is still alive.</code></pre>
6910 </div></div>
6911 <div class="literalblock">
6912 <div class="content">
6913 <pre><code>{-1 error &lt;error-description&gt;} if the process does not exist or has already been waited for.</code></pre>
6914 </div></div>
6915 <div class="literalblock">
6916 <div class="content">
6917 <pre><code>{&lt;pid&gt; exit &lt;exit-status&gt;} if the process exited normally.</code></pre>
6918 </div></div>
6919 <div class="literalblock">
6920 <div class="content">
6921 <pre><code>{&lt;pid&gt; signal &lt;signal-number&gt;} if the process terminated on a signal.</code></pre>
6922 </div></div>
6923 <div class="literalblock">
6924 <div class="content">
6925 <pre><code>{&lt;pid&gt; other 0} otherwise (core dump, stopped, continued, etc.)</code></pre>
6926 </div></div>
6927 </dd>
6928 <dt class="hdlist1">
6929 <code><strong>os.gethostname</strong></code>
6930 </dt>
6931 <dd>
6933 Invokes <em>gethostname(3)</em> and returns the result.
6934 </p>
6935 </dd>
6936 <dt class="hdlist1">
6937 <code><strong>os.getids</strong></code>
6938 </dt>
6939 <dd>
6941 Returns the various user/group ids for the current process.
6942 </p>
6943 <div class="literalblock">
6944 <div class="content">
6945 <pre><code>jim&gt; os.getids
6946 uid 1000 euid 1000 gid 100 egid 100</code></pre>
6947 </div></div>
6948 </dd>
6949 <dt class="hdlist1">
6950 <code><strong>os.uptime</strong></code>
6951 </dt>
6952 <dd>
6954 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
6955 </p>
6956 </dd>
6957 </dl></div>
6958 </div>
6959 </div>
6960 </div>
6961 <div class="sect1">
6962 <h2 id="_ansi_i_o_aio_and_eventloop_api">ANSI I/O (aio) and EVENTLOOP API</h2>
6963 <div class="sectionbody">
6964 <div class="paragraph"><p>Jim provides an alternative object-based API for I/O.</p></div>
6965 <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>
6966 <div class="sect2">
6967 <h3 id="_aio">aio</h3>
6968 <div class="dlist"><dl>
6969 <dt class="hdlist1">
6970 <code>$handle <strong>accept</strong> ?addrvar?</code>
6971 </dt>
6972 <dd>
6974 Server socket only: Accept a connection and return stream.
6975 If <code><em>addrvar</em></code> is specified, the address of the connected client is stored
6976 in the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
6977 </p>
6978 </dd>
6979 <dt class="hdlist1">
6980 <code>$handle <strong>buffering none|line|full</strong></code>
6981 </dt>
6982 <dd>
6984 Sets the buffering mode of the stream.
6985 </p>
6986 </dd>
6987 <dt class="hdlist1">
6988 <code>$handle <strong>close</strong> ?r(ead)|w(rite)?</code>
6989 </dt>
6990 <dd>
6992 Closes the stream.
6993 The two-argument form is a "half-close" on a socket. See the <code>shutdown(2)</code> man page.
6994 </p>
6995 </dd>
6996 <dt class="hdlist1">
6997 <code>$handle <strong>copyto</strong> <em>tofd ?size?</em></code>
6998 </dt>
6999 <dd>
7001 Copy bytes to the file descriptor <code><em>tofd</em></code>. If <code><em>size</em></code> is specified, at most
7002 that many bytes will be copied. Otherwise copying continues until the end
7003 of the input file. Returns the number of bytes actually copied.
7004 </p>
7005 </dd>
7006 <dt class="hdlist1">
7007 <code>$handle <strong>eof</strong></code>
7008 </dt>
7009 <dd>
7011 Returns 1 if stream is at eof
7012 </p>
7013 </dd>
7014 <dt class="hdlist1">
7015 <code>$handle <strong>filename</strong></code>
7016 </dt>
7017 <dd>
7019 Returns the original filename associated with the handle.
7020 Handles returned by <a href="#_socket"><strong><code>socket</code></strong></a> give the socket type instead of a filename.
7021 </p>
7022 </dd>
7023 <dt class="hdlist1">
7024 <code>$handle <strong>flush</strong></code>
7025 </dt>
7026 <dd>
7028 Flush the stream
7029 </p>
7030 </dd>
7031 <dt class="hdlist1">
7032 <code>$handle <strong>gets</strong> <em>?var?</em></code>
7033 </dt>
7034 <dd>
7036 Read one line and return it or store it in the var
7037 </p>
7038 </dd>
7039 <dt class="hdlist1">
7040 <code>$handle <strong>isatty</strong></code>
7041 </dt>
7042 <dd>
7044 Returns 1 if the stream is a tty device.
7045 </p>
7046 </dd>
7047 <dt class="hdlist1">
7048 <code>$handle <strong>lock</strong></code>
7049 </dt>
7050 <dd>
7052 Apply a POSIX lock to the open file associated with the handle using
7053 fcntl(2).
7054 The handle must be open for write access.
7055 Returns 1 if the lock was successfully obtained, 0 otherwise.
7056 An error occurs if the handle is not suitable for locking (e.g.
7057 if it is not open for write)
7058 </p>
7059 </dd>
7060 <dt class="hdlist1">
7061 <code>$handle <strong>ndelay ?0|1?</strong></code>
7062 </dt>
7063 <dd>
7065 Set O_NDELAY (if arg). Returns current/new setting.
7066 Note that in general ANSI I/O interacts badly with non-blocking I/O.
7067 Use with care.
7068 </p>
7069 </dd>
7070 <dt class="hdlist1">
7071 <code>$handle <strong>puts ?-nonewline?</strong> <em>str</em></code>
7072 </dt>
7073 <dd>
7075 Write the string, with newline unless -nonewline
7076 </p>
7077 </dd>
7078 <dt class="hdlist1">
7079 <code>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></code>
7080 </dt>
7081 <dd>
7083 Read and return bytes from the stream. To eof if no len.
7084 </p>
7085 </dd>
7086 <dt class="hdlist1">
7087 <code>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></code>
7088 </dt>
7089 <dd>
7091 Receives a message from the handle via recvfrom(2) and returns it.
7092 At most <code><em>maxlen</em></code> bytes are read.
7093 If <code><em>addrvar</em></code> is specified, the sending address of the message is stored in
7094 the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
7095 </p>
7096 </dd>
7097 <dt class="hdlist1">
7098 <code>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></code>
7099 </dt>
7100 <dd>
7102 Seeks in the stream (default <em>current</em>)
7103 </p>
7104 </dd>
7105 <dt class="hdlist1">
7106 <code>$handle <strong>sendto</strong> <em>str ?addr:?port</em></code>
7107 </dt>
7108 <dd>
7110 Sends the string, <code><em>str</em></code>, to the given address via the socket using sendto(2).
7111 This is intended for udp/dgram sockets and may give an error or behave in unintended
7112 ways for other handle types.
7113 Returns the number of bytes written.
7114 </p>
7115 </dd>
7116 <dt class="hdlist1">
7117 <code>$handle <strong>sync</strong></code>
7118 </dt>
7119 <dd>
7121 Flush the stream, then fsync(2) to commit any changes to storage.
7122 Only available on platforms that support fsync(2).
7123 </p>
7124 </dd>
7125 <dt class="hdlist1">
7126 <code>$handle <strong>tell</strong></code>
7127 </dt>
7128 <dd>
7130 Returns the current seek position
7131 </p>
7132 </dd>
7133 <dt class="hdlist1">
7134 <code>$handle <strong>ssl</strong> <strong>?-server cert priv?</strong></code>
7135 </dt>
7136 <dd>
7138 Initiates a SSL/TLS session and returns a new stream
7139 </p>
7140 </dd>
7141 <dt class="hdlist1">
7142 <code>$handle <strong>unlock</strong></code>
7143 </dt>
7144 <dd>
7146 Release a POSIX lock previously acquired by <a href="#_aio"><strong><code>aio</code></strong></a> <code>lock</code>.
7147 </p>
7148 </dd>
7149 <dt class="hdlist1">
7150 <code>$handle <strong>verify</strong></code>
7151 </dt>
7152 <dd>
7154 Verifies the certificate of a SSL/TLS stream peer
7155 </p>
7156 </dd>
7157 <dt class="hdlist1">
7158 <code><strong>load_ssl_certs</strong> <em>dir</em></code>
7159 </dt>
7160 <dd>
7162 Loads SSL/TLS CA certificates for use during verification
7163 </p>
7164 </dd>
7165 </dl></div>
7166 </div>
7167 <div class="sect2">
7168 <h3 id="_fconfigure">fconfigure</h3>
7169 <div class="dlist"><dl>
7170 <dt class="hdlist1">
7171 <code><strong>fconfigure</strong> <em>handle</em> <strong>?-blocking 0|1? ?-buffering noneline|full? ?-translation</strong> <em>mode</em>?</code>
7172 </dt>
7173 <dd>
7175 For compatibility with Tcl, a limited form of the <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a>
7176 command is supported.
7177 </p>
7178 <div class="ulist"><ul>
7179 <li>
7181 <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>
7182 </p>
7183 </li>
7184 <li>
7186 <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>
7187 </p>
7188 </li>
7189 <li>
7191 <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a> <code>... -translation</code> is accepted but ignored
7192 </p>
7193 </li>
7194 </ul></div>
7195 </dd>
7196 </dl></div>
7197 </div>
7198 <div class="sect2">
7199 <h3 id="cmd_2">eventloop: after, vwait, update</h3>
7200 <div class="paragraph"><p>The following commands allow a script to be invoked when the given condition occurs.
7201 If no script is given, returns the current script. If the given script is the empty, the
7202 handler is removed.</p></div>
7203 <div class="dlist"><dl>
7204 <dt class="hdlist1">
7205 <code>$handle <strong>readable</strong> <em>?readable-script?</em></code>
7206 </dt>
7207 <dd>
7209 Sets or returns the script for when the socket is readable.
7210 </p>
7211 </dd>
7212 <dt class="hdlist1">
7213 <code>$handle <strong>writable</strong> <em>?writable-script?</em></code>
7214 </dt>
7215 <dd>
7217 Sets or returns the script for when the socket is writable.
7218 </p>
7219 </dd>
7220 <dt class="hdlist1">
7221 <code>$handle <strong>onexception</strong> <em>?exception-script?</em></code>
7222 </dt>
7223 <dd>
7225 Sets or returns the script for when oob data received.
7226 </p>
7227 </dd>
7228 </dl></div>
7229 <div class="paragraph"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <code>fileevent</code>. e.g.</p></div>
7230 <div class="dlist"><dl>
7231 <dt class="hdlist1">
7233 </dt>
7234 <dd>
7236 <code>fileevent $handle <strong>readable</strong> <em>...</em></code>
7237 </p>
7238 </dd>
7239 </dl></div>
7240 <div class="paragraph"><p>Time-based execution is also available via the eventloop API.</p></div>
7241 <div class="dlist"><dl>
7242 <dt class="hdlist1">
7243 <code><strong>after</strong> <em>ms</em></code>
7244 </dt>
7245 <dd>
7247 Sleeps for the given number of milliseconds. No events are
7248 processed during this time.
7249 </p>
7250 </dd>
7251 <dt class="hdlist1">
7252 <code><strong>after</strong> <em>ms</em>|<strong>idle</strong> <em>script ?script ...?</em></code>
7253 </dt>
7254 <dd>
7256 The scripts are concatenated and executed after the given
7257 number of milliseconds have elapsed. If <em>idle</em> is specified,
7258 the script will run the next time the event loop is processed
7259 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
7260 then removed. Returns an event id.
7261 </p>
7262 </dd>
7263 <dt class="hdlist1">
7264 <code><strong>after cancel</strong> <em>id|command</em></code>
7265 </dt>
7266 <dd>
7268 Cancels an <a href="#cmd_2"><strong><code>after</code></strong></a> event with the given event id or matching
7269 command (script). Returns the number of milliseconds
7270 remaining until the event would have fired. Returns the
7271 empty string if no matching event is found.
7272 </p>
7273 </dd>
7274 <dt class="hdlist1">
7275 <code><strong>after info</strong> <em>?id?</em></code>
7276 </dt>
7277 <dd>
7279 If <code><em>id</em></code> is not given, returns a list of current <a href="#cmd_2"><strong><code>after</code></strong></a>
7280 events. If <code><em>id</em></code> is given, returns a list containing the
7281 associated script and either <em>timer</em> or <em>idle</em> to indicated
7282 the type of the event. An error occurs if <code><em>id</em></code> does not
7283 match an event.
7284 </p>
7285 </dd>
7286 <dt class="hdlist1">
7287 <code><strong>vwait</strong> <em>variable</em></code>
7288 </dt>
7289 <dd>
7291 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
7292 events until the named (global) variable changes or all
7293 event handlers are removed. The variable need not exist
7294 beforehand. If there are no event handlers defined, <a href="#cmd_2"><strong><code>vwait</code></strong></a>
7295 returns immediately.
7296 </p>
7297 </dd>
7298 <dt class="hdlist1">
7299 <code><strong>update ?idletasks?</strong></code>
7300 </dt>
7301 <dd>
7303 A call to <a href="#cmd_2"><strong><code>update</code></strong></a> enters the eventloop to process expired events, but
7304 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
7305 not file events.
7306 Returns once handlers have been run for all expired events.
7307 </p>
7308 </dd>
7309 </dl></div>
7310 <div class="paragraph"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
7311 an attempt is made to call (the user-defined command) <code>bgerror</code> with the details of the error.
7312 If the <code>bgerror</code> command does not exist, the error message details are printed to stderr instead.</p></div>
7313 <div class="paragraph"><p>If a file event handler script generates an error, the handler is automatically removed
7314 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
7315 <div class="dlist"><dl>
7316 <dt class="hdlist1">
7317 <code><strong>bgerror</strong> <em>msg</em></code>
7318 </dt>
7319 <dd>
7321 Called when an event handler script generates an error. Note that the normal command resolution
7322 rules are used for bgerror. First the name is resolved in the current namespace, then in the
7323 global scope.
7324 </p>
7325 </dd>
7326 </dl></div>
7327 </div>
7328 <div class="sect2">
7329 <h3 id="_socket">socket</h3>
7330 <div class="paragraph"><p>Various socket types may be created.</p></div>
7331 <div class="dlist"><dl>
7332 <dt class="hdlist1">
7333 <code><strong>socket unix</strong> <em>path</em></code>
7334 </dt>
7335 <dd>
7337 A unix domain socket client.
7338 </p>
7339 </dd>
7340 <dt class="hdlist1">
7341 <code><strong>socket unix.server</strong> <em>path</em></code>
7342 </dt>
7343 <dd>
7345 A unix domain socket server.
7346 </p>
7347 </dd>
7348 <dt class="hdlist1">
7349 <code><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></code>
7350 </dt>
7351 <dd>
7353 A TCP socket client. (See the forms for <code><em>addr</em></code> below)
7354 </p>
7355 </dd>
7356 <dt class="hdlist1">
7357 <code><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></code>
7358 </dt>
7359 <dd>
7361 A TCP socket server (<code><em>addr</em></code> defaults to <code>0.0.0.0</code> for IPv4 or <code>[::]</code> for IPv6).
7362 </p>
7363 </dd>
7364 <dt class="hdlist1">
7365 <code><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</code>
7366 </dt>
7367 <dd>
7369 A UDP socket client. If the address is not specified,
7370 the client socket will be unbound and <em>sendto</em> must be used
7371 to indicated the destination.
7372 </p>
7373 </dd>
7374 <dt class="hdlist1">
7375 <code><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></code>
7376 </dt>
7377 <dd>
7379 A UDP socket server.
7380 </p>
7381 </dd>
7382 <dt class="hdlist1">
7383 <code><strong>socket pipe</strong></code>
7384 </dt>
7385 <dd>
7387 A pipe. Note that unlike all other socket types, this command returns
7388 a list of two channels: {read write}
7389 </p>
7390 </dd>
7391 <dt class="hdlist1">
7392 <code><strong>socket pair</strong></code>
7393 </dt>
7394 <dd>
7396 A socketpair (see socketpair(2)). Like <a href="#_socket"><strong><code>socket</code></strong></a> <code>pipe</code>, this command returns
7397 a list of two channels: {s1 s2}. These channels are both readable and writable.
7398 </p>
7399 </dd>
7400 </dl></div>
7401 <div class="paragraph"><p>This command creates a socket connected (client) or bound (server) to the given
7402 address.</p></div>
7403 <div class="paragraph"><p>The returned value is channel and may generally be used with the various file I/O
7404 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
7405 <div class="olist arabic"><ol class="arabic">
7406 <li>
7408 set f [socket stream www.google.com:80]
7409 aio.sockstream1
7410 </p>
7411 </li>
7412 <li>
7414 $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
7415 </p>
7416 </li>
7417 <li>
7419 $f gets
7420 HTTP/1.0 302 Found
7421 </p>
7422 </li>
7423 <li>
7425 $f close
7426 </p>
7427 </li>
7428 </ol></div>
7429 <div class="paragraph"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
7430 the EVENTLOOP API.</p></div>
7431 <div class="literalblock">
7432 <div class="content">
7433 <pre><code>set f [socket stream.server 80]
7434 $f readable {
7435 set client [$f accept]
7436 $client gets $buf
7438 $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
7439 $client close
7441 vwait done</code></pre>
7442 </div></div>
7443 <div class="paragraph"><p>The address, <code><em>addr</em></code>, can be given in one of the following forms:</p></div>
7444 <div class="olist arabic"><ol class="arabic">
7445 <li>
7447 For IPv4 socket types, an IPv4 address such as 192.168.1.1
7448 </p>
7449 </li>
7450 <li>
7452 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
7453 </p>
7454 </li>
7455 <li>
7457 A hostname
7458 </p>
7459 </li>
7460 </ol></div>
7461 <div class="paragraph"><p>Note that on many systems, listening on an IPv6 address such as [::] will
7462 also accept requests via IPv4.</p></div>
7463 <div class="paragraph"><p>Where a hostname is specified, the <code><em>first</em></code> returned address is used
7464 which matches the socket type is used.</p></div>
7465 <div class="paragraph"><p>The special type <em>pipe</em> isn&#8217;t really a socket.</p></div>
7466 <div class="literalblock">
7467 <div class="content">
7468 <pre><code>lassign [socket pipe] r w</code></pre>
7469 </div></div>
7470 <div class="literalblock">
7471 <div class="content">
7472 <pre><code># Must close $w after exec
7473 exec ps &gt;@$w &amp;
7474 $w close</code></pre>
7475 </div></div>
7476 <div class="literalblock">
7477 <div class="content">
7478 <pre><code>$r readable ...</code></pre>
7479 </div></div>
7480 </div>
7481 <div class="sect2">
7482 <h3 id="_syslog">syslog</h3>
7483 <div class="paragraph"><p><code><strong>syslog</strong> <em>?options? ?priority? message</em></code></p></div>
7484 <div class="paragraph"><p>This command sends message to system syslog facility with given
7485 priority. Valid priorities are:</p></div>
7486 <div class="literalblock">
7487 <div class="content">
7488 <pre><code>emerg, alert, crit, err, error, warning, notice, info, debug</code></pre>
7489 </div></div>
7490 <div class="paragraph"><p>If a message is specified, but no priority is specified, then a
7491 priority of info is used.</p></div>
7492 <div class="paragraph"><p>By default, facility user is used and the value of global tcl variable
7493 argv0 is used as ident string. However, any of the following options
7494 may be specified before priority to control these parameters:</p></div>
7495 <div class="dlist"><dl>
7496 <dt class="hdlist1">
7497 <code><strong>-facility</strong> <em>value</em></code>
7498 </dt>
7499 <dd>
7501 Use specified facility instead of user. The following
7502 values for facility are recognized:
7503 </p>
7504 <div class="literalblock">
7505 <div class="content">
7506 <pre><code>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
7507 uucp, local0-local7</code></pre>
7508 </div></div>
7509 </dd>
7510 <dt class="hdlist1">
7511 <code><strong>-ident</strong> <em>string</em></code>
7512 </dt>
7513 <dd>
7515 Use given string instead of argv0 variable for ident string.
7516 </p>
7517 </dd>
7518 <dt class="hdlist1">
7519 <code><strong>-options</strong> <em>integer</em></code>
7520 </dt>
7521 <dd>
7523 Set syslog options such as <code>LOG_CONS</code>, <code>LOG_NDELAY</code>. You should
7524 use numeric values of those from your system syslog.h file,
7525 because I haven&#8217;t got time to implement yet another hash
7526 table.
7527 </p>
7528 </dd>
7529 </dl></div>
7530 </div>
7531 <div class="sect2">
7532 <h3 id="cmd_3">pack: pack, unpack</h3>
7533 <div class="paragraph"><p>The optional <em>pack</em> extension provides commands to encode and decode binary strings.</p></div>
7534 <div class="dlist"><dl>
7535 <dt class="hdlist1">
7536 <code><strong>pack</strong> <em>varName value</em> <strong>-intle|-intbe|-floatle|-floatbe|-str</strong> <em>bitwidth ?bitoffset?</em></code>
7537 </dt>
7538 <dd>
7540 Packs the binary representation of <code><em>value</em></code> into the variable
7541 <code><em>varName</em></code>. The value is packed according to the given type
7542 (integer/floating point/string, big-endian/little-endian), width and bit offset.
7543 The variable is created if necessary (like <a href="#_append"><strong><code>append</code></strong></a>).
7544 The variable is expanded if necessary.
7545 </p>
7546 </dd>
7547 <dt class="hdlist1">
7548 <code><strong>unpack</strong> <em>binvalue</em> <strong>-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str</strong> <em>bitpos bitwidth</em></code>
7549 </dt>
7550 <dd>
7552 Unpacks bits from <code><em>binvalue</em></code> at bit position <code><em>bitpos</em></code> and with <code><em>bitwidth</em></code>.
7553 Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
7554 and signed/unsigned) and returns it. For integer types, <code><em>bitwidth</em></code>
7555 may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
7556 <code><em>bitwidth</em></code> may be 32 bits (for single precision numbers) or 64 bits (for double precision).
7557 For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
7558 access outside the length of the value will return 0 for integer types, 0.0 for floating point types
7559 or the empty string for the string type.
7560 </p>
7561 </dd>
7562 </dl></div>
7563 </div>
7564 <div class="sect2">
7565 <h3 id="_zlib">zlib</h3>
7566 <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>
7567 <div class="dlist"><dl>
7568 <dt class="hdlist1">
7569 <code><strong>crc32</strong> <em>data</em> <em>?startValue?</em></code>
7570 </dt>
7571 <dd>
7573 Returns the CRC32 checksum of a buffer. Optionally, an initial value may be specified; this is most useful
7574 for calculating the checksum of chunked data read from a stream (for instance, a pipe).
7575 </p>
7576 </dd>
7577 <dt class="hdlist1">
7578 <code><strong>deflate</strong> <em>string</em> <em>?level?</em></code>
7579 </dt>
7580 <dd>
7582 Compresses a buffer and outputs a raw, Deflate-compressed stream. Optionally, a compression level (1-9) may
7583 be specified to choose the desired speed vs. compression rate ratio.
7584 </p>
7585 </dd>
7586 <dt class="hdlist1">
7587 <code><strong>inflate</strong> <em>data</em> <em>?bufferSize?</em></code>
7588 </dt>
7589 <dd>
7591 Decompresses a raw, Deflate-compressed stream. When the uncompressed data size is known and specified, memory
7592 allocation is more efficient. Otherwise, decomperssion is chunked and therefore slower.
7593 </p>
7594 </dd>
7595 <dt class="hdlist1">
7596 <code><strong>gzip</strong> <em>string</em> <em>?-level level?</em></code>
7597 </dt>
7598 <dd>
7600 Compresses a buffer and adds a gzip header.
7601 </p>
7602 </dd>
7603 <dt class="hdlist1">
7604 <code><strong>gunzip</strong> <em>data</em> <em>?-buffersize size?</em></code>
7605 </dt>
7606 <dd>
7608 Decompresses a gzip-compressed buffer. Decompression is chunked, with a default, small buffer size of 64K
7609 which guarantees lower memory footprint at the cost of speed. It is recommended to use a bigger size, on
7610 systems without a severe memory constraint.
7611 </p>
7612 </dd>
7613 </dl></div>
7614 </div>
7615 <div class="sect2">
7616 <h3 id="_binary">binary</h3>
7617 <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>
7618 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>
7619 <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>
7620 <div class="paragraph"><p>Note that <em>binary format</em> with f/r/R specifiers (single-precision float) uses the value of Infinity
7621 in case of overflow.</p></div>
7622 </div>
7623 <div class="sect2">
7624 <h3 id="cmd_4">oo: class, super</h3>
7625 <div class="paragraph"><p>The optional, pure-Tcl <em>oo</em> extension provides object-oriented (OO) support for Jim Tcl.</p></div>
7626 <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>
7627 <div class="dlist"><dl>
7628 <dt class="hdlist1">
7629 <code><strong>class</strong> <em>classname ?baseclasses? classvars</em></code>
7630 </dt>
7631 <dd>
7633 Create a new class, <code><em>classname</em></code>, with the given dictionary
7634 (<code><em>classvars</em></code>) as class variables. These are the initial variables
7635 which all newly created objects of this class are initialised with.
7636 If a list of baseclasses is given, methods and instance variables
7637 are inherited.
7638 </p>
7639 </dd>
7640 <dt class="hdlist1">
7641 <code><strong>super</strong> <em>method ?args ...?</em></code>
7642 </dt>
7643 <dd>
7645 From within a method, invokes the given method on the base class.
7646 Note that this will only call the last baseclass given.
7647 </p>
7648 </dd>
7649 </dl></div>
7650 </div>
7651 <div class="sect2">
7652 <h3 id="_tree">tree</h3>
7653 <div class="paragraph"><p>The optional, pure-Tcl <em>tree</em> extension implements an OO, general purpose tree structure
7654 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>
7655 <div class="paragraph"><p>A tree is a collection of nodes, where each node (except the root node) has a single parent
7656 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.</p></div>
7657 <div class="dlist"><dl>
7658 <dt class="hdlist1">
7659 <code><strong>tree</strong></code>
7660 </dt>
7661 <dd>
7663 Creates and returns a new tree object with a single node named "root".
7664 All operations on the tree are invoked through this object.
7665 </p>
7666 </dd>
7667 <dt class="hdlist1">
7668 <code>$tree <strong>destroy</strong></code>
7669 </dt>
7670 <dd>
7672 Destroy the tree and all it&#8217;s nodes. (Note that the tree will also
7673 be automatically garbage collected once it goes out of scope).
7674 </p>
7675 </dd>
7676 <dt class="hdlist1">
7677 <code>$tree <strong>set</strong> <em>nodename key value</em></code>
7678 </dt>
7679 <dd>
7681 Set the value for the given attribute key.
7682 </p>
7683 </dd>
7684 <dt class="hdlist1">
7685 <code>$tree <strong>lappend</strong> <em>nodename key value ...</em></code>
7686 </dt>
7687 <dd>
7689 Append to the (list) value(s) for the given attribute key, or set if not yet set.
7690 </p>
7691 </dd>
7692 <dt class="hdlist1">
7693 <code>$tree <strong>keyexists</strong> <em>nodename key</em></code>
7694 </dt>
7695 <dd>
7697 Returns 1 if the given attribute key exists.
7698 </p>
7699 </dd>
7700 <dt class="hdlist1">
7701 <code>$tree <strong>get</strong> <em>nodename key</em></code>
7702 </dt>
7703 <dd>
7705 Returns the value associated with the given attribute key.
7706 </p>
7707 </dd>
7708 <dt class="hdlist1">
7709 <code>$tree <strong>getall</strong> <em>nodename</em></code>
7710 </dt>
7711 <dd>
7713 Returns the entire attribute dictionary associated with the given key.
7714 </p>
7715 </dd>
7716 <dt class="hdlist1">
7717 <code>$tree <strong>depth</strong> <em>nodename</em></code>
7718 </dt>
7719 <dd>
7721 Returns the depth of the given node. The depth of "root" is 0.
7722 </p>
7723 </dd>
7724 <dt class="hdlist1">
7725 <code>$tree <strong>parent</strong> <em>nodename</em></code>
7726 </dt>
7727 <dd>
7729 Returns the node name of the parent node, or "" for the root node.
7730 </p>
7731 </dd>
7732 <dt class="hdlist1">
7733 <code>$tree <strong>numchildren</strong> <em>nodename</em></code>
7734 </dt>
7735 <dd>
7737 Returns the number of child nodes.
7738 </p>
7739 </dd>
7740 <dt class="hdlist1">
7741 <code>$tree <strong>children</strong> <em>nodename</em></code>
7742 </dt>
7743 <dd>
7745 Returns a list of the child nodes.
7746 </p>
7747 </dd>
7748 <dt class="hdlist1">
7749 <code>$tree <strong>next</strong> <em>nodename</em></code>
7750 </dt>
7751 <dd>
7753 Returns the next sibling node, or "" if none.
7754 </p>
7755 </dd>
7756 <dt class="hdlist1">
7757 <code>$tree <strong>insert</strong> <em>nodename ?index?</em></code>
7758 </dt>
7759 <dd>
7761 Add a new child node to the given node. The index is a list index
7762 such as <code>3</code> or <code>end-2</code>. The default index is <code>end</code>.
7763 Returns the name of the newly added node.
7764 </p>
7765 </dd>
7766 <dt class="hdlist1">
7767 <code>$tree <strong>walk</strong> <em>nodename</em> <strong>dfs|bfs</strong> {<em>actionvar nodevar</em>} <em>script</em></code>
7768 </dt>
7769 <dd>
7771 Walks the tree starting from the given node, either breadth first (<code>bfs</code>)
7772 depth first (<code>dfs</code>).
7773 The value <code>"enter"</code> or <code>"exit"</code> is stored in variable <code><em>actionvar</em></code>.
7774 The name of each node is stored in <code><em>nodevar</em></code>.
7775 The script is evaluated twice for each node, on entry and exit.
7776 </p>
7777 </dd>
7778 <dt class="hdlist1">
7779 <code>$tree <strong>dump</strong></code>
7780 </dt>
7781 <dd>
7783 Dumps the tree contents to stdout
7784 </p>
7785 </dd>
7786 </dl></div>
7787 </div>
7788 <div class="sect2">
7789 <h3 id="_tcl_prefix">tcl::prefix</h3>
7790 <div class="paragraph"><p>The optional tclprefix extension provides the Tcl8.6-compatible <em>tcl::prefix</em> command
7791 (<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
7792 of possible values (typically commands or options).</p></div>
7793 <div class="dlist"><dl>
7794 <dt class="hdlist1">
7795 <code><strong>tcl::prefix all</strong> <em>table string</em></code>
7796 </dt>
7797 <dd>
7799 Returns a list of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7800 </p>
7801 </dd>
7802 <dt class="hdlist1">
7803 <code><strong>tcl::prefix longest</strong> <em>table string</em></code>
7804 </dt>
7805 <dd>
7807 Returns the longest common prefix of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7808 </p>
7809 </dd>
7810 <dt class="hdlist1">
7811 <code><strong>tcl::prefix match</strong> <em>?options? table string</em></code>
7812 </dt>
7813 <dd>
7815 If <code><em>string</em></code> equals one element in <code><em>table</em></code> or is a prefix to
7816 exactly one element, the matched element is returned. If not, the
7817 result depends on the <code>-error</code> option.
7818 </p>
7819 <div class="ulist"><ul>
7820 <li>
7822 <code><strong>-exact</strong></code> Accept only exact matches.
7823 </p>
7824 </li>
7825 <li>
7827 <code><strong>-message</strong> <em>string</em></code> Use <code><em>string</em></code> in the error message at a mismatch. Default is "option".
7828 </p>
7829 </li>
7830 <li>
7832 <code><strong>-error</strong> <em>options</em></code> The options are used when no match is found. If <code><em>options</em></code> is
7833 empty, no error is generated and an empty string is returned.
7834 Otherwise the options are used as return options when
7835 generating the error message. The default corresponds to
7836 setting <code>-level 0</code>.
7837 </p>
7838 </li>
7839 </ul></div>
7840 </dd>
7841 </dl></div>
7842 </div>
7843 <div class="sect2">
7844 <h3 id="_history">history</h3>
7845 <div class="paragraph"><p>The optional history extension provides script access to the command line editing
7846 and history support available in <em>jimsh</em>. See <em>examples/jtclsh.tcl</em> for an example.
7847 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
7848 the remaining subcommands do nothing.</p></div>
7849 <div class="dlist"><dl>
7850 <dt class="hdlist1">
7851 <code><strong>history load</strong> <em>filename</em></code>
7852 </dt>
7853 <dd>
7855 Load history from a (text) file. If the file does not exist or is not readable,
7856 it is ignored.
7857 </p>
7858 </dd>
7859 <dt class="hdlist1">
7860 <code><strong>history getline</strong> <em>prompt ?varname?</em></code>
7861 </dt>
7862 <dd>
7864 Displays the given prompt and allows a line to be entered. Similarly to <a href="#_gets"><strong><code>gets</code></strong></a>,
7865 if <code><em>varname</em></code> is given, it receives the line and the length of the line is returned,
7866 or -1 on EOF. If <code><em>varname</em></code> is not given, the line is returned directly.
7867 </p>
7868 </dd>
7869 <dt class="hdlist1">
7870 <code><strong>history add</strong> <em>line</em></code>
7871 </dt>
7872 <dd>
7874 Adds the given line to the history buffer.
7875 </p>
7876 </dd>
7877 <dt class="hdlist1">
7878 <code><strong>history save</strong> <em>filename</em></code>
7879 </dt>
7880 <dd>
7882 Saves the current history buffer to the given file.
7883 </p>
7884 </dd>
7885 <dt class="hdlist1">
7886 <code><strong>history show</strong></code>
7887 </dt>
7888 <dd>
7890 Displays the current history buffer to standard output.
7891 </p>
7892 </dd>
7893 </dl></div>
7894 </div>
7895 <div class="sect2">
7896 <h3 id="_namespace">namespace</h3>
7897 <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>
7898 <div class="dlist"><dl>
7899 <dt class="hdlist1">
7900 <code><strong>namespace code</strong> <em>script</em></code>
7901 </dt>
7902 <dd>
7904 Captures the current namespace context for later execution of
7905 the script <code><em>script</em></code>. It returns a new script in which script has
7906 been wrapped in a <code><strong>namespace inscope</strong></code> command.
7907 </p>
7908 </dd>
7909 <dt class="hdlist1">
7910 <code><strong>namespace current</strong></code>
7911 </dt>
7912 <dd>
7914 Returns the fully-qualified name for the current namespace.
7915 </p>
7916 </dd>
7917 <dt class="hdlist1">
7918 <code><strong>namespace delete</strong> <em>?namespace &#8230;?</em></code>
7919 </dt>
7920 <dd>
7922 Deletes all commands and variables with the given namespace prefixes.
7923 </p>
7924 </dd>
7925 <dt class="hdlist1">
7926 <code><strong>namespace eval</strong> <em>namespace arg ?arg&#8230;?</em></code>
7927 </dt>
7928 <dd>
7930 Activates a namespace called <code><em>namespace</em></code> and evaluates some code in that context.
7931 </p>
7932 </dd>
7933 <dt class="hdlist1">
7934 <code><strong>namespace origin</strong> <em>command</em></code>
7935 </dt>
7936 <dd>
7938 Returns the fully-qualified name of the original command to which the imported command <code><em>command</em></code> refers.
7939 </p>
7940 </dd>
7941 <dt class="hdlist1">
7942 <code><strong>namespace parent</strong> ?namespace?</code>
7943 </dt>
7944 <dd>
7946 Returns the fully-qualified name of the parent namespace for namespace <code><em>namespace</em></code>, if given, otherwise
7947 for the current namespace.
7948 </p>
7949 </dd>
7950 <dt class="hdlist1">
7951 <code><strong>namespace qualifiers</strong> <em>string</em></code>
7952 </dt>
7953 <dd>
7955 Returns any leading namespace qualifiers for <code><em>string</em></code>
7956 </p>
7957 </dd>
7958 <dt class="hdlist1">
7959 <code><strong>namespace tail</strong> <em>string</em></code>
7960 </dt>
7961 <dd>
7963 Returns the simple name at the end of a qualified string.
7964 </p>
7965 </dd>
7966 <dt class="hdlist1">
7967 <code><strong>namespace upvar</strong> <em>namespace ?arg&#8230;?</em></code>
7968 </dt>
7969 <dd>
7971 This command arranges for zero or more local variables in the current procedure to refer to variables in <code><em>namespace</em></code>
7972 </p>
7973 </dd>
7974 <dt class="hdlist1">
7975 <code><strong>namespace which</strong> <em>?-command|-variable? name</em></code>
7976 </dt>
7977 <dd>
7979 Looks up <code><em>name</em></code> as either a command (the default) or variable and returns its fully-qualified name.
7980 </p>
7981 </dd>
7982 </dl></div>
7983 </div>
7984 <div class="sect2">
7985 <h3 id="_interp">interp</h3>
7986 <div class="paragraph"><p>The optional <em>interp</em> command allows sub-interpreters to be created where commands may be run
7987 independently (but synchronously) of the main interpreter.</p></div>
7988 <div class="dlist"><dl>
7989 <dt class="hdlist1">
7990 <code><strong>interp</strong></code>
7991 </dt>
7992 <dd>
7994 Creates and returns a new interpreter object (command).
7995 The created interpeter contains any built-in commands along with static extensions,
7996 but does not include any dynamically loaded commands (package require, load).
7997 These must be reloaded in the child interpreter if required.
7998 </p>
7999 </dd>
8000 <dt class="hdlist1">
8001 <code><strong>$interp delete</strong></code>
8002 </dt>
8003 <dd>
8005 Deletes the interpeter object.
8006 </p>
8007 </dd>
8008 <dt class="hdlist1">
8009 <code><strong>$interp eval</strong> <em>script</em> &#8230;</code>
8010 </dt>
8011 <dd>
8013 Evaluates a script in the context for the child interpreter, in the same way as <em>eval</em>.
8014 </p>
8015 </dd>
8016 <dt class="hdlist1">
8017 <code><strong>$interp alias</strong> <em>alias childcmd parentcmd ?arg &#8230;?</em></code>
8018 </dt>
8019 <dd>
8021 Similar to <em>alias</em>, but creates a command, <code><em>childcmd</em></code>, in the child interpreter that is an
8022 alias for <code><em>parentcmd</em></code> in the parent interpreter, with the given, fixed arguments.
8023 The alias may be deleted in the child with <em>rename</em>.
8024 </p>
8025 </dd>
8026 </dl></div>
8027 </div>
8028 </div>
8029 </div>
8030 <div class="sect1">
8031 <h2 id="BuiltinVariables">BUILT-IN VARIABLES</h2>
8032 <div class="sectionbody">
8033 <div class="paragraph"><p>The following global variables are created automatically
8034 by the Tcl library.</p></div>
8035 <div class="dlist"><dl>
8036 <dt class="hdlist1">
8037 <code><strong>env</strong></code>
8038 </dt>
8039 <dd>
8041 This variable is set by Jim as an array
8042 whose elements are the environment variables for the process.
8043 Reading an element will return the value of the corresponding
8044 environment variable.
8045 This array is initialised at startup from the <a href="#_env"><strong><code>env</code></strong></a> command.
8046 It may be modified and will affect the environment passed to
8047 commands invoked with <a href="#_exec"><strong><code>exec</code></strong></a>.
8048 </p>
8049 </dd>
8050 <dt class="hdlist1">
8051 <code><strong>platform_tcl</strong></code>
8052 </dt>
8053 <dd>
8055 This variable is set by Jim as an array containing information
8056 about the platform on which Jim was built. Currently this includes
8057 <em>os</em> and <em>platform</em>.
8058 </p>
8059 </dd>
8060 <dt class="hdlist1">
8061 <code><strong>auto_path</strong></code>
8062 </dt>
8063 <dd>
8065 This variable contains a list of paths to search for packages.
8066 It defaults to a location based on where jim is installed
8067 (e.g. <code>/usr/local/lib/jim</code>), but may be changed by <code>jimsh</code>
8068 or the embedding application. Note that <code>jimsh</code> will consider
8069 the environment variable <code>$JIMLIB</code> to be a list of colon-separated
8070 list of paths to add to <code><strong>auto_path</strong></code>.
8071 </p>
8072 </dd>
8073 <dt class="hdlist1">
8074 <code><strong>errorCode</strong></code>
8075 </dt>
8076 <dd>
8078 This variable holds the value of the -errorcode return
8079 option set by the most recent error that occurred in this
8080 interpreter. This list value represents additional information
8081 about the error in a form that is easy to process with
8082 programs. The first element of the list identifies a general
8083 class of errors, and determines the format of the rest of
8084 the list. The following formats for -errorcode return options
8085 are used by the Tcl core; individual applications may define
8086 additional formats. Currently only <a href="#_exec"><strong><code>exec</code></strong></a> sets this variable.
8087 Otherwise it will be <code>NONE</code>.
8088 </p>
8089 </dd>
8090 </dl></div>
8091 <div class="paragraph"><p>The following global variables are set by jimsh.</p></div>
8092 <div class="dlist"><dl>
8093 <dt class="hdlist1">
8094 <code><strong>tcl_interactive</strong></code>
8095 </dt>
8096 <dd>
8098 This variable is set to 1 if jimsh is started in interactive mode
8099 or 0 otherwise.
8100 </p>
8101 </dd>
8102 <dt class="hdlist1">
8103 <code><strong>tcl_platform</strong></code>
8104 </dt>
8105 <dd>
8107 This variable is set by Jim as an array containing information
8108 about the platform upon which Jim was built. The following is an
8109 example of the contents of this array.
8110 </p>
8111 <div class="literalblock">
8112 <div class="content">
8113 <pre><code>tcl_platform(byteOrder) = littleEndian
8114 tcl_platform(engine) = Jim
8115 tcl_platform(os) = Darwin
8116 tcl_platform(platform) = unix
8117 tcl_platform(pointerSize) = 8
8118 tcl_platform(threaded) = 0
8119 tcl_platform(wordSize) = 8
8120 tcl_platform(pathSeparator) = :</code></pre>
8121 </div></div>
8122 </dd>
8123 <dt class="hdlist1">
8124 <code><strong>argv0</strong></code>
8125 </dt>
8126 <dd>
8128 If jimsh is invoked to run a script, this variable contains the name
8129 of the script.
8130 </p>
8131 </dd>
8132 <dt class="hdlist1">
8133 <code><strong>argv</strong></code>
8134 </dt>
8135 <dd>
8137 If jimsh is invoked to run a script, this variable contains a list
8138 of any arguments supplied to the script.
8139 </p>
8140 </dd>
8141 <dt class="hdlist1">
8142 <code><strong>argc</strong></code>
8143 </dt>
8144 <dd>
8146 If jimsh is invoked to run a script, this variable contains the number
8147 of arguments supplied to the script.
8148 </p>
8149 </dd>
8150 <dt class="hdlist1">
8151 <code><strong>jim::argv0</strong></code>
8152 </dt>
8153 <dd>
8155 The value of argv[0] when jimsh was invoked.
8156 </p>
8157 </dd>
8158 </dl></div>
8159 </div>
8160 </div>
8161 <div class="sect1">
8162 <h2 id="_changes_in_previous_releases">CHANGES IN PREVIOUS RELEASES</h2>
8163 <div class="sectionbody">
8164 <div class="sect2">
8165 <h3 id="_in_v0_70">In v0.70</h3>
8166 <div class="olist arabic"><ol class="arabic">
8167 <li>
8169 <code>platform_tcl()</code> settings are now automatically determined
8170 </p>
8171 </li>
8172 <li>
8174 Add aio <code>$handle filename</code>
8175 </p>
8176 </li>
8177 <li>
8179 Add <a href="#_info"><strong><code>info</code></strong></a> <code>channels</code>
8180 </p>
8181 </li>
8182 <li>
8184 The <em>bio</em> extension is gone. Now <a href="#_aio"><strong><code>aio</code></strong></a> supports <em>copyto</em>.
8185 </p>
8186 </li>
8187 <li>
8189 Add <a href="#_exists"><strong><code>exists</code></strong></a> command
8190 </p>
8191 </li>
8192 <li>
8194 Add the pure-Tcl <em>oo</em> extension
8195 </p>
8196 </li>
8197 <li>
8199 The <a href="#_exec"><strong><code>exec</code></strong></a> command now only uses vfork(), not fork()
8200 </p>
8201 </li>
8202 <li>
8204 Unit test framework is less verbose and more Tcl-compatible
8205 </p>
8206 </li>
8207 <li>
8209 Optional UTF-8 support
8210 </p>
8211 </li>
8212 <li>
8214 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
8215 </p>
8216 </li>
8217 <li>
8219 Command line editing in interactive mode, e.g. <em>jimsh</em>
8220 </p>
8221 </li>
8222 </ol></div>
8223 </div>
8224 <div class="sect2">
8225 <h3 id="_in_v0_63">In v0.63</h3>
8226 <div class="olist arabic"><ol class="arabic">
8227 <li>
8229 <a href="#_source"><strong><code>source</code></strong></a> now checks that a script is complete (.i.e. not missing a brace)
8230 </p>
8231 </li>
8232 <li>
8234 <em>info complete</em> now uses the real parser and so is 100% accurate
8235 </p>
8236 </li>
8237 <li>
8239 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>
8240 </p>
8241 </li>
8242 <li>
8244 <a href="#_tailcall"><strong><code>tailcall</code></strong></a> no longer loses stack trace information
8245 </p>
8246 </li>
8247 <li>
8249 Add <a href="#_alias"><strong><code>alias</code></strong></a> and <a href="#_curry"><strong><code>curry</code></strong></a>
8250 </p>
8251 </li>
8252 <li>
8254 <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
8255 </p>
8256 </li>
8257 <li>
8259 <a href="#_local"><strong><code>local</code></strong></a> allows procedures to be deleted automatically at the end of the current procedure
8260 </p>
8261 </li>
8262 <li>
8264 udp sockets are now supported for both clients and servers.
8265 </p>
8266 </li>
8267 <li>
8269 vfork-based exec is now working correctly
8270 </p>
8271 </li>
8272 <li>
8274 Add <em>file tempfile</em>
8275 </p>
8276 </li>
8277 <li>
8279 Add <em>socket pipe</em>
8280 </p>
8281 </li>
8282 <li>
8284 Enhance <em>try &#8230; on &#8230; finally</em> to be more Tcl 8.6 compatible
8285 </p>
8286 </li>
8287 <li>
8289 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>
8290 </p>
8291 </li>
8292 <li>
8294 IPv6 support is now included
8295 </p>
8296 </li>
8297 <li>
8299 Add <em>string is</em>
8300 </p>
8301 </li>
8302 <li>
8304 Event handlers works better if an error occurs. eof handler has been removed.
8305 </p>
8306 </li>
8307 <li>
8309 <a href="#_exec"><strong><code>exec</code></strong></a> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
8310 </p>
8311 </li>
8312 <li>
8314 Command pipelines via open "|&#8230;" are now supported
8315 </p>
8316 </li>
8317 <li>
8319 <a href="#_pid"><strong><code>pid</code></strong></a> can now return pids of a command pipeline
8320 </p>
8321 </li>
8322 <li>
8324 Add <em>info references</em>
8325 </p>
8326 </li>
8327 <li>
8329 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>
8330 </p>
8331 </li>
8332 <li>
8334 <a href="#_exec"><strong><code>exec</code></strong></a> now sets environment based on $::env
8335 </p>
8336 </li>
8337 <li>
8339 Add <em>dict keys</em>
8340 </p>
8341 </li>
8342 <li>
8344 Add support for <em>lsort -index</em>
8345 </p>
8346 </li>
8347 </ol></div>
8348 </div>
8349 <div class="sect2">
8350 <h3 id="_in_v0_62">In v0.62</h3>
8351 <div class="olist arabic"><ol class="arabic">
8352 <li>
8354 Add support to <a href="#_exec"><strong><code>exec</code></strong></a> for <em>&gt;&amp;</em>, <em>&gt;&gt;&amp;</em>, <em>|&amp;</em>, <em>2&gt;@1</em>
8355 </p>
8356 </li>
8357 <li>
8359 Fix <a href="#_exec"><strong><code>exec</code></strong></a> error messages when special token (e.g. <em>&gt;</em>) is the last token
8360 </p>
8361 </li>
8362 <li>
8364 Fix <a href="#_subst"><strong><code>subst</code></strong></a> handling of backslash escapes.
8365 </p>
8366 </li>
8367 <li>
8369 Allow abbreviated options for <a href="#_subst"><strong><code>subst</code></strong></a>
8370 </p>
8371 </li>
8372 <li>
8374 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
8375 </p>
8376 </li>
8377 <li>
8379 Many <a href="#_expr"><strong><code>expr</code></strong></a> bug fixes
8380 </p>
8381 </li>
8382 <li>
8384 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
8385 </p>
8386 </li>
8387 <li>
8389 The variable name argument to <a href="#_regsub"><strong><code>regsub</code></strong></a> is now optional
8390 </p>
8391 </li>
8392 <li>
8394 Add support for <em>unset -nocomplain</em>
8395 </p>
8396 </li>
8397 <li>
8399 Add support for list commands: <a href="#_lassign"><strong><code>lassign</code></strong></a>, <a href="#_lrepeat"><strong><code>lrepeat</code></strong></a>
8400 </p>
8401 </li>
8402 <li>
8404 Fully-functional <a href="#_lsearch"><strong><code>lsearch</code></strong></a> is now implemented
8405 </p>
8406 </li>
8407 <li>
8409 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
8410 </p>
8411 </li>
8412 <li>
8414 Allow <a href="#_catch"><strong><code>catch</code></strong></a> to determine what return codes are caught
8415 </p>
8416 </li>
8417 <li>
8419 Allow <a href="#_incr"><strong><code>incr</code></strong></a> to increment an unset variable by first setting to 0
8420 </p>
8421 </li>
8422 <li>
8424 Allow <em>args</em> and optional arguments to the left or required arguments in <a href="#_proc"><strong><code>proc</code></strong></a>
8425 </p>
8426 </li>
8427 <li>
8429 Add <em>file copy</em>
8430 </p>
8431 </li>
8432 <li>
8434 Add <em>try &#8230; finally</em> command
8435 </p>
8436 </li>
8437 </ol></div>
8438 </div>
8439 </div>
8440 </div>
8441 <div class="sect1">
8442 <h2 id="_licence">LICENCE</h2>
8443 <div class="sectionbody">
8444 <div class="literalblock">
8445 <div class="content">
8446 <pre><code>Copyright 2005 Salvatore Sanfilippo &lt;antirez@invece.org&gt;
8447 Copyright 2005 Clemens Hintze &lt;c.hintze@gmx.net&gt;
8448 Copyright 2005 patthoyts - Pat Thoyts &lt;patthoyts@users.sf.net&gt;
8449 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
8450 Copyright 2008 Andrew Lunn &lt;andrew@lunn.ch&gt;
8451 Copyright 2008 Duane Ellis &lt;openocd@duaneellis.com&gt;
8452 Copyright 2008 Uwe Klein &lt;uklein@klein-messgeraete.de&gt;
8453 Copyright 2009 Steve Bennett &lt;steveb@workware.net.au&gt;</code></pre>
8454 </div></div>
8455 <div class="literalblock">
8456 <div class="content">
8457 <pre><code>Redistribution and use in source and binary forms, with or without
8458 modification, are permitted provided that the following conditions
8459 are met:
8460 1. Redistributions of source code must retain the above copyright
8461 notice, this list of conditions and the following disclaimer.
8462 2. Redistributions in binary form must reproduce the above
8463 copyright notice, this list of conditions and the following
8464 disclaimer in the documentation and/or other materials
8465 provided with the distribution.</code></pre>
8466 </div></div>
8467 <div class="literalblock">
8468 <div class="content">
8469 <pre><code>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
8470 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8471 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
8472 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
8473 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8474 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8475 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8476 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8477 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8478 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8479 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
8480 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</code></pre>
8481 </div></div>
8482 <div class="literalblock">
8483 <div class="content">
8484 <pre><code>The views and conclusions contained in the software and documentation
8485 are those of the authors and should not be interpreted as representing
8486 official policies, either expressed or implied, of the Jim Tcl Project.</code></pre>
8487 </div></div>
8488 </div>
8489 </div>
8490 </div>
8491 <div id="footnotes"><hr /></div>
8492 <div id="footer">
8493 <div id="footer-text">
8494 Last updated 2016-08-29 16:18:20 AEST
8495 </div>
8496 </div>
8497 </body>
8498 </html>