Update version to 0.76
[jimtcl.git] / Tcl_shipped.html
blob9bb32cdcf860a94fe234b89a9128e3a52daee032
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.76 -
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_75_and_0_76">Changes between 0.75 and 0.76</h3>
882 <div class="olist arabic"><ol class="arabic">
883 <li>
885 Add support for <a href="#_file"><strong><code>file</code></strong></a> <code>link</code>
886 </p>
887 </li>
888 <li>
890 <a href="#_glob"><strong><code>glob</code></strong></a> now supports the <em>--tails</em> option
891 </p>
892 </li>
893 <li>
895 Add support for <a href="#_string"><strong><code>string</code></strong></a> <code>cat</code>
896 </p>
897 </li>
898 <li>
900 Allow <a href="#_info"><strong><code>info</code></strong></a> <code>source</code> to add source info
901 </p>
902 </li>
903 </ol></div>
904 </div>
905 <div class="sect2">
906 <h3 id="_changes_between_0_74_and_0_75">Changes between 0.74 and 0.75</h3>
907 <div class="olist arabic"><ol class="arabic">
908 <li>
910 <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
911 </p>
912 </li>
913 <li>
915 <a href="#_file"><strong><code>file</code></strong></a> <code>copy</code> <em>-force</em> handles source and target as the same file
916 </p>
917 </li>
918 <li>
920 <a href="#_format"><strong><code>format</code></strong></a> now supports <code>%b</code> for binary conversion
921 </p>
922 </li>
923 <li>
925 <a href="#_lsort"><strong><code>lsort</code></strong></a> now supports <em>-unique</em> and <em>-real</em>
926 </p>
927 </li>
928 <li>
930 Add support for half-close with <a href="#_aio"><strong><code>aio</code></strong></a> <code>close</code> ?r|w?
931 </p>
932 </li>
933 <li>
935 Add <a href="#_socket"><strong><code>socket</code></strong></a> <code>pair</code> for a bidirectional pipe
936 </p>
937 </li>
938 <li>
940 Add <em>--random-hash</em> to randomise hash tables for greater security
941 </p>
942 </li>
943 <li>
945 <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>
946 </p>
947 </li>
948 <li>
950 <a href="#_file"><strong><code>file</code></strong></a> <code>stat</code> no longer requires the variable name
951 </p>
952 </li>
953 </ol></div>
954 </div>
955 <div class="sect2">
956 <h3 id="_changes_between_0_73_and_0_74">Changes between 0.73 and 0.74</h3>
957 <div class="olist arabic"><ol class="arabic">
958 <li>
960 Numbers with leading zeros are treated as decimal, not octal
961 </p>
962 </li>
963 <li>
965 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>isatty</code>
966 </p>
967 </li>
968 <li>
970 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>
971 </p>
972 </li>
973 <li>
975 <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>
976 </p>
977 </li>
978 <li>
980 <a href="#_glob"><strong><code>glob</code></strong></a> now supports <em>-directory</em>
981 </p>
982 </li>
983 </ol></div>
984 </div>
985 <div class="sect2">
986 <h3 id="_changes_between_0_72_and_0_73">Changes between 0.72 and 0.73</h3>
987 <div class="olist arabic"><ol class="arabic">
988 <li>
990 Built-in regexp now support non-capturing parentheses: (?:&#8230;)
991 </p>
992 </li>
993 <li>
995 Add <a href="#_string"><strong><code>string</code></strong></a> <code>replace</code>
996 </p>
997 </li>
998 <li>
1000 Add <a href="#_string"><strong><code>string</code></strong></a> <code>totitle</code>
1001 </p>
1002 </li>
1003 <li>
1005 Add <a href="#_info"><strong><code>info</code></strong></a> <code>statics</code>
1006 </p>
1007 </li>
1008 <li>
1010 Add <code>build-jim-ext</code> for easy separate building of loadable modules (extensions)
1011 </p>
1012 </li>
1013 <li>
1015 <a href="#_local"><strong><code>local</code></strong></a> now works with any command, not just procs
1016 </p>
1017 </li>
1018 <li>
1020 Add <a href="#_info"><strong><code>info</code></strong></a> <code>alias</code> to access the target of an alias
1021 </p>
1022 </li>
1023 <li>
1025 UTF-8 encoding past the basic multilingual plane (BMP) is supported
1026 </p>
1027 </li>
1028 <li>
1030 Add <a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a>
1031 </p>
1032 </li>
1033 <li>
1035 Add <a href="#_history"><strong><code>history</code></strong></a>
1036 </p>
1037 </li>
1038 <li>
1040 Most extensions are now enabled by default
1041 </p>
1042 </li>
1043 <li>
1045 Add support for namespaces and the <a href="#_namespace"><strong><code>namespace</code></strong></a> command
1046 </p>
1047 </li>
1048 <li>
1050 Add <a href="#_apply"><strong><code>apply</code></strong></a>
1051 </p>
1052 </li>
1053 </ol></div>
1054 </div>
1055 <div class="sect2">
1056 <h3 id="_changes_between_0_71_and_0_72">Changes between 0.71 and 0.72</h3>
1057 <div class="olist arabic"><ol class="arabic">
1058 <li>
1060 procs now allow <em>args</em> and optional parameters in any position
1061 </p>
1062 </li>
1063 <li>
1065 Add Tcl-compatible expr functions, <code>rand()</code>, <code>srand()</code> and <code>pow()</code>
1066 </p>
1067 </li>
1068 <li>
1070 Add support for the <em>-force</em> option to <a href="#_file"><strong><code>file</code></strong></a> <code>delete</code>
1071 </p>
1072 </li>
1073 <li>
1075 Better diagnostics when <a href="#_source"><strong><code>source</code></strong></a> fails to load a script with a missing quote or bracket
1076 </p>
1077 </li>
1078 <li>
1080 New <code>tcl_platform(pathSeparator)</code>
1081 </p>
1082 </li>
1083 <li>
1085 Add support settings the modification time with <a href="#_file"><strong><code>file</code></strong></a> <code>mtime</code>
1086 </p>
1087 </li>
1088 <li>
1090 <a href="#_exec"><strong><code>exec</code></strong></a> is now fully supported on win32 (mingw32)
1091 </p>
1092 </li>
1093 <li>
1095 <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
1096 </p>
1097 </li>
1098 <li>
1100 Line editing is now supported for the win32 console (mingw32)
1101 </p>
1102 </li>
1103 <li>
1105 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>listen</code> command
1106 </p>
1107 </li>
1108 </ol></div>
1109 </div>
1110 <div class="sect2">
1111 <h3 id="_changes_between_0_70_and_0_71">Changes between 0.70 and 0.71</h3>
1112 <div class="olist arabic"><ol class="arabic">
1113 <li>
1115 Allow <em>args</em> to be renamed in procs
1116 </p>
1117 </li>
1118 <li>
1120 Add <code>$(&#8230;)</code> shorthand syntax for expressions
1121 </p>
1122 </li>
1123 <li>
1125 Add automatic reference variables in procs with <code>&amp;var</code> syntax
1126 </p>
1127 </li>
1128 <li>
1130 Support <code>jimsh --version</code>
1131 </p>
1132 </li>
1133 <li>
1135 Additional variables in <code>tcl_platform()</code>
1136 </p>
1137 </li>
1138 <li>
1140 <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
1141 </p>
1142 </li>
1143 <li>
1145 Add <a href="#_loop"><strong><code>loop</code></strong></a> command (TclX compatible)
1146 </p>
1147 </li>
1148 <li>
1150 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>buffering</code> command
1151 </p>
1152 </li>
1153 <li>
1155 <a href="#_info"><strong><code>info</code></strong></a> <code>complete</code> can now return the missing character
1156 </p>
1157 </li>
1158 <li>
1160 <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
1161 </p>
1162 </li>
1163 <li>
1165 Add <a href="#_string"><strong><code>string</code></strong></a> <code>byterange</code>
1166 </p>
1167 </li>
1168 <li>
1170 Built-in regexp now support non-greedy repetition (*?, +?, ??)
1171 </p>
1172 </li>
1173 </ol></div>
1174 </div>
1175 </div>
1176 </div>
1177 <div class="sect1">
1178 <h2 id="_tcl_introduction">TCL INTRODUCTION</h2>
1179 <div class="sectionbody">
1180 <div class="paragraph"><p>Tcl stands for <em>tool command language</em> and is pronounced <em>tickle.</em>
1181 It is actually two things: a language and a library.</p></div>
1182 <div class="paragraph"><p>First, Tcl is a simple textual language, intended primarily for
1183 issuing commands to interactive programs such as text editors,
1184 debuggers, illustrators, and shells. It has a simple syntax and is also
1185 programmable, so Tcl users can write command procedures to provide more
1186 powerful commands than those in the built-in set.</p></div>
1187 <div class="paragraph"><p>Second, Tcl is a library package that can be embedded in application
1188 programs. The Tcl library consists of a parser for the Tcl language,
1189 routines to implement the Tcl built-in commands, and procedures that
1190 allow each application to extend Tcl with additional commands specific
1191 to that application. The application program generates Tcl commands and
1192 passes them to the Tcl parser for execution. Commands may be generated
1193 by reading characters from an input source, or by associating command
1194 strings with elements of the application&#8217;s user interface, such as menu
1195 entries, buttons, or keystrokes.</p></div>
1196 <div class="paragraph"><p>When the Tcl library receives commands it parses them into component
1197 fields and executes built-in commands directly. For commands implemented
1198 by the application, Tcl calls back to the application to execute the
1199 commands. In many cases commands will invoke recursive invocations of the
1200 Tcl interpreter by passing in additional strings to execute (procedures,
1201 looping commands, and conditional commands all work in this way).</p></div>
1202 <div class="paragraph"><p>An application program gains three advantages by using Tcl for its command
1203 language. First, Tcl provides a standard syntax: once users know Tcl,
1204 they will be able to issue commands easily to any Tcl-based application.
1205 Second, Tcl provides programmability. All a Tcl application needs
1206 to do is to implement a few application-specific low-level commands.
1207 Tcl provides many utility commands plus a general programming interface
1208 for building up complex command procedures. By using Tcl, applications
1209 need not re-implement these features.</p></div>
1210 <div class="paragraph"><p>Third, Tcl can be used as a common language for communicating between
1211 applications. Inter-application communication is not built into the
1212 Tcl core described here, but various add-on libraries, such as the Tk
1213 toolkit, allow applications to issue commands to each other. This makes
1214 it possible for applications to work together in much more powerful ways
1215 than was previously possible.</p></div>
1216 <div class="paragraph"><p>Fourth, Jim Tcl includes a command processor, <code>jimsh</code>, which can be
1217 used to run standalone Tcl scripts, or to run Tcl commands interactively.</p></div>
1218 <div class="paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
1219 the language syntax and the built-in commands that will be available
1220 in any application based on Tcl. The individual library procedures are
1221 described in more detail in separate manual pages, one per procedure.</p></div>
1222 </div>
1223 </div>
1224 <div class="sect1">
1225 <h2 id="_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER</h2>
1226 <div class="sectionbody">
1227 <div class="paragraph"><p>A simple, but powerful command processor, <code>jimsh</code>, is part of Jim Tcl.
1228 It may be invoked in interactive mode as:</p></div>
1229 <div class="literalblock">
1230 <div class="content">
1231 <pre><code>jimsh</code></pre>
1232 </div></div>
1233 <div class="paragraph"><p>or to process the Tcl script in a file with:</p></div>
1234 <div class="literalblock">
1235 <div class="content">
1236 <pre><code>jimsh filename</code></pre>
1237 </div></div>
1238 <div class="paragraph"><p>It may also be invoked to execute an immediate script with:</p></div>
1239 <div class="literalblock">
1240 <div class="content">
1241 <pre><code>jimsh -e "script"</code></pre>
1242 </div></div>
1243 <div class="sect2">
1244 <h3 id="_interactive_mode">Interactive Mode</h3>
1245 <div class="paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
1246 those commands and prints the results.</p></div>
1247 <div class="literalblock">
1248 <div class="content">
1249 <pre><code>$ jimsh
1250 Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
1251 . info version
1252 0.73
1253 . lsort [info commands p*]
1254 package parray pid popen proc puts pwd
1255 . foreach i {a b c} {
1256 {&gt; puts $i
1257 {&gt; }
1261 . bad
1262 invalid command name "bad"
1263 [error] . exit
1264 $</code></pre>
1265 </div></div>
1266 <div class="paragraph"><p>If <code>jimsh</code> is configured with line editing (it is by default) and a VT-100-compatible
1267 terminal is detected, Emacs-style line editing commands are available, including:
1268 arrow keys, <code>^W</code> to erase a word, <code>^U</code> to erase the line, <code>^R</code> for reverse incremental search
1269 in history. Additionally, the <code>h</code> command may be used to display the command history.</p></div>
1270 <div class="paragraph"><p>Command line history is automatically saved and loaded from <code>~/.jim_history</code></p></div>
1271 <div class="paragraph"><p>In interactive mode, <code>jimsh</code> automatically runs the script <code>~/.jimrc</code> at startup
1272 if it exists.</p></div>
1273 </div>
1274 </div>
1275 </div>
1276 <div class="sect1">
1277 <h2 id="_interpreters">INTERPRETERS</h2>
1278 <div class="sectionbody">
1279 <div class="paragraph"><p>The central data structure in Tcl is an interpreter (C type <em>Jim_Interp</em>).
1280 An interpreter consists of a set of command bindings, a set of variable
1281 values, and a few other miscellaneous pieces of state. Each Tcl command
1282 is interpreted in the context of a particular interpreter.</p></div>
1283 <div class="paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
1284 simultaneously, each associated with a different widget or portion of
1285 the application. Interpreters are relatively lightweight structures.
1286 They can be created and deleted quickly, so application programmers should
1287 feel free to use multiple interpreters if that simplifies the application.</p></div>
1288 </div>
1289 </div>
1290 <div class="sect1">
1291 <h2 id="_data_types">DATA TYPES</h2>
1292 <div class="sectionbody">
1293 <div class="paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
1294 to commands, all command results, and all variable values are strings.</p></div>
1295 <div class="paragraph"><p>Where commands require numeric arguments or return numeric results,
1296 the arguments and results are passed as strings. Many commands expect
1297 their string arguments to have certain formats, but this interpretation
1298 is up to the individual commands. For example, arguments often contain
1299 Tcl command strings, which may get executed as part of the commands.
1300 The easiest way to understand the Tcl interpreter is to remember that
1301 everything is just an operation on a string. In many cases Tcl constructs
1302 will look similar to more structured constructs from other languages.
1303 However, the Tcl constructs are not structured at all; they are just
1304 strings of characters, and this gives them a different behaviour than
1305 the structures they may look like.</p></div>
1306 <div class="paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
1307 the interpretation, there are three common forms that strings take:
1308 commands, expressions, and lists. The major sections below discuss
1309 these three forms in more detail.</p></div>
1310 </div>
1311 </div>
1312 <div class="sect1">
1313 <h2 id="_basic_command_syntax">BASIC COMMAND SYNTAX</h2>
1314 <div class="sectionbody">
1315 <div class="paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
1316 and Lisp. However, the interpretation of commands is different
1317 in Tcl than in either of those other two systems.
1318 A Tcl command string consists of one or more commands separated
1319 by newline characters or semi-colons.
1320 Each command consists of a collection of fields separated by
1321 white space (spaces or tabs).
1322 The first field must be the name of a command, and the
1323 additional fields, if any, are arguments that will be passed to
1324 that command. For example, the command:</p></div>
1325 <div class="literalblock">
1326 <div class="content">
1327 <pre><code>set a 22</code></pre>
1328 </div></div>
1329 <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
1330 the last two, <em>a</em> and <em>22</em>, will be passed as arguments to
1331 the <a href="#_set"><strong><code>set</code></strong></a> command. The command name may refer either to a built-in
1332 Tcl command, an application-specific command bound in with the library
1333 procedure <em>Jim_CreateCommand</em>, or a command procedure defined with the
1334 <a href="#_proc"><strong><code>proc</code></strong></a> built-in command.</p></div>
1335 <div class="paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1336 interpret those strings in any fashion they wish. The <a href="#_set"><strong><code>set</code></strong></a> command,
1337 for example, will treat its first argument as the name of a variable
1338 and its second argument as a string value to assign to that variable.
1339 For other commands arguments may be interpreted as integers, lists,
1340 file names, or Tcl commands.</p></div>
1341 <div class="paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1342 However, if the Tcl interpreter cannot locate a command it invokes a
1343 special command named <a href="#_unknown"><strong><code>unknown</code></strong></a> which attempts to find or create the
1344 command.</p></div>
1345 <div class="paragraph"><p>For example, at many sites <a href="#_unknown"><strong><code>unknown</code></strong></a> will search through library
1346 directories for the desired command and create it as a Tcl procedure if
1347 it is found. The <a href="#_unknown"><strong><code>unknown</code></strong></a> command often provides automatic completion
1348 of abbreviated commands, but usually only for commands that were typed
1349 interactively.</p></div>
1350 <div class="paragraph"><p>It&#8217;s probably a bad idea to use abbreviations in command scripts and
1351 other forms that will be re-used over time: changes to the command set
1352 may cause abbreviations to become ambiguous, resulting in scripts that
1353 no longer work.</p></div>
1354 </div>
1355 </div>
1356 <div class="sect1">
1357 <h2 id="_comments">COMMENTS</h2>
1358 <div class="sectionbody">
1359 <div class="paragraph"><p>If the first non-blank character in a command is <code>#</code>, then everything
1360 from the <code>#</code> up through the next newline character is treated as
1361 a comment and ignored. When comments are embedded inside nested
1362 commands (e.g. fields enclosed in braces) they must have properly-matched
1363 braces (this is necessary because when Tcl parses the top-level command
1364 it doesn&#8217;t yet know that the nested field will be used as a command so
1365 it cannot process the nested comment character as a comment).</p></div>
1366 </div>
1367 </div>
1368 <div class="sect1">
1369 <h2 id="_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES</h2>
1370 <div class="sectionbody">
1371 <div class="paragraph"><p>Normally each argument field ends at the next white space, but
1372 double-quotes may be used to create arguments with embedded space.</p></div>
1373 <div class="paragraph"><p>If an argument field begins with a double-quote, then the argument isn&#8217;t
1374 terminated by white space (including newlines) or a semi-colon (see below
1375 for information on semi-colons); instead it ends at the next double-quote
1376 character. The double-quotes are not included in the resulting argument.
1377 For example, the command</p></div>
1378 <div class="literalblock">
1379 <div class="content">
1380 <pre><code>set a "This is a single argument"</code></pre>
1381 </div></div>
1382 <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>
1383 <div class="paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1384 and backslash substitutions still occur, as described below. If the
1385 first character of a command field is not a quote, then quotes receive
1386 no special interpretation in the parsing of that field.</p></div>
1387 </div>
1388 </div>
1389 <div class="sect1">
1390 <h2 id="_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES</h2>
1391 <div class="sectionbody">
1392 <div class="paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1393 to quotes except for two differences. First, they nest; this makes them
1394 easier to use for complicated arguments like nested Tcl command strings.
1395 Second, the substitutions described below for commands, variables, and
1396 backslashes do <strong>not</strong> occur in arguments enclosed in braces, so braces
1397 can be used to prevent substitutions where they are undesirable.</p></div>
1398 <div class="paragraph"><p>If an argument field begins with a left brace, then the argument ends
1399 at the matching right brace. Tcl will strip off the outermost layer
1400 of braces and pass the information between the braces to the command
1401 without any further modification. For example, in the command</p></div>
1402 <div class="literalblock">
1403 <div class="content">
1404 <pre><code>set a {xyz a {b c d}}</code></pre>
1405 </div></div>
1406 <div class="paragraph"><p>the <a href="#_set"><strong><code>set</code></strong></a> command will receive two arguments: <em>a</em>
1407 and <em>xyz a {b c d}</em>.</p></div>
1408 <div class="paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1409 not be on the same line as the starting quote or brace; in this case
1410 the newline will be included in the argument field along with any other
1411 characters up to the matching brace or quote. For example, the <a href="#_eval"><strong><code>eval</code></strong></a>
1412 command takes one argument, which is a command string; <a href="#_eval"><strong><code>eval</code></strong></a> invokes
1413 the Tcl interpreter to execute the command string. The command</p></div>
1414 <div class="literalblock">
1415 <div class="content">
1416 <pre><code>eval {
1417 set a 22
1418 set b 33
1419 }</code></pre>
1420 </div></div>
1421 <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>
1422 <div class="paragraph"><p>If the first character of a command field is not a left
1423 brace, then neither left nor right
1424 braces in the field will be treated specially (except as part of
1425 variable substitution; see below).</p></div>
1426 </div>
1427 </div>
1428 <div class="sect1">
1429 <h2 id="_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS</h2>
1430 <div class="sectionbody">
1431 <div class="paragraph"><p>If an open bracket occurs in a field of a command, then command
1432 substitution occurs (except for fields enclosed in braces). All of the
1433 text up to the matching close bracket is treated as a Tcl command and
1434 executed immediately. Then the result of that command is substituted
1435 for the bracketed text. For example, consider the command</p></div>
1436 <div class="literalblock">
1437 <div class="content">
1438 <pre><code>set a [set b]</code></pre>
1439 </div></div>
1440 <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
1441 variable and <a href="#_set"><strong><code>set</code></strong></a> returns the contents of that variable. In this case,
1442 if variable <em>b</em> has the value <em>foo</em>, then the command above is equivalent
1443 to the command</p></div>
1444 <div class="literalblock">
1445 <div class="content">
1446 <pre><code>set a foo</code></pre>
1447 </div></div>
1448 <div class="paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1449 <em>b</em> has the value <em>foo</em> and the variable <em>c</em> has the value <em>gorp</em>,
1450 then the command</p></div>
1451 <div class="literalblock">
1452 <div class="content">
1453 <pre><code>set a xyz[set b].[set c]</code></pre>
1454 </div></div>
1455 <div class="paragraph"><p>is equivalent to the command</p></div>
1456 <div class="literalblock">
1457 <div class="content">
1458 <pre><code>set a xyzfoo.gorp</code></pre>
1459 </div></div>
1460 <div class="paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1461 or semi-colons in the usual fashion. In this case the value of the last
1462 command is used for substitution. For example, the command</p></div>
1463 <div class="literalblock">
1464 <div class="content">
1465 <pre><code>set a x[set b 22
1466 expr $b+2]x</code></pre>
1467 </div></div>
1468 <div class="paragraph"><p>is equivalent to the command</p></div>
1469 <div class="literalblock">
1470 <div class="content">
1471 <pre><code>set a x24x</code></pre>
1472 </div></div>
1473 <div class="paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1474 between them are not interpreted specially; they are passed through to
1475 the argument verbatim.</p></div>
1476 </div>
1477 </div>
1478 <div class="sect1">
1479 <h2 id="_variable_substitution_with">VARIABLE SUBSTITUTION WITH $</h2>
1480 <div class="sectionbody">
1481 <div class="paragraph"><p>The dollar sign (<code>$</code>) may be used as a special shorthand form for
1482 substituting variable values. If <code>$</code> appears in an argument that isn&#8217;t
1483 enclosed in braces then variable substitution will occur. The characters
1484 after the <code>$</code>, up to the first character that isn&#8217;t a number, letter,
1485 or underscore, are taken as a variable name and the string value of that
1486 variable is substituted for the name.</p></div>
1487 <div class="paragraph"><p>For example, if variable <em>foo</em> has the value <em>test</em>, then the command</p></div>
1488 <div class="literalblock">
1489 <div class="content">
1490 <pre><code>set a $foo.c</code></pre>
1491 </div></div>
1492 <div class="paragraph"><p>is equivalent to the command</p></div>
1493 <div class="literalblock">
1494 <div class="content">
1495 <pre><code>set a test.c</code></pre>
1496 </div></div>
1497 <div class="paragraph"><p>There are two special forms for variable substitution. If the next
1498 character after the name of the variable is an open parenthesis, then
1499 the variable is assumed to be an array name, and all of the characters
1500 between the open parenthesis and the next close parenthesis are taken as
1501 an index into the array. Command substitutions and variable substitutions
1502 are performed on the information between the parentheses before it is
1503 used as an index.</p></div>
1504 <div class="paragraph"><p>For example, if the variable <em>x</em> is an array with one element named
1505 <em>first</em> and value <em>87</em> and another element named <em>14</em> and value <em>more</em>,
1506 then the command</p></div>
1507 <div class="literalblock">
1508 <div class="content">
1509 <pre><code>set a xyz$x(first)zyx</code></pre>
1510 </div></div>
1511 <div class="paragraph"><p>is equivalent to the command</p></div>
1512 <div class="literalblock">
1513 <div class="content">
1514 <pre><code>set a xyz87zyx</code></pre>
1515 </div></div>
1516 <div class="paragraph"><p>If the variable <em>index</em> has the value <em>14</em>, then the command</p></div>
1517 <div class="literalblock">
1518 <div class="content">
1519 <pre><code>set a xyz$x($index)zyx</code></pre>
1520 </div></div>
1521 <div class="paragraph"><p>is equivalent to the command</p></div>
1522 <div class="literalblock">
1523 <div class="content">
1524 <pre><code>set a xyzmorezyx</code></pre>
1525 </div></div>
1526 <div class="paragraph"><p>For more information on arrays, see VARIABLES AND ARRAYS below.</p></div>
1527 <div class="paragraph"><p>The second special form for variables occurs when the dollar sign is
1528 followed by an open curly brace. In this case the variable name consists
1529 of all the characters up to the next curly brace.</p></div>
1530 <div class="paragraph"><p>Array references are not possible in this form: the name between braces
1531 is assumed to refer to a scalar variable. For example, if variable
1532 <em>foo</em> has the value <em>test</em>, then the command</p></div>
1533 <div class="literalblock">
1534 <div class="content">
1535 <pre><code>set a abc${foo}bar</code></pre>
1536 </div></div>
1537 <div class="paragraph"><p>is equivalent to the command</p></div>
1538 <div class="literalblock">
1539 <div class="content">
1540 <pre><code>set a abctestbar</code></pre>
1541 </div></div>
1542 <div class="paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1543 braces: the dollar sign and variable name are passed through to the
1544 argument verbatim.</p></div>
1545 <div class="paragraph"><p>The dollar sign abbreviation is simply a shorthand form. <code>$a</code> is
1546 completely equivalent to <code>[set a]</code>; it is provided as a convenience
1547 to reduce typing.</p></div>
1548 </div>
1549 </div>
1550 <div class="sect1">
1551 <h2 id="_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS</h2>
1552 <div class="sectionbody">
1553 <div class="paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1554 newline character). However, semi-colon (<code>;</code>) is treated as a command
1555 separator character; multiple commands may be placed on one line by
1556 separating them with a semi-colon. Semi-colons are not treated as
1557 command separators if they appear within curly braces or double-quotes.</p></div>
1558 </div>
1559 </div>
1560 <div class="sect1">
1561 <h2 id="_backslash_substitution">BACKSLASH SUBSTITUTION</h2>
1562 <div class="sectionbody">
1563 <div class="paragraph"><p>Backslashes may be used to insert non-printing characters into command
1564 fields and also to insert special characters like braces and brackets
1565 into fields without them being interpreted specially as described above.</p></div>
1566 <div class="paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1567 listed below. In each case, the backslash
1568 sequence is replaced by the given character:</p></div>
1569 <div class="dlist" id="BackslashSequences"><dl>
1570 <dt class="hdlist1">
1571 <code>\b</code>
1572 </dt>
1573 <dd>
1575 Backspace (0x8)
1576 </p>
1577 </dd>
1578 <dt class="hdlist1">
1579 <code>\f</code>
1580 </dt>
1581 <dd>
1583 Form feed (0xc)
1584 </p>
1585 </dd>
1586 <dt class="hdlist1">
1587 <code>\n</code>
1588 </dt>
1589 <dd>
1591 Newline (0xa)
1592 </p>
1593 </dd>
1594 <dt class="hdlist1">
1595 <code>\r</code>
1596 </dt>
1597 <dd>
1599 Carriage-return (0xd).
1600 </p>
1601 </dd>
1602 <dt class="hdlist1">
1603 <code>\t</code>
1604 </dt>
1605 <dd>
1607 Tab (0x9).
1608 </p>
1609 </dd>
1610 <dt class="hdlist1">
1611 <code>\v</code>
1612 </dt>
1613 <dd>
1615 Vertical tab (0xb).
1616 </p>
1617 </dd>
1618 <dt class="hdlist1">
1619 <code>\{</code>
1620 </dt>
1621 <dd>
1623 Left brace ({).
1624 </p>
1625 </dd>
1626 <dt class="hdlist1">
1627 <code>\}</code>
1628 </dt>
1629 <dd>
1631 Right brace (}).
1632 </p>
1633 </dd>
1634 <dt class="hdlist1">
1635 <code>\[</code>
1636 </dt>
1637 <dd>
1639 Open bracket ([).
1640 </p>
1641 </dd>
1642 <dt class="hdlist1">
1643 <code>\]</code>
1644 </dt>
1645 <dd>
1647 Close bracket (]).
1648 </p>
1649 </dd>
1650 <dt class="hdlist1">
1651 <code>\$</code>
1652 </dt>
1653 <dd>
1655 Dollar sign ($).
1656 </p>
1657 </dd>
1658 <dt class="hdlist1">
1659 <code>\&lt;space&gt;</code>
1660 </dt>
1661 <dd>
1663 Space ( ): doesn&#8217;t terminate argument.
1664 </p>
1665 </dd>
1666 <dt class="hdlist1">
1667 <code>\;</code>
1668 </dt>
1669 <dd>
1671 Semi-colon: doesn&#8217;t terminate command.
1672 </p>
1673 </dd>
1674 <dt class="hdlist1">
1675 <code>\"</code>
1676 </dt>
1677 <dd>
1679 Double-quote.
1680 </p>
1681 </dd>
1682 <dt class="hdlist1">
1683 <code>\&lt;newline&gt;</code>
1684 </dt>
1685 <dd>
1687 Nothing: this joins two lines together
1688 into a single line. This backslash feature is unique in that
1689 it will be applied even when the sequence occurs within braces.
1690 </p>
1691 </dd>
1692 <dt class="hdlist1">
1693 <code>\\</code>
1694 </dt>
1695 <dd>
1697 Backslash (<em>\</em>).
1698 </p>
1699 </dd>
1700 <dt class="hdlist1">
1701 <code>\ddd</code>
1702 </dt>
1703 <dd>
1705 The digits <code><em>ddd</em></code> (one, two, or three of them) give the octal value of
1706 the character. Note that Jim supports null characters in strings.
1707 </p>
1708 </dd>
1709 <dt class="hdlist1">
1710 <code>\unnnn</code>
1711 </dt>
1712 <dt class="hdlist1">
1713 <code>\u{nnn}</code>
1714 </dt>
1715 <dt class="hdlist1">
1716 <code>\Unnnnnnnn</code>
1717 </dt>
1718 <dd>
1720 The UTF-8 encoding of the unicode codepoint represented by the hex digits, <code><em>nnnn</em></code>, is inserted.
1721 The <em>u</em> form allows for one to four hex digits.
1722 The <em>U</em> form allows for one to eight hex digits.
1723 The <em>u{nnn}</em> form allows for one to eight hex digits, but makes it easier to insert
1724 characters UTF-8 characters which are followed by a hex digit.
1725 </p>
1726 </dd>
1727 </dl></div>
1728 <div class="paragraph"><p>For example, in the command</p></div>
1729 <div class="literalblock">
1730 <div class="content">
1731 <pre><code>set a \{x\[\ yz\141</code></pre>
1732 </div></div>
1733 <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>
1734 <div class="paragraph"><p>If a backslash is followed by something other than one of the options
1735 described above, then the backslash is transmitted to the argument
1736 field without any special processing, and the Tcl scanner continues
1737 normal processing with the next character. For example, in the
1738 command</p></div>
1739 <div class="literalblock">
1740 <div class="content">
1741 <pre><code>set \*a \\\{foo</code></pre>
1742 </div></div>
1743 <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
1744 argument will be <code>\{foo</code>.</p></div>
1745 <div class="paragraph"><p>If an argument is enclosed in braces, then backslash sequences inside
1746 the argument are parsed but no substitution occurs (except for
1747 backslash-newline): the backslash
1748 sequence is passed through to the argument as is, without making
1749 any special interpretation of the characters in the backslash sequence.
1750 In particular, backslashed braces are not counted in locating the
1751 matching right brace that terminates the argument.
1752 For example, in the
1753 command</p></div>
1754 <div class="literalblock">
1755 <div class="content">
1756 <pre><code>set a {\{abc}</code></pre>
1757 </div></div>
1758 <div class="paragraph"><p>the second argument to <a href="#_set"><strong><code>set</code></strong></a> will be <code>\{abc</code>.</p></div>
1759 <div class="paragraph"><p>This backslash mechanism is not sufficient to generate absolutely
1760 any argument structure; it only covers the
1761 most common cases. To produce particularly complicated arguments
1762 it is probably easiest to use the <a href="#_format"><strong><code>format</code></strong></a> command along with
1763 command substitution.</p></div>
1764 </div>
1765 </div>
1766 <div class="sect1">
1767 <h2 id="_string_and_list_index_specifications">STRING AND LIST INDEX SPECIFICATIONS</h2>
1768 <div class="sectionbody">
1769 <div class="paragraph"><p>Many string and list commands take one or more <em>index</em> parameters which
1770 specify a position in the string relative to the start or end of the string/list.</p></div>
1771 <div class="paragraph"><p>The index may be one of the following forms:</p></div>
1772 <div class="dlist"><dl>
1773 <dt class="hdlist1">
1774 <code>integer</code>
1775 </dt>
1776 <dd>
1778 A simple integer, where <em>0</em> refers to the first element of the string
1779 or list.
1780 </p>
1781 </dd>
1782 <dt class="hdlist1">
1783 <code>integer+integer</code> or
1784 </dt>
1785 <dt class="hdlist1">
1786 <code>integer-integer</code>
1787 </dt>
1788 <dd>
1790 The sum or difference of the two integers. e.g. <code>2+3</code> refers to the 5th element.
1791 This is useful when used with (e.g.) <code>$i+1</code> rather than the more verbose
1792 <code>[expr {$i+1}]</code>
1793 </p>
1794 </dd>
1795 <dt class="hdlist1">
1796 <code>end</code>
1797 </dt>
1798 <dd>
1800 The last element of the string or list.
1801 </p>
1802 </dd>
1803 <dt class="hdlist1">
1804 <code>end-integer</code>
1805 </dt>
1806 <dd>
1808 The <em>nth-from-last</em> element of the string or list.
1809 </p>
1810 </dd>
1811 </dl></div>
1812 </div>
1813 </div>
1814 <div class="sect1">
1815 <h2 id="_command_summary">COMMAND SUMMARY</h2>
1816 <div class="sectionbody">
1817 <div class="olist arabic"><ol class="arabic">
1818 <li>
1820 A command is just a string.
1821 </p>
1822 </li>
1823 <li>
1825 Within a string commands are separated by newlines or semi-colons
1826 (unless the newline or semi-colon is within braces or brackets
1827 or is backslashed).
1828 </p>
1829 </li>
1830 <li>
1832 A command consists of fields. The first field is the name of the command.
1833 The other fields are strings that are passed to that command as arguments.
1834 </p>
1835 </li>
1836 <li>
1838 Fields are normally separated by white space.
1839 </p>
1840 </li>
1841 <li>
1843 Double-quotes allow white space and semi-colons to appear within
1844 a single argument.
1845 Command substitution, variable substitution, and backslash substitution
1846 still occur inside quotes.
1847 </p>
1848 </li>
1849 <li>
1851 Braces defer interpretation of special characters.
1852 If a field begins with a left brace, then it consists of everything
1853 between the left brace and the matching right brace. The
1854 braces themselves are not included in the argument.
1855 No further processing is done on the information between the braces
1856 except that backslash-newline sequences are eliminated.
1857 </p>
1858 </li>
1859 <li>
1861 If a field doesn&#8217;t begin with a brace then backslash,
1862 variable, and command substitution are done on the field. Only a
1863 single level of processing is done: the results of one substitution
1864 are not scanned again for further substitutions or any other
1865 special treatment. Substitution can
1866 occur on any field of a command, including the command name
1867 as well as the arguments.
1868 </p>
1869 </li>
1870 <li>
1872 If the first non-blank character of a command is a <code>#</code>, everything
1873 from the <code>#</code> up through the next newline is treated as a comment
1874 and ignored.
1875 </p>
1876 </li>
1877 </ol></div>
1878 </div>
1879 </div>
1880 <div class="sect1">
1881 <h2 id="_expressions">EXPRESSIONS</h2>
1882 <div class="sectionbody">
1883 <div class="paragraph"><p>The second major interpretation applied to strings in Tcl is
1884 as expressions. Several commands, such as <a href="#_expr"><strong><code>expr</code></strong></a>, <a href="#_for"><strong><code>for</code></strong></a>,
1885 and <a href="#_if"><strong><code>if</code></strong></a>, treat one or more of their arguments as expressions
1886 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
1887 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
1888 <div class="paragraph"><p>The operators permitted in Tcl expressions are a subset of
1889 the operators permitted in C expressions, and they have the
1890 same meaning and precedence as the corresponding C operators.
1891 Expressions almost always yield numeric results
1892 (integer or floating-point values).
1893 For example, the expression</p></div>
1894 <div class="literalblock">
1895 <div class="content">
1896 <pre><code>8.2 + 6</code></pre>
1897 </div></div>
1898 <div class="paragraph"><p>evaluates to 14.2.</p></div>
1899 <div class="paragraph"><p>Tcl expressions differ from C expressions in the way that
1900 operands are specified, and in that Tcl expressions support
1901 non-numeric operands and string comparisons.</p></div>
1902 <div class="paragraph"><p>A Tcl expression consists of a combination of operands, operators,
1903 and parentheses.</p></div>
1904 <div class="paragraph"><p>White space may be used between the operands and operators and
1905 parentheses; it is ignored by the expression processor.
1906 Where possible, operands are interpreted as integer values.</p></div>
1907 <div class="paragraph"><p>Integer values may be specified in decimal (the normal case) or in
1908 hexadecimal (if the first two characters of the operand are <em>0x</em>).
1909 Note that Jim Tcl does <strong>not</strong> treat numbers with leading zeros as octal.</p></div>
1910 <div class="paragraph"><p>If an operand does not have one of the integer formats given
1911 above, then it is treated as a floating-point number if that is
1912 possible. Floating-point numbers may be specified in any of the
1913 ways accepted by an ANSI-compliant C compiler (except that the
1914 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
1915 most installations). For example, all of the
1916 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
1917 <div class="paragraph"><p>If no numeric interpretation is possible, then an operand is left
1918 as a string (and only a limited set of operators may be applied to
1919 it).</p></div>
1920 <div class="olist arabic"><ol class="arabic">
1921 <li>
1923 Operands may be specified in any of the following ways:
1924 </p>
1925 </li>
1926 <li>
1928 As a numeric value, either integer or floating-point.
1929 </p>
1930 </li>
1931 <li>
1933 As a Tcl variable, using standard <em>$</em> notation.
1934 The variable&#8217;s value will be used as the operand.
1935 </p>
1936 </li>
1937 <li>
1939 As a string enclosed in double-quotes.
1940 The expression parser will perform backslash, variable, and
1941 command substitutions on the information between the quotes,
1942 and use the resulting value as the operand
1943 </p>
1944 </li>
1945 <li>
1947 As a string enclosed in braces.
1948 The characters between the open brace and matching close brace
1949 will be used as the operand without any substitutions.
1950 </p>
1951 </li>
1952 <li>
1954 As a Tcl command enclosed in brackets.
1955 The command will be executed and its result will be used as
1956 the operand.
1957 </p>
1958 </li>
1959 </ol></div>
1960 <div class="paragraph"><p>Where substitutions occur above (e.g. inside quoted strings), they
1961 are performed by the expression processor.
1962 However, an additional layer of substitution may already have
1963 been performed by the command parser before the expression
1964 processor was called.</p></div>
1965 <div class="paragraph"><p>As discussed below, it is usually best to enclose expressions
1966 in braces to prevent the command parser from performing substitutions
1967 on the contents.</p></div>
1968 <div class="paragraph"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
1969 the value 3 and the variable <em>b</em> has the value 6. Then the expression
1970 on the left side of each of the lines below will evaluate to the value
1971 on the right side of the line:</p></div>
1972 <div class="literalblock">
1973 <div class="content">
1974 <pre><code>$a + 3.1 6.1
1975 2 + "$a.$b" 5.6
1976 4*[llength "6 2"] 8
1977 {word one} &lt; "word $a" 0</code></pre>
1978 </div></div>
1979 <div class="paragraph"><p>The valid operators are listed below, grouped in decreasing order
1980 of precedence:</p></div>
1981 <div class="dlist" id="OperatorPrecedence"><dl>
1982 <dt class="hdlist1">
1983 <code>int() double() round() abs(), rand(), srand()</code>
1984 </dt>
1985 <dd>
1987 Unary functions (except rand() which takes no arguments)
1988 </p>
1989 <div class="ulist"><ul>
1990 <li>
1992 <code><em>int()</em></code> converts the numeric argument to an integer by truncating down.
1993 </p>
1994 </li>
1995 <li>
1997 <code><em>double()</em></code> converts the numeric argument to floating point.
1998 </p>
1999 </li>
2000 <li>
2002 <code><em>round()</em></code> converts the numeric argument to the closest integer value.
2003 </p>
2004 </li>
2005 <li>
2007 <code><em>abs()</em></code> takes the absolute value of the numeric argument.
2008 </p>
2009 </li>
2010 <li>
2012 <code><em>rand()</em></code> takes the absolute value of the numeric argument.
2013 </p>
2014 </li>
2015 <li>
2017 <code><em>rand()</em></code> returns a pseudo-random floating-point value in the range (0,1).
2018 </p>
2019 </li>
2020 <li>
2022 <code><em>srand()</em></code> takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
2023 </p>
2024 </li>
2025 </ul></div>
2026 </dd>
2027 <dt class="hdlist1">
2028 <code>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</code>
2029 </dt>
2030 <dd>
2032 Unary math functions.
2033 If Jim is compiled with math support, these functions are available.
2034 </p>
2035 </dd>
2036 <dt class="hdlist1">
2037 <code>- + ~ !</code>
2038 </dt>
2039 <dd>
2041 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
2042 may be applied to string operands, and bit-wise NOT may be
2043 applied only to integers.
2044 </p>
2045 </dd>
2046 <dt class="hdlist1">
2047 <code>** pow(x,y)</code>
2048 </dt>
2049 <dd>
2051 Power. e.g. <em>x<sup>y</sup></em>. If Jim is compiled with math support, supports doubles and
2052 integers. Otherwise supports integers only. (Note that the math-function form
2053 has the same highest precedence)
2054 </p>
2055 </dd>
2056 <dt class="hdlist1">
2057 <code>* / %</code>
2058 </dt>
2059 <dd>
2061 Multiply, divide, remainder. None of these operands may be
2062 applied to string operands, and remainder may be applied only
2063 to integers.
2064 </p>
2065 </dd>
2066 <dt class="hdlist1">
2067 <code>+ -</code>
2068 </dt>
2069 <dd>
2071 Add and subtract. Valid for any numeric operands.
2072 </p>
2073 </dd>
2074 <dt class="hdlist1">
2075 <code>&lt;&lt; &gt;&gt; &lt;&lt;&lt; &gt;&gt;&gt;</code>
2076 </dt>
2077 <dd>
2079 Left and right shift, left and right rotate. Valid for integer operands only.
2080 </p>
2081 </dd>
2082 <dt class="hdlist1">
2083 <code>&lt; &gt; &lt;= &gt;=</code>
2084 </dt>
2085 <dd>
2087 Boolean less, greater, less than or equal, and greater than or equal.
2088 Each operator produces 1 if the condition is true, 0 otherwise.
2089 These operators may be applied to strings as well as numeric operands,
2090 in which case string comparison is used.
2091 </p>
2092 </dd>
2093 <dt class="hdlist1">
2094 <code>== !=</code>
2095 </dt>
2096 <dd>
2098 Boolean equal and not equal. Each operator produces a zero/one result.
2099 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
2100 if possible, then floating point types, and finally strings will be compared.
2101 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
2102 </p>
2103 </dd>
2104 <dt class="hdlist1">
2105 <code>eq ne</code>
2106 </dt>
2107 <dd>
2109 String equal and not equal. Uses the string value directly without
2110 attempting to convert to a number first.
2111 </p>
2112 </dd>
2113 <dt class="hdlist1">
2114 <code>in ni</code>
2115 </dt>
2116 <dd>
2118 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
2119 is contained in the right operand (as a list), or 0 otherwise. The result for
2120 <code>{$a ni $list}</code> is equivalent to <code>{!($a in $list)}</code>.
2121 </p>
2122 </dd>
2123 <dt class="hdlist1">
2124 <code>&amp;</code>
2125 </dt>
2126 <dd>
2128 Bit-wise AND. Valid for integer operands only.
2129 </p>
2130 </dd>
2131 <dt class="hdlist1">
2132 <code>|</code>
2133 </dt>
2134 <dd>
2136 Bit-wise OR. Valid for integer operands only.
2137 </p>
2138 </dd>
2139 <dt class="hdlist1">
2140 <code>^</code>
2141 </dt>
2142 <dd>
2144 Bit-wise exclusive OR. Valid for integer operands only.
2145 </p>
2146 </dd>
2147 <dt class="hdlist1">
2148 <code>&amp;&amp;</code>
2149 </dt>
2150 <dd>
2152 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
2153 Valid for numeric operands only (integers or floating-point).
2154 </p>
2155 </dd>
2156 <dt class="hdlist1">
2157 <code>||</code>
2158 </dt>
2159 <dd>
2161 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
2162 Valid for numeric operands only (integers or floating-point).
2163 </p>
2164 </dd>
2165 <dt class="hdlist1">
2166 <code>x ? y : z</code>
2167 </dt>
2168 <dd>
2170 If-then-else, as in C. If <code><em>x</em></code>
2171 evaluates to non-zero, then the result is the value of <code><em>y</em></code>.
2172 Otherwise the result is the value of <code><em>z</em></code>.
2173 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
2174 be of any type.
2175 </p>
2176 </dd>
2177 </dl></div>
2178 <div class="paragraph"><p>See the C manual for more details on the results
2179 produced by each operator.
2180 All of the binary operators group left-to-right within the same
2181 precedence level. For example, the expression</p></div>
2182 <div class="literalblock">
2183 <div class="content">
2184 <pre><code>4*2 &lt; 7</code></pre>
2185 </div></div>
2186 <div class="paragraph"><p>evaluates to 0.</p></div>
2187 <div class="paragraph"><p>The <code>&amp;&amp;</code>, <code>||</code>, and <code>?:</code> operators have <em>lazy evaluation</em>, just as
2188 in C, which means that operands are not evaluated if they are not
2189 needed to determine the outcome. For example, in</p></div>
2190 <div class="literalblock">
2191 <div class="content">
2192 <pre><code>$v ? [a] : [b]</code></pre>
2193 </div></div>
2194 <div class="paragraph"><p>only one of <code>[a]</code> or <code>[b]</code> will actually be evaluated,
2195 depending on the value of <code>$v</code>.</p></div>
2196 <div class="paragraph"><p>All internal computations involving integers are done with the C
2197 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
2198 computations involving floating-point are done with the C type
2199 <em>double</em>.</p></div>
2200 <div class="paragraph"><p>When converting a string to floating-point, exponent overflow is
2201 detected and results in a Tcl error.
2202 For conversion to integer from string, detection of overflow depends
2203 on the behaviour of some routines in the local C library, so it should
2204 be regarded as unreliable.
2205 In any case, overflow and underflow are generally not detected
2206 reliably for intermediate results.</p></div>
2207 <div class="paragraph"><p>Conversion among internal representations for integer, floating-point,
2208 and string operands is done automatically as needed.
2209 For arithmetic computations, integers are used until some
2210 floating-point number is introduced, after which floating-point is used.
2211 For example,</p></div>
2212 <div class="literalblock">
2213 <div class="content">
2214 <pre><code>5 / 4</code></pre>
2215 </div></div>
2216 <div class="paragraph"><p>yields the result 1, while</p></div>
2217 <div class="literalblock">
2218 <div class="content">
2219 <pre><code>5 / 4.0
2220 5 / ( [string length "abcd"] + 0.0 )</code></pre>
2221 </div></div>
2222 <div class="paragraph"><p>both yield the result 1.25.</p></div>
2223 <div class="paragraph"><p>String values may be used as operands of the comparison operators,
2224 although the expression evaluator tries to do comparisons as integer
2225 or floating-point when it can.
2226 If one of the operands of a comparison is a string and the other
2227 has a numeric value, the numeric operand is converted back to
2228 a string using the C <em>sprintf</em> format specifier
2229 <em>%d</em> for integers and <em>%g</em> for floating-point values.
2230 For example, the expressions</p></div>
2231 <div class="literalblock">
2232 <div class="content">
2233 <pre><code>"0x03" &gt; "2"
2234 "0y" &lt; "0x12"</code></pre>
2235 </div></div>
2236 <div class="paragraph"><p>both evaluate to 1. The first comparison is done using integer
2237 comparison, and the second is done using string comparison after
2238 the second operand is converted to the string <em>18</em>.</p></div>
2239 <div class="paragraph"><p>In general it is safest to enclose an expression in braces when
2240 entering it in a command: otherwise, if the expression contains
2241 any white space then the Tcl interpreter will split it
2242 among several arguments. For example, the command</p></div>
2243 <div class="literalblock">
2244 <div class="content">
2245 <pre><code>expr $a + $b</code></pre>
2246 </div></div>
2247 <div class="paragraph"><p>results in three arguments being passed to <a href="#_expr"><strong><code>expr</code></strong></a>: <code>$a</code>,
2248 +, and <code>$b</code>. In addition, if the expression isn&#8217;t in braces
2249 then the Tcl interpreter will perform variable and command substitution
2250 immediately (it will happen in the command parser rather than in
2251 the expression parser). In many cases the expression is being
2252 passed to a command that will evaluate the expression later (or
2253 even many times if, for example, the expression is to be used to
2254 decide when to exit a loop). Usually the desired goal is to re-do
2255 the variable or command substitutions each time the expression is
2256 evaluated, rather than once and for all at the beginning. For example,
2257 the command</p></div>
2258 <div class="literalblock">
2259 <div class="content">
2260 <pre><code>for {set i 1} $i&lt;=10 {incr i} {...} ** WRONG **</code></pre>
2261 </div></div>
2262 <div class="paragraph"><p>is probably intended to iterate over all values of <code>i</code> from 1 to 10.
2263 After each iteration of the body of the loop, <a href="#_for"><strong><code>for</code></strong></a> will pass
2264 its second argument to the expression evaluator to see whether or not
2265 to continue processing. Unfortunately, in this case the value of <code>i</code>
2266 in the second argument will be substituted once and for all when the
2267 <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>
2268 command was invoked then the second argument of <a href="#_for"><strong><code>for</code></strong></a> will be <code>0&lt;=10</code>
2269 which will always evaluate to 1, even though <code>i</code> eventually
2270 becomes greater than 10. In the above case the loop will never
2271 terminate. Instead, the expression should be placed in braces:</p></div>
2272 <div class="literalblock">
2273 <div class="content">
2274 <pre><code>for {set i 1} {$i&lt;=10} {incr i} {...} ** RIGHT **</code></pre>
2275 </div></div>
2276 <div class="paragraph"><p>This causes the substitution of <em>i</em>
2277 to be delayed; it will be re-done each time the expression is
2278 evaluated, which is the desired result.</p></div>
2279 </div>
2280 </div>
2281 <div class="sect1">
2282 <h2 id="_lists">LISTS</h2>
2283 <div class="sectionbody">
2284 <div class="paragraph"><p>The third major way that strings are interpreted in Tcl is as lists.
2285 A list is just a string with a list-like structure
2286 consisting of fields separated by white space. For example, the
2287 string</p></div>
2288 <div class="literalblock">
2289 <div class="content">
2290 <pre><code>Al Sue Anne John</code></pre>
2291 </div></div>
2292 <div class="paragraph"><p>is a list with four elements or fields.
2293 Lists have the same basic structure as command strings, except
2294 that a newline character in a list is treated as a field separator
2295 just like space or tab. Conventions for braces and quotes
2296 and backslashes are the same for lists as for commands. For example,
2297 the string</p></div>
2298 <div class="literalblock">
2299 <div class="content">
2300 <pre><code>a b\ c {d e {f g h}}</code></pre>
2301 </div></div>
2302 <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>
2303 <div class="paragraph"><p>Whenever an element is extracted from a list, the same rules about
2304 braces and quotes and backslashes are applied as for commands. Thus in
2305 the example above when the third element is extracted from the list,
2306 the result is</p></div>
2307 <div class="literalblock">
2308 <div class="content">
2309 <pre><code>d e {f g h}</code></pre>
2310 </div></div>
2311 <div class="paragraph"><p>(when the field was extracted, all that happened was to strip off
2312 the outermost layer of braces). Command substitution and
2313 variable substitution are never
2314 made on a list (at least, not by the list-processing commands; the
2315 list can always be passed to the Tcl interpreter for evaluation).</p></div>
2316 <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>,
2317 <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
2318 you to build lists, extract elements from them, search them, and perform
2319 other list-related functions.</p></div>
2320 <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>
2321 </div>
2322 </div>
2323 <div class="sect1">
2324 <h2 id="_list_expansion">LIST EXPANSION</h2>
2325 <div class="sectionbody">
2326 <div class="paragraph"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
2327 arguments. Support for this feature is also available in Jim.</p></div>
2328 <div class="paragraph"><p>Consider the following attempt to exec a list:</p></div>
2329 <div class="literalblock">
2330 <div class="content">
2331 <pre><code>set cmd {ls -l}
2332 exec $cmd</code></pre>
2333 </div></div>
2334 <div class="paragraph"><p>This will attempt to exec the a command named "ls -l", which will clearly not
2335 work. Typically eval and concat are required to solve this problem, however
2336 it can be solved much more easily with <code>{*}</code>.</p></div>
2337 <div class="literalblock">
2338 <div class="content">
2339 <pre><code>exec {*}$cmd</code></pre>
2340 </div></div>
2341 <div class="paragraph"><p>This will expand the following argument into individual elements and then evaluate
2342 the resulting command.</p></div>
2343 <div class="paragraph"><p>Note that the official Tcl syntax is <code>{*}</code>, however <code>{expand}</code> is retained
2344 for backward compatibility with experimental versions of this feature.</p></div>
2345 </div>
2346 </div>
2347 <div class="sect1">
2348 <h2 id="_regular_expressions">REGULAR EXPRESSIONS</h2>
2349 <div class="sectionbody">
2350 <div class="paragraph"><p>Tcl provides two commands that support string matching using regular
2351 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
2352 <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-regexp</code>.</p></div>
2353 <div class="paragraph"><p>Regular expressions may be implemented one of two ways. Either using the system&#8217;s C library
2354 POSIX regular expression support, or using the built-in regular expression engine.
2355 The differences between these are described below.</p></div>
2356 <div class="paragraph"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<code>ARE</code>).</p></div>
2357 <div class="sect2">
2358 <h3 id="_posix_regular_expressions">POSIX Regular Expressions</h3>
2359 <div class="paragraph"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
2360 this support will be used by default. The type of regular expressions supported are
2361 Extended Regular Expressions (<code>ERE</code>) rather than Basic Regular Expressions (<code>BRE</code>).
2362 See REG_EXTENDED in the documentation.</p></div>
2363 <div class="paragraph"><p>Using the system-supported POSIX regular expressions will typically
2364 make for the smallest code size, but some features such as UTF-8
2365 and <code>\w</code>, <code>\d</code>, <code>\s</code> are not supported, and null characters
2366 in strings are not supported.</p></div>
2367 <div class="paragraph"><p>See regex(3) and regex(7) for full details.</p></div>
2368 </div>
2369 <div class="sect2">
2370 <h3 id="_jim_built_in_regular_expressions">Jim built-in Regular Expressions</h3>
2371 <div class="paragraph"><p>The Jim built-in regular expression engine may be selected with <code>./configure --with-jim-regexp</code>
2372 or it will be selected automatically if UTF-8 support is enabled.</p></div>
2373 <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
2374 and POSIX are highlighted below.</p></div>
2375 <div class="olist arabic"><ol class="arabic">
2376 <li>
2378 UTF-8 strings and patterns are both supported
2379 </p>
2380 </li>
2381 <li>
2383 Supported character classes: <code>[:alnum:]</code>, <code>[:digit:]</code> and <code>[:space:]</code>
2384 </p>
2385 </li>
2386 <li>
2388 Supported shorthand character classes: <code>\w</code> = <code>[:alnum:]</code>, <code>\d</code> = <code>[:digit:],</code> <code>\s</code> = <code>[:space:]</code>
2389 </p>
2390 </li>
2391 <li>
2393 Character classes apply to ASCII characters only
2394 </p>
2395 </li>
2396 <li>
2398 Supported constraint escapes: <code>\m</code> = <code>\&lt;</code> = start of word, <code>\M</code> = <code>\&gt;</code> = end of word
2399 </p>
2400 </li>
2401 <li>
2403 Backslash escapes may be used within regular expressions, such as <code>\n</code> = newline, <code>\uNNNN</code> = unicode
2404 </p>
2405 </li>
2406 <li>
2408 Support for the <code>?</code> non-greedy quantifier. e.g. <code>*?</code>
2409 </p>
2410 </li>
2411 <li>
2413 Support for non-capuring parentheses <code>(?:&#8230;)</code>
2414 </p>
2415 </li>
2416 <li>
2418 Jim Tcl considers that both patterns and strings end at a null character (<code>\x00</code>)
2419 </p>
2420 </li>
2421 </ol></div>
2422 </div>
2423 </div>
2424 </div>
2425 <div class="sect1">
2426 <h2 id="_command_results">COMMAND RESULTS</h2>
2427 <div class="sectionbody">
2428 <div class="paragraph"><p>Each command produces two results: a code and a string. The
2429 code indicates whether the command completed successfully or not,
2430 and the string gives additional information. The valid codes are
2431 defined in jim.h, and are:</p></div>
2432 <div class="dlist"><dl>
2433 <dt class="hdlist1">
2434 <code>JIM_OK(0)</code>
2435 </dt>
2436 <dd>
2438 This is the normal return code, and indicates that the command completed
2439 successfully. The string gives the command&#8217;s return value.
2440 </p>
2441 </dd>
2442 <dt class="hdlist1">
2443 <code>JIM_ERR(1)</code>
2444 </dt>
2445 <dd>
2447 Indicates that an error occurred; the string gives a message describing
2448 the error.
2449 </p>
2450 </dd>
2451 <dt class="hdlist1">
2452 <code>JIM_RETURN(2)</code>
2453 </dt>
2454 <dd>
2456 Indicates that the <a href="#_return"><strong><code>return</code></strong></a> command has been invoked, and that the
2457 current procedure (or top-level command or <a href="#_source"><strong><code>source</code></strong></a> command)
2458 should return immediately. The
2459 string gives the return value for the procedure or command.
2460 </p>
2461 </dd>
2462 <dt class="hdlist1">
2463 <code>JIM_BREAK(3)</code>
2464 </dt>
2465 <dd>
2467 Indicates that the <a href="#_break"><strong><code>break</code></strong></a> command has been invoked, so the
2468 innermost loop should abort immediately. The string should always
2469 be empty.
2470 </p>
2471 </dd>
2472 <dt class="hdlist1">
2473 <code>JIM_CONTINUE(4)</code>
2474 </dt>
2475 <dd>
2477 Indicates that the <a href="#_continue"><strong><code>continue</code></strong></a> command has been invoked, so the
2478 innermost loop should go on to the next iteration. The string
2479 should always be empty.
2480 </p>
2481 </dd>
2482 <dt class="hdlist1">
2483 <code>JIM_SIGNAL(5)</code>
2484 </dt>
2485 <dd>
2487 Indicates that a signal was caught while executing a commands.
2488 The string contains the name of the signal caught.
2489 See the <a href="#_signal"><strong><code>signal</code></strong></a> and <a href="#_catch"><strong><code>catch</code></strong></a> commands.
2490 </p>
2491 </dd>
2492 <dt class="hdlist1">
2493 <code>JIM_EXIT(6)</code>
2494 </dt>
2495 <dd>
2497 Indicates that the command called the <a href="#_exit"><strong><code>exit</code></strong></a> command.
2498 The string contains the exit code.
2499 </p>
2500 </dd>
2501 </dl></div>
2502 <div class="paragraph"><p>Tcl programmers do not normally need to think about return codes,
2503 since <code>JIM_OK</code> is almost always returned. If anything else is returned
2504 by a command, then the Tcl interpreter immediately stops processing
2505 commands and returns to its caller. If there are several nested
2506 invocations of the Tcl interpreter in progress, then each nested
2507 command will usually return the error to its caller, until eventually
2508 the error is reported to the top-level application code. The
2509 application will then display the error message for the user.</p></div>
2510 <div class="paragraph"><p>In a few cases, some commands will handle certain <a href="#_error"><strong><code>error</code></strong></a> conditions
2511 themselves and not return them upwards. For example, the <a href="#_for"><strong><code>for</code></strong></a>
2512 command checks for the <code>JIM_BREAK</code> code; if it occurs, then <a href="#_for"><strong><code>for</code></strong></a>
2513 stops executing the body of the loop and returns <code>JIM_OK</code> to its
2514 caller. The <a href="#_for"><strong><code>for</code></strong></a> command also handles <code>JIM_CONTINUE</code> codes and the
2515 procedure interpreter handles <code>JIM_RETURN</code> codes. The <a href="#_catch"><strong><code>catch</code></strong></a>
2516 command allows Tcl programs to catch errors and handle them without
2517 aborting command interpretation any further.</p></div>
2518 <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
2519 return codes and names.</p></div>
2520 </div>
2521 </div>
2522 <div class="sect1">
2523 <h2 id="_procedures">PROCEDURES</h2>
2524 <div class="sectionbody">
2525 <div class="paragraph"><p>Tcl allows you to extend the command interface by defining
2526 procedures. A Tcl procedure can be invoked just like any other Tcl
2527 command (it has a name and it receives one or more arguments).
2528 The only difference is that its body isn&#8217;t a piece of C code linked
2529 into the program; it is a string containing one or more other
2530 Tcl commands.</p></div>
2531 <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>
2532 <div class="paragraph"><p><code><strong>proc</strong> <em>name arglist ?statics? body</em></code></p></div>
2533 <div class="paragraph"><p>The new command is named <code><em>name</em></code>, and it replaces any existing command
2534 there may have been by that name. Whenever the new command is
2535 invoked, the contents of <code><em>body</em></code> will be executed by the Tcl
2536 interpreter.</p></div>
2537 <div class="paragraph"><p><code><em>arglist</em></code> specifies the formal arguments to the procedure.
2538 It consists of a list, possibly empty, of the following
2539 argument specifiers:</p></div>
2540 <div class="dlist"><dl>
2541 <dt class="hdlist1">
2542 <code>name</code>
2543 </dt>
2544 <dd>
2546 Required Argument - A simple argument name.
2547 </p>
2548 </dd>
2549 <dt class="hdlist1">
2550 <code>name default</code>
2551 </dt>
2552 <dd>
2554 Optional Argument - A two-element list consisting of the
2555 argument name, followed by the default value, which will
2556 be used if the corresponding argument is not supplied.
2557 </p>
2558 </dd>
2559 <dt class="hdlist1">
2560 <code>&amp;name</code>
2561 </dt>
2562 <dd>
2564 Reference Argument - The caller is expected to pass the name of
2565 an existing variable. An implicit <a href="#_upvar"><strong><code>upvar</code></strong></a> <code>1 'origname' 'name'</code> is done
2566 to make the variable available in the proc scope.
2567 </p>
2568 </dd>
2569 <dt class="hdlist1">
2570 <code><strong>args</strong></code>
2571 </dt>
2572 <dd>
2574 Variable Argument - The special name <code><em>args</em></code>, which is
2575 assigned all remaining arguments (including none) as a list. The
2576 variable argument may only be specified once. Note that
2577 the syntax <code>args newname</code> may be used to retain the special
2578 behaviour of <code><em>args</em></code> with a different local name. In this case,
2579 the variable is named <code><em>newname</em></code> rather than <code><em>args</em></code>.
2580 </p>
2581 </dd>
2582 </dl></div>
2583 <div class="paragraph"><p>When the command is invoked, a local variable will be created for each of
2584 the formal arguments to the procedure; its value will be the value
2585 of corresponding argument in the invoking command or the argument&#8217;s
2586 default value.</p></div>
2587 <div class="paragraph"><p>Arguments with default values need not be specified in a procedure
2588 invocation. However, there must be enough actual arguments for all
2589 required arguments, and there must not be any extra actual arguments
2590 (unless the Variable Argument is specified).</p></div>
2591 <div class="paragraph"><p>Actual arguments are assigned to formal arguments as in left-to-right
2592 order with the following precedence.</p></div>
2593 <div class="olist arabic"><ol class="arabic">
2594 <li>
2596 Required Arguments (including Reference Arguments)
2597 </p>
2598 </li>
2599 <li>
2601 Optional Arguments
2602 </p>
2603 </li>
2604 <li>
2606 Variable Argument
2607 </p>
2608 </li>
2609 </ol></div>
2610 <div class="paragraph"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2611 <div class="literalblock">
2612 <div class="content">
2613 <pre><code>proc p {{a A} args b {c C} d} {...}</code></pre>
2614 </div></div>
2615 <div class="paragraph"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2616 The following table shows how various numbers of arguments are assigned.
2617 Values marked as <code>-</code> are assigned the default value.</p></div>
2618 <div class="tableblock">
2619 <table rules="all"
2620 width="40%"
2621 frame="hsides"
2622 cellspacing="0" cellpadding="4">
2623 <col width="16%" />
2624 <col width="16%" />
2625 <col width="16%" />
2626 <col width="16%" />
2627 <col width="16%" />
2628 <col width="16%" />
2629 <thead>
2630 <tr>
2631 <th align="left" valign="top">Number of arguments</th>
2632 <th align="left" valign="top">a</th>
2633 <th align="left" valign="top">args</th>
2634 <th align="left" valign="top">b</th>
2635 <th align="left" valign="top">c</th>
2636 <th align="left" valign="top">d</th>
2637 </tr>
2638 </thead>
2639 <tbody>
2640 <tr>
2641 <td align="left" valign="top"><p class="table">2</p></td>
2642 <td align="left" valign="top"><p class="table">-</p></td>
2643 <td align="left" valign="top"><p class="table">-</p></td>
2644 <td align="left" valign="top"><p class="table">1</p></td>
2645 <td align="left" valign="top"><p class="table">-</p></td>
2646 <td align="left" valign="top"><p class="table">2</p></td>
2647 </tr>
2648 <tr>
2649 <td align="left" valign="top"><p class="table">3</p></td>
2650 <td align="left" valign="top"><p class="table">1</p></td>
2651 <td align="left" valign="top"><p class="table">-</p></td>
2652 <td align="left" valign="top"><p class="table">2</p></td>
2653 <td align="left" valign="top"><p class="table">-</p></td>
2654 <td align="left" valign="top"><p class="table">3</p></td>
2655 </tr>
2656 <tr>
2657 <td align="left" valign="top"><p class="table">4</p></td>
2658 <td align="left" valign="top"><p class="table">1</p></td>
2659 <td align="left" valign="top"><p class="table">-</p></td>
2660 <td align="left" valign="top"><p class="table">2</p></td>
2661 <td align="left" valign="top"><p class="table">3</p></td>
2662 <td align="left" valign="top"><p class="table">4</p></td>
2663 </tr>
2664 <tr>
2665 <td align="left" valign="top"><p class="table">5</p></td>
2666 <td align="left" valign="top"><p class="table">1</p></td>
2667 <td align="left" valign="top"><p class="table">2</p></td>
2668 <td align="left" valign="top"><p class="table">3</p></td>
2669 <td align="left" valign="top"><p class="table">4</p></td>
2670 <td align="left" valign="top"><p class="table">5</p></td>
2671 </tr>
2672 <tr>
2673 <td align="left" valign="top"><p class="table">6</p></td>
2674 <td align="left" valign="top"><p class="table">1</p></td>
2675 <td align="left" valign="top"><p class="table">2,3</p></td>
2676 <td align="left" valign="top"><p class="table">4</p></td>
2677 <td align="left" valign="top"><p class="table">5</p></td>
2678 <td align="left" valign="top"><p class="table">6</p></td>
2679 </tr>
2680 </tbody>
2681 </table>
2682 </div>
2683 <div class="paragraph"><p>When <code><em>body</em></code> is being executed, variable names normally refer to local
2684 variables, which are created automatically when referenced and deleted
2685 when the procedure returns. One local variable is automatically created
2686 for each of the procedure&#8217;s arguments. Global variables can be
2687 accessed by invoking the <a href="#_global"><strong><code>global</code></strong></a> command or via the <code>::</code> prefix.</p></div>
2688 <div class="sect2">
2689 <h3 id="_new_in_jim">New in Jim</h3>
2690 <div class="paragraph"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2691 These variables scoped to the procedure and initialised at procedure definition.
2692 Either from the static variable definition, or from the enclosing scope.</p></div>
2693 <div class="paragraph"><p>Consider the following example:</p></div>
2694 <div class="literalblock">
2695 <div class="content">
2696 <pre><code>jim&gt; set a 1
2697 jim&gt; proc a {} {a {b 2}} {
2698 set c 1
2699 puts "$a $b $c"
2700 incr a
2701 incr b
2702 incr c
2704 jim&gt; a
2705 1 2 1
2706 jim&gt; a
2707 2 3 1</code></pre>
2708 </div></div>
2709 <div class="paragraph"><p>The static variable <code><em>a</em></code> has no initialiser, so it is initialised from
2710 the enclosing scope with the value 1. (Note that it is an error if there
2711 is no variable with the same name in the enclosing scope). However <code><em>b</em></code>
2712 has an initialiser, so it is initialised to 2.</p></div>
2713 <div class="paragraph"><p>Unlike a local variable, the value of a static variable is retained across
2714 invocations of the procedure.</p></div>
2715 <div class="paragraph"><p>See the <a href="#_proc"><strong><code>proc</code></strong></a> command for information on how to define procedures
2716 and what happens when they are invoked. See also NAMESPACES.</p></div>
2717 </div>
2718 </div>
2719 </div>
2720 <div class="sect1">
2721 <h2 id="_variables_scalars_and_arrays">VARIABLES - SCALARS AND ARRAYS</h2>
2722 <div class="sectionbody">
2723 <div class="paragraph"><p>Tcl allows the definition of variables and the use of their values
2724 either through <em>$</em>-style variable substitution, the <a href="#_set"><strong><code>set</code></strong></a>
2725 command, or a few other mechanisms.</p></div>
2726 <div class="paragraph"><p>Variables need not be declared: a new variable will automatically
2727 be created each time a new variable name is used.</p></div>
2728 <div class="paragraph"><p>Tcl supports two types of variables: scalars and arrays.
2729 A scalar variable has a single value, whereas an array variable
2730 can have any number of elements, each with a name (called
2731 its <em>index</em>) and a value.</p></div>
2732 <div class="paragraph"><p>Array indexes may be arbitrary strings; they need not be numeric.
2733 Parentheses are used refer to array elements in Tcl commands.
2734 For example, the command</p></div>
2735 <div class="literalblock">
2736 <div class="content">
2737 <pre><code>set x(first) 44</code></pre>
2738 </div></div>
2739 <div class="paragraph"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2740 so that its new value is <em>44</em>.</p></div>
2741 <div class="paragraph"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2742 that contain multiple concatenated values.
2743 For example, the commands</p></div>
2744 <div class="literalblock">
2745 <div class="content">
2746 <pre><code>set a(2,3) 1
2747 set a(3,6) 2</code></pre>
2748 </div></div>
2749 <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>
2750 <div class="paragraph"><p>In general, array elements may be used anywhere in Tcl that scalar
2751 variables may be used.</p></div>
2752 <div class="paragraph"><p>If an array is defined with a particular name, then there may
2753 not be a scalar variable with the same name.</p></div>
2754 <div class="paragraph"><p>Similarly, if there is a scalar variable with a particular
2755 name then it is not possible to make array references to the
2756 variable.</p></div>
2757 <div class="paragraph"><p>To convert a scalar variable to an array or vice versa, remove
2758 the existing variable with the <a href="#_unset"><strong><code>unset</code></strong></a> command.</p></div>
2759 <div class="paragraph"><p>The <a href="#_array"><strong><code>array</code></strong></a> command provides several features for dealing
2760 with arrays, such as querying the names of all the elements of
2761 the array and converting between an array and a list.</p></div>
2762 <div class="paragraph"><p>Variables may be either global or local. If a variable
2763 name is used when a procedure isn&#8217;t being executed, then it
2764 automatically refers to a global variable. Variable names used
2765 within a procedure normally refer to local variables associated with that
2766 invocation of the procedure. Local variables are deleted whenever
2767 a procedure exits. Either <a href="#_global"><strong><code>global</code></strong></a> command may be used to request
2768 that a name refer to a global variable for the duration of the current
2769 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2770 may be explicitly scoped with the <code>::</code> prefix. For example</p></div>
2771 <div class="literalblock">
2772 <div class="content">
2773 <pre><code>set a 1
2774 set b 2
2775 proc p {} {
2776 set c 3
2777 global a</code></pre>
2778 </div></div>
2779 <div class="literalblock">
2780 <div class="content">
2781 <pre><code> puts "$a $::b $c"
2783 p</code></pre>
2784 </div></div>
2785 <div class="paragraph"><p>will output:</p></div>
2786 <div class="literalblock">
2787 <div class="content">
2788 <pre><code>1 2 3</code></pre>
2789 </div></div>
2790 </div>
2791 </div>
2792 <div class="sect1">
2793 <h2 id="_arrays_as_lists_in_jim">ARRAYS AS LISTS IN JIM</h2>
2794 <div class="sectionbody">
2795 <div class="paragraph"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2796 number of elements) and an array value. This is similar to the way Tcl
2797 can convert between a string and a list.</p></div>
2798 <div class="paragraph"><p>For example:</p></div>
2799 <div class="literalblock">
2800 <div class="content">
2801 <pre><code>set a {1 one 2 two}
2802 puts $a(2)</code></pre>
2803 </div></div>
2804 <div class="paragraph"><p>will output:</p></div>
2805 <div class="literalblock">
2806 <div class="content">
2807 <pre><code>two</code></pre>
2808 </div></div>
2809 <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
2810 exist or is empty.</p></div>
2811 <div class="paragraph"><p>The reverse is also true where an array will be converted into
2812 a list.</p></div>
2813 <div class="literalblock">
2814 <div class="content">
2815 <pre><code>set a(1) one; set a(2) two
2816 puts $a</code></pre>
2817 </div></div>
2818 <div class="paragraph"><p>will output:</p></div>
2819 <div class="literalblock">
2820 <div class="content">
2821 <pre><code>1 one 2 two</code></pre>
2822 </div></div>
2823 </div>
2824 </div>
2825 <div class="sect1">
2826 <h2 id="_dictionary_values">DICTIONARY VALUES</h2>
2827 <div class="sectionbody">
2828 <div class="paragraph"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2829 of this command. Dictionaries provide efficient access to key-value
2830 pairs, just like arrays, but dictionaries are pure values. This
2831 means that you can pass them to a procedure just as a list or a
2832 string. Tcl dictionaries are therefore much more like Tcl lists,
2833 except that they represent a mapping from keys to values, rather
2834 than an ordered sequence.</p></div>
2835 <div class="paragraph"><p>You can nest dictionaries, so that the value for a particular key
2836 consists of another dictionary. That way you can elegantly build
2837 complicated data structures, such as hierarchical databases. You
2838 can also combine dictionaries with other Tcl data structures. For
2839 instance, you can build a list of dictionaries that themselves
2840 contain lists.</p></div>
2841 <div class="paragraph"><p>Dictionaries are values that contain an efficient, order-preserving
2842 mapping from arbitrary keys to arbitrary values. Each key in the
2843 dictionary maps to a single value. They have a textual format that
2844 is exactly that of any list with an even number of elements, with
2845 each mapping in the dictionary being represented as two items in
2846 the list. When a command takes a dictionary and produces a new
2847 dictionary based on it (either returning it or writing it back into
2848 the variable that the starting dictionary was read from) the new
2849 dictionary will have the same order of keys, modulo any deleted
2850 keys and with new keys added on to the end. When a string is
2851 interpreted as a dictionary and it would otherwise have duplicate
2852 keys, only the last value for a particular key is used; the others
2853 are ignored, meaning that, "apple banana" and "apple carrot apple
2854 banana" are equivalent dictionaries (with different string
2855 representations).</p></div>
2856 <div class="paragraph"><p>Note that in Jim, arrays are implemented as dictionaries.
2857 Thus automatic conversion between lists and dictionaries applies
2858 as it does for arrays.</p></div>
2859 <div class="literalblock">
2860 <div class="content">
2861 <pre><code>jim&gt; dict set a 1 one
2862 1 one
2863 jim&gt; dict set a 2 two
2864 1 one 2 two
2865 jim&gt; puts $a
2866 1 one 2 two
2867 jim&gt; puts $a(2)
2869 jim&gt; dict set a 3 T three
2870 1 one 2 two 3 {T three}</code></pre>
2871 </div></div>
2872 <div class="paragraph"><p>See the <a href="#_dict"><strong><code>dict</code></strong></a> command for more details.</p></div>
2873 </div>
2874 </div>
2875 <div class="sect1">
2876 <h2 id="_namespaces">NAMESPACES</h2>
2877 <div class="sectionbody">
2878 <div class="paragraph"><p>Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
2879 including a number of 3rd party components. While there is less need for namespaces
2880 in Jim Tcl (which does not strive to support large applications), it is convenient to
2881 provide a subset of the support for namespaces to easy porting code from Tcl.</p></div>
2882 <div class="paragraph"><p>Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
2883 purposes. This feature is currently experimental. See README.namespaces for more information
2884 and the documentation of the <a href="#_namespace"><strong><code>namespace</code></strong></a> command.</p></div>
2885 </div>
2886 </div>
2887 <div class="sect1">
2888 <h2 id="_garbage_collection_references_lambda">GARBAGE COLLECTION, REFERENCES, LAMBDA</h2>
2889 <div class="sectionbody">
2890 <div class="paragraph"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
2891 These are described briefly below.</p></div>
2892 <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>
2893 <div class="sect2">
2894 <h3 id="_references">References</h3>
2895 <div class="paragraph"><p>A reference can be thought of as holding a value with one level of indirection,
2896 where the value may be garbage collected when unreferenced.
2897 Consider the following example:</p></div>
2898 <div class="literalblock">
2899 <div class="content">
2900 <pre><code>jim&gt; set r [ref "One String" test]
2901 &lt;reference.&lt;test___&gt;.00000000000000000000&gt;
2902 jim&gt; getref $r
2903 One String</code></pre>
2904 </div></div>
2905 <div class="paragraph"><p>The operation <a href="#_ref"><strong><code>ref</code></strong></a> creates a references to the value specified by the
2906 first argument. (The second argument is a "type" used for documentation purposes).</p></div>
2907 <div class="paragraph"><p>The operation <a href="#_getref"><strong><code>getref</code></strong></a> is the dereferencing operation which retrieves the value
2908 stored in the reference.</p></div>
2909 <div class="literalblock">
2910 <div class="content">
2911 <pre><code>jim&gt; setref $r "New String"
2912 New String
2913 jim&gt; getref $r
2914 New String</code></pre>
2915 </div></div>
2916 <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
2917 is no longer accessible by any reference, it will eventually be automatically be garbage
2918 collected.</p></div>
2919 </div>
2920 <div class="sect2">
2921 <h3 id="_garbage_collection">Garbage Collection</h3>
2922 <div class="paragraph"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
2923 automatically as necessary.</p></div>
2924 <div class="paragraph"><p>With the introduction of references, it is possible to create values whose lifetime
2925 transcend their scope. To support this, case, the Jim system will periodically identify
2926 and discard objects which are no longer accessible by any reference.</p></div>
2927 <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
2928 with a finalizer:</p></div>
2929 <div class="literalblock">
2930 <div class="content">
2931 <pre><code>jim&gt; proc f {ref value} { puts "Finaliser called for $ref,$value" }
2932 jim&gt; set r [ref "One String" test f]
2933 &lt;reference.&lt;test___&gt;.00000000000
2934 jim&gt; collect
2936 jim&gt; set r ""
2937 jim&gt; collect
2938 Finaliser called for &lt;reference.&lt;test___&gt;.00000000000,One String
2939 1</code></pre>
2940 </div></div>
2941 <div class="paragraph"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
2942 contained a reference to the value, the garbage collector discarded
2943 the value (after calling the finalizer).</p></div>
2944 <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>
2945 <div class="literalblock">
2946 <div class="content">
2947 <pre><code>jim&gt; finalize $r
2949 jim&gt; finalize $r newf
2950 newf</code></pre>
2951 </div></div>
2952 </div>
2953 <div class="sect2">
2954 <h3 id="_lambda">Lambda</h3>
2955 <div class="paragraph"><p>Jim provides a garbage collected lambda function. This is a procedure
2956 which is able to create an anonymous procedure. Consider:</p></div>
2957 <div class="literalblock">
2958 <div class="content">
2959 <pre><code>jim&gt; set f [lambda {a} {{x 0}} { incr x $a }]
2960 jim&gt; $f 1
2962 jim&gt; $f 2
2964 jim&gt; set f ""</code></pre>
2965 </div></div>
2966 <div class="paragraph"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
2967 which is incremented by the supplied value and the result returned.</p></div>
2968 <div class="paragraph"><p>Once the procedure name is no longer accessible, it will automatically be deleted
2969 when the garbage collector runs.</p></div>
2970 <div class="paragraph"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
2971 <div class="literalblock">
2972 <div class="content">
2973 <pre><code>jim&gt; rename $f ""</code></pre>
2974 </div></div>
2975 </div>
2976 </div>
2977 </div>
2978 <div class="sect1">
2979 <h2 id="_utf_8_and_unicode">UTF-8 AND UNICODE</h2>
2980 <div class="sectionbody">
2981 <div class="paragraph"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
2982 then most string-related commands become UTF-8 aware. These include,
2983 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
2984 <a href="#_format"><strong><code>format</code></strong></a>.</p></div>
2985 <div class="paragraph"><p>UTF-8 encoding has many advantages, but one of the complications is that
2986 characters can take a variable number of bytes. Thus the addition of
2987 <a href="#_string"><strong><code>string</code></strong></a> <code>bytelength</code> which returns the number of bytes in a string,
2988 while <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> returns the number of characters.</p></div>
2989 <div class="paragraph"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
2990 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>
2991 <div class="paragraph"><p>Note that even if UTF-8 support is not enabled, the <code>\uNNNN</code> and related syntax
2992 is still available to embed UTF-8 sequences.</p></div>
2993 <div class="paragraph"><p>Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +<em>U+1FFFFF</em>.</p></div>
2994 <div class="sect2">
2995 <h3 id="_string_matching">String Matching</h3>
2996 <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
2997 pattern matching rules. These commands support UTF-8. For example:</p></div>
2998 <div class="literalblock">
2999 <div class="content">
3000 <pre><code>string match a\[\ua0-\ubf\]b "a\u00a3b"</code></pre>
3001 </div></div>
3002 </div>
3003 <div class="sect2">
3004 <h3 id="_format_and_scan">format and scan</h3>
3005 <div class="paragraph"><p><code>format %c</code> allows a unicode codepoint to be be encoded. For example, the following will return
3006 a string with two bytes and one character. The same as <code>\ub5</code></p></div>
3007 <div class="literalblock">
3008 <div class="content">
3009 <pre><code>format %c 0xb5</code></pre>
3010 </div></div>
3011 <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
3012 return a string with three characters, not three bytes.</p></div>
3013 <div class="literalblock">
3014 <div class="content">
3015 <pre><code>format %.3s \ub5\ub6\ub7\ub8</code></pre>
3016 </div></div>
3017 <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
3018 <code><em>a</em></code> to 181 (0xb5) and <code><em>b</em></code> to 65 (0x41).</p></div>
3019 <div class="literalblock">
3020 <div class="content">
3021 <pre><code>scan \u00b5A %c%c a b</code></pre>
3022 </div></div>
3023 <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>
3024 </div>
3025 <div class="sect2">
3026 <h3 id="_string_classes">String Classes</h3>
3027 <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
3028 will return 0, even though the string may be considered to be alphabetic.</p></div>
3029 <div class="literalblock">
3030 <div class="content">
3031 <pre><code>string is alpha \ub5Test</code></pre>
3032 </div></div>
3033 <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>
3034 </div>
3035 <div class="sect2">
3036 <h3 id="_case_mapping_and_conversion">Case Mapping and Conversion</h3>
3037 <div class="paragraph"><p>Jim provides a simplified unicode case mapping. This means that case conversion
3038 and comparison will not increase or decrease the number of characters in a string.
3039 (Although it may change the number of bytes).</p></div>
3040 <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.
3041 Any character which is not a letter or has no uppercase equivalent is left unchanged.
3042 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>
3043 <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>
3044 and <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-nocase</code> fold both strings to uppercase before comparison.</p></div>
3045 </div>
3046 <div class="sect2">
3047 <h3 id="_invalid_utf_8_sequences">Invalid UTF-8 Sequences</h3>
3048 <div class="paragraph"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
3049 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
3050 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
3051 <div class="paragraph"><p>In these situations, the offending bytes are treated as single characters. For example,
3052 the following returns 2.</p></div>
3053 <div class="literalblock">
3054 <div class="content">
3055 <pre><code>string bytelength \xff\xff</code></pre>
3056 </div></div>
3057 </div>
3058 <div class="sect2">
3059 <h3 id="_regular_expressions_2">Regular Expressions</h3>
3060 <div class="paragraph"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
3061 selected which supports UTF-8 strings and patterns.</p></div>
3062 <div class="paragraph"><p>See REGULAR EXPRESSIONS</p></div>
3063 </div>
3064 </div>
3065 </div>
3066 <div class="sect1">
3067 <h2 id="_built_in_commands">BUILT-IN COMMANDS</h2>
3068 <div class="sectionbody">
3069 <div class="paragraph"><p>The Tcl library provides the following built-in commands, which will
3070 be available in any application using Tcl. In addition to these
3071 built-in commands, there may be additional commands defined by each
3072 application, plus commands defined as Tcl procedures.</p></div>
3073 <div class="paragraph"><p>In the command syntax descriptions below, words in <code><strong>boldface</strong></code> are
3074 literals that you type verbatim to Tcl.</p></div>
3075 <div class="paragraph"><p>Words in <code><em>italics</em></code> are meta-symbols; they serve as names for any of
3076 a range of values that you can type.</p></div>
3077 <div class="paragraph"><p>Optional arguments or groups of arguments are indicated by enclosing them
3078 in <code>?question-marks?</code>.</p></div>
3079 <div class="paragraph"><p>Ellipses (<code>...</code>) indicate that any number of additional
3080 arguments or groups of arguments may appear, in the same format
3081 as the preceding argument(s).</p></div>
3082 <div class="sect2">
3083 <h3 id="CommandIndex">Command Index</h3>
3084 <div class="tableblock">
3085 <table rules="none"
3086 width="100%"
3087 frame="void"
3088 cellspacing="0" cellpadding="4">
3089 <col width="12%" />
3090 <col width="12%" />
3091 <col width="12%" />
3092 <col width="12%" />
3093 <col width="12%" />
3094 <col width="12%" />
3095 <col width="12%" />
3096 <col width="12%" />
3097 <tbody>
3098 <tr>
3099 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>after</code></strong></a></p></td>
3100 <td align="left" valign="top"><p class="table"><a href="#_aio"><strong><code>aio</code></strong></a></p></td>
3101 <td align="left" valign="top"><p class="table"><a href="#_alarm"><strong><code>alarm</code></strong></a></p></td>
3102 <td align="left" valign="top"><p class="table"><a href="#_alias"><strong><code>alias</code></strong></a></p></td>
3103 <td align="left" valign="top"><p class="table"><a href="#_append"><strong><code>append</code></strong></a></p></td>
3104 <td align="left" valign="top"><p class="table"><a href="#_apply"><strong><code>apply</code></strong></a></p></td>
3105 <td align="left" valign="top"><p class="table"><a href="#_array"><strong><code>array</code></strong></a></p></td>
3106 <td align="left" valign="top"><p class="table"><a href="#_binary"><strong><code>binary</code></strong></a></p></td>
3107 </tr>
3108 <tr>
3109 <td align="left" valign="top"><p class="table"><a href="#_break"><strong><code>break</code></strong></a></p></td>
3110 <td align="left" valign="top"><p class="table"><a href="#_case"><strong><code>case</code></strong></a></p></td>
3111 <td align="left" valign="top"><p class="table"><a href="#_catch"><strong><code>catch</code></strong></a></p></td>
3112 <td align="left" valign="top"><p class="table"><a href="#_cd"><strong><code>cd</code></strong></a></p></td>
3113 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>class</code></strong></a></p></td>
3114 <td align="left" valign="top"><p class="table"><a href="#_clock"><strong><code>clock</code></strong></a></p></td>
3115 <td align="left" valign="top"><p class="table"><a href="#_close"><strong><code>close</code></strong></a></p></td>
3116 <td align="left" valign="top"><p class="table"><a href="#_collect"><strong><code>collect</code></strong></a></p></td>
3117 </tr>
3118 <tr>
3119 <td align="left" valign="top"><p class="table"><a href="#_concat"><strong><code>concat</code></strong></a></p></td>
3120 <td align="left" valign="top"><p class="table"><a href="#_continue"><strong><code>continue</code></strong></a></p></td>
3121 <td align="left" valign="top"><p class="table"><a href="#_curry"><strong><code>curry</code></strong></a></p></td>
3122 <td align="left" valign="top"><p class="table"><a href="#_dict"><strong><code>dict</code></strong></a></p></td>
3123 <td align="left" valign="top"><p class="table"><a href="#_env"><strong><code>env</code></strong></a></p></td>
3124 <td align="left" valign="top"><p class="table"><a href="#_eof"><strong><code>eof</code></strong></a></p></td>
3125 <td align="left" valign="top"><p class="table"><a href="#_error"><strong><code>error</code></strong></a></p></td>
3126 <td align="left" valign="top"><p class="table"><a href="#_eval"><strong><code>eval</code></strong></a></p></td>
3127 </tr>
3128 <tr>
3129 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>eventloop</code></strong></a></p></td>
3130 <td align="left" valign="top"><p class="table"><a href="#_exec"><strong><code>exec</code></strong></a></p></td>
3131 <td align="left" valign="top"><p class="table"><a href="#_exists"><strong><code>exists</code></strong></a></p></td>
3132 <td align="left" valign="top"><p class="table"><a href="#_exit"><strong><code>exit</code></strong></a></p></td>
3133 <td align="left" valign="top"><p class="table"><a href="#_expr"><strong><code>expr</code></strong></a></p></td>
3134 <td align="left" valign="top"><p class="table"><a href="#_fconfigure"><strong><code>fconfigure</code></strong></a></p></td>
3135 <td align="left" valign="top"><p class="table"><a href="#_file"><strong><code>file</code></strong></a></p></td>
3136 <td align="left" valign="top"><p class="table"><a href="#_finalize"><strong><code>finalize</code></strong></a></p></td>
3137 </tr>
3138 <tr>
3139 <td align="left" valign="top"><p class="table"><a href="#_flush"><strong><code>flush</code></strong></a></p></td>
3140 <td align="left" valign="top"><p class="table"><a href="#_for"><strong><code>for</code></strong></a></p></td>
3141 <td align="left" valign="top"><p class="table"><a href="#_foreach"><strong><code>foreach</code></strong></a></p></td>
3142 <td align="left" valign="top"><p class="table"><a href="#_format"><strong><code>format</code></strong></a></p></td>
3143 <td align="left" valign="top"><p class="table"><a href="#_getref"><strong><code>getref</code></strong></a></p></td>
3144 <td align="left" valign="top"><p class="table"><a href="#_gets"><strong><code>gets</code></strong></a></p></td>
3145 <td align="left" valign="top"><p class="table"><a href="#_glob"><strong><code>glob</code></strong></a></p></td>
3146 <td align="left" valign="top"><p class="table"><a href="#_global"><strong><code>global</code></strong></a></p></td>
3147 </tr>
3148 <tr>
3149 <td align="left" valign="top"><p class="table"><a href="#_history"><strong><code>history</code></strong></a></p></td>
3150 <td align="left" valign="top"><p class="table"><a href="#_if"><strong><code>if</code></strong></a></p></td>
3151 <td align="left" valign="top"><p class="table"><a href="#_incr"><strong><code>incr</code></strong></a></p></td>
3152 <td align="left" valign="top"><p class="table"><a href="#_info"><strong><code>info</code></strong></a></p></td>
3153 <td align="left" valign="top"><p class="table"><a href="#_join"><strong><code>join</code></strong></a></p></td>
3154 <td align="left" valign="top"><p class="table"><a href="#_kill"><strong><code>kill</code></strong></a></p></td>
3155 <td align="left" valign="top"><p class="table"><a href="#_lambda"><strong><code>lambda</code></strong></a></p></td>
3156 <td align="left" valign="top"><p class="table"><a href="#_lappend"><strong><code>lappend</code></strong></a></p></td>
3157 </tr>
3158 <tr>
3159 <td align="left" valign="top"><p class="table"><a href="#_lassign"><strong><code>lassign</code></strong></a></p></td>
3160 <td align="left" valign="top"><p class="table"><a href="#_lindex"><strong><code>lindex</code></strong></a></p></td>
3161 <td align="left" valign="top"><p class="table"><a href="#_linsert"><strong><code>linsert</code></strong></a></p></td>
3162 <td align="left" valign="top"><p class="table"><a href="#_list"><strong><code>list</code></strong></a></p></td>
3163 <td align="left" valign="top"><p class="table"><a href="#_llength"><strong><code>llength</code></strong></a></p></td>
3164 <td align="left" valign="top"><p class="table"><a href="#_lmap"><strong><code>lmap</code></strong></a></p></td>
3165 <td align="left" valign="top"><p class="table"><a href="#_load"><strong><code>load</code></strong></a></p></td>
3166 <td align="left" valign="top"><p class="table"><a href="#_local"><strong><code>local</code></strong></a></p></td>
3167 </tr>
3168 <tr>
3169 <td align="left" valign="top"><p class="table"><a href="#_loop"><strong><code>loop</code></strong></a></p></td>
3170 <td align="left" valign="top"><p class="table"><a href="#_lrange"><strong><code>lrange</code></strong></a></p></td>
3171 <td align="left" valign="top"><p class="table"><a href="#_lrepeat"><strong><code>lrepeat</code></strong></a></p></td>
3172 <td align="left" valign="top"><p class="table"><a href="#_lreplace"><strong><code>lreplace</code></strong></a></p></td>
3173 <td align="left" valign="top"><p class="table"><a href="#_lreverse"><strong><code>lreverse</code></strong></a></p></td>
3174 <td align="left" valign="top"><p class="table"><a href="#_lsearch"><strong><code>lsearch</code></strong></a></p></td>
3175 <td align="left" valign="top"><p class="table"><a href="#_lset"><strong><code>lset</code></strong></a></p></td>
3176 <td align="left" valign="top"><p class="table"><a href="#_lsort"><strong><code>lsort</code></strong></a></p></td>
3177 </tr>
3178 <tr>
3179 <td align="left" valign="top"><p class="table"><a href="#_namespace"><strong><code>namespace</code></strong></a></p></td>
3180 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>oo</code></strong></a></p></td>
3181 <td align="left" valign="top"><p class="table"><a href="#_open"><strong><code>open</code></strong></a></p></td>
3182 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.fork</code></strong></a></p></td>
3183 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.gethostname</code></strong></a></p></td>
3184 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.getids</code></strong></a></p></td>
3185 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.uptime</code></strong></a></p></td>
3186 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.wait</code></strong></a></p></td>
3187 </tr>
3188 <tr>
3189 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3190 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3191 <td align="left" valign="top"><p class="table"><a href="#_package"><strong><code>package</code></strong></a></p></td>
3192 <td align="left" valign="top"><p class="table"><a href="#_pid"><strong><code>pid</code></strong></a></p></td>
3193 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>posix</code></strong></a></p></td>
3194 <td align="left" valign="top"><p class="table"><a href="#_proc"><strong><code>proc</code></strong></a></p></td>
3195 <td align="left" valign="top"><p class="table"><a href="#_puts"><strong><code>puts</code></strong></a></p></td>
3196 <td align="left" valign="top"><p class="table"><a href="#_pwd"><strong><code>pwd</code></strong></a></p></td>
3197 </tr>
3198 <tr>
3199 <td align="left" valign="top"><p class="table"><a href="#_rand"><strong><code>rand</code></strong></a></p></td>
3200 <td align="left" valign="top"><p class="table"><a href="#_range"><strong><code>range</code></strong></a></p></td>
3201 <td align="left" valign="top"><p class="table"><a href="#_read"><strong><code>read</code></strong></a></p></td>
3202 <td align="left" valign="top"><p class="table"><a href="#_ref"><strong><code>ref</code></strong></a></p></td>
3203 <td align="left" valign="top"><p class="table"><a href="#_regexp"><strong><code>regexp</code></strong></a></p></td>
3204 <td align="left" valign="top"><p class="table"><a href="#_regsub"><strong><code>regsub</code></strong></a></p></td>
3205 <td align="left" valign="top"><p class="table"><a href="#_rename"><strong><code>rename</code></strong></a></p></td>
3206 <td align="left" valign="top"><p class="table"><a href="#_return"><strong><code>return</code></strong></a></p></td>
3207 </tr>
3208 <tr>
3209 <td align="left" valign="top"><p class="table"><a href="#_scan"><strong><code>scan</code></strong></a></p></td>
3210 <td align="left" valign="top"><p class="table"><a href="#_seek"><strong><code>seek</code></strong></a></p></td>
3211 <td align="left" valign="top"><p class="table"><a href="#_set"><strong><code>set</code></strong></a></p></td>
3212 <td align="left" valign="top"><p class="table"><a href="#_setref"><strong><code>setref</code></strong></a></p></td>
3213 <td align="left" valign="top"><p class="table"><a href="#_signal"><strong><code>signal</code></strong></a></p></td>
3214 <td align="left" valign="top"><p class="table"><a href="#_sleep"><strong><code>sleep</code></strong></a></p></td>
3215 <td align="left" valign="top"><p class="table"><a href="#_socket"><strong><code>socket</code></strong></a></p></td>
3216 <td align="left" valign="top"><p class="table"><a href="#_source"><strong><code>source</code></strong></a></p></td>
3217 </tr>
3218 <tr>
3219 <td align="left" valign="top"><p class="table"><a href="#_split"><strong><code>split</code></strong></a></p></td>
3220 <td align="left" valign="top"><p class="table"><a href="#_stackdump"><strong><code>stackdump</code></strong></a></p></td>
3221 <td align="left" valign="top"><p class="table"><a href="#_stacktrace"><strong><code>stacktrace</code></strong></a></p></td>
3222 <td align="left" valign="top"><p class="table"><a href="#_string"><strong><code>string</code></strong></a></p></td>
3223 <td align="left" valign="top"><p class="table"><a href="#_subst"><strong><code>subst</code></strong></a></p></td>
3224 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>super</code></strong></a></p></td>
3225 <td align="left" valign="top"><p class="table"><a href="#_switch"><strong><code>switch</code></strong></a></p></td>
3226 <td align="left" valign="top"><p class="table"><a href="#_syslog"><strong><code>syslog</code></strong></a></p></td>
3227 </tr>
3228 <tr>
3229 <td align="left" valign="top"><p class="table"><a href="#_tailcall"><strong><code>tailcall</code></strong></a></p></td>
3230 <td align="left" valign="top"><p class="table"><a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a></p></td>
3231 <td align="left" valign="top"><p class="table"><a href="#_tell"><strong><code>tell</code></strong></a></p></td>
3232 <td align="left" valign="top"><p class="table"><a href="#_throw"><strong><code>throw</code></strong></a></p></td>
3233 <td align="left" valign="top"><p class="table"><a href="#_time"><strong><code>time</code></strong></a></p></td>
3234 <td align="left" valign="top"><p class="table"><a href="#_tree"><strong><code>tree</code></strong></a></p></td>
3235 <td align="left" valign="top"><p class="table"><a href="#_try"><strong><code>try</code></strong></a></p></td>
3236 <td align="left" valign="top"><p class="table"><a href="#_unknown"><strong><code>unknown</code></strong></a></p></td>
3237 </tr>
3238 <tr>
3239 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>unpack</code></strong></a></p></td>
3240 <td align="left" valign="top"><p class="table"><a href="#_unset"><strong><code>unset</code></strong></a></p></td>
3241 <td align="left" valign="top"><p class="table"><a href="#_upcall"><strong><code>upcall</code></strong></a></p></td>
3242 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>update</code></strong></a></p></td>
3243 <td align="left" valign="top"><p class="table"><a href="#_uplevel"><strong><code>uplevel</code></strong></a></p></td>
3244 <td align="left" valign="top"><p class="table"><a href="#_upvar"><strong><code>upvar</code></strong></a></p></td>
3245 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>vwait</code></strong></a></p></td>
3246 <td align="left" valign="top"><p class="table"><a href="#_while"><strong><code>while</code></strong></a></p></td>
3247 </tr>
3248 </tbody>
3249 </table>
3250 </div>
3251 </div>
3252 <div class="sect2">
3253 <h3 id="_alarm">alarm</h3>
3254 <div class="paragraph"><p><code><strong>alarm</strong> <em>seconds</em></code></p></div>
3255 <div class="paragraph"><p>Delivers the <code>SIGALRM</code> signal to the process after the given
3256 number of seconds. If the platform supports <em>ualarm(3)</em> then
3257 the argument may be a floating point value. Otherwise it must
3258 be an integer.</p></div>
3259 <div class="paragraph"><p>Note that unless a signal handler for <code>SIGALRM</code> has been installed
3260 (see <a href="#_signal"><strong><code>signal</code></strong></a>), the process will exit on this signal.</p></div>
3261 </div>
3262 <div class="sect2">
3263 <h3 id="_alias">alias</h3>
3264 <div class="paragraph"><p><code><strong>alias</strong> <em>name args...</em></code></p></div>
3265 <div class="paragraph"><p>Creates a single word alias (command) for one or more words. For example,
3266 the following creates an alias for the command <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>.</p></div>
3267 <div class="literalblock">
3268 <div class="content">
3269 <pre><code>alias e info exists
3270 if {[e var]} {
3272 }</code></pre>
3273 </div></div>
3274 <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>
3275 <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>
3276 </div>
3277 <div class="sect2">
3278 <h3 id="_append">append</h3>
3279 <div class="paragraph"><p><code><strong>append</strong> <em>varName value ?value value &#8230;?</em></code></p></div>
3280 <div class="paragraph"><p>Append all of the <code><em>value</em></code> arguments to the current value
3281 of variable <code><em>varName</em></code>. If <code><em>varName</em></code> doesn&#8217;t exist,
3282 it is given a value equal to the concatenation of all the
3283 <code><em>value</em></code> arguments.</p></div>
3284 <div class="paragraph"><p>This command provides an efficient way to build up long
3285 variables incrementally.
3286 For example, "<a href="#_append"><strong><code>append</code></strong></a> <code>a $b</code>" is much more efficient than
3287 "<a href="#_set"><strong><code>set</code></strong></a> <code>a $a$b</code>" if <code>$a</code> is long.</p></div>
3288 </div>
3289 <div class="sect2">
3290 <h3 id="_apply">apply</h3>
3291 <div class="paragraph"><p><code><strong>apply</strong> <em>lambdaExpr ?arg1 arg2 ...?</em></code></p></div>
3292 <div class="paragraph"><p>The command <a href="#_apply"><strong><code>apply</code></strong></a> provides for anonymous procedure calls,
3293 similar to <a href="#_lambda"><strong><code>lambda</code></strong></a>, but without command name being created, even temporarily.</p></div>
3294 <div class="paragraph"><p>The function <code><em>lambdaExpr</em></code> is a two element list <code>{args body}</code>
3295 or a three element list <code>{args body namespace}</code>. The first element
3296 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>
3297 </div>
3298 <div class="sect2">
3299 <h3 id="_array">array</h3>
3300 <div class="paragraph"><p><code><strong>array</strong> <em>option arrayName ?arg...?</em></code></p></div>
3301 <div class="paragraph"><p>This command performs one of several operations on the
3302 variable given by <code><em>arrayName</em></code>.</p></div>
3303 <div class="paragraph"><p>Note that in general, if the named array does not exist, the <code><em>array</em></code> command behaves
3304 as though the array exists but is empty.</p></div>
3305 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3306 command. The legal <code><em>options</em></code> (which may be abbreviated) are:</p></div>
3307 <div class="dlist"><dl>
3308 <dt class="hdlist1">
3309 <code><strong>array exists</strong> <em>arrayName</em></code>
3310 </dt>
3311 <dd>
3313 Returns 1 if arrayName is an array variable, 0 if there is
3314 no variable by that name. This command is essentially
3315 identical to <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>
3316 </p>
3317 </dd>
3318 <dt class="hdlist1">
3319 <code><strong>array get</strong> <em>arrayName ?pattern?</em></code>
3320 </dt>
3321 <dd>
3323 Returns a list containing pairs of elements. The first
3324 element in each pair is the name of an element in arrayName
3325 and the second element of each pair is the value of the
3326 array element. The order of the pairs is undefined. If
3327 pattern is not specified, then all of the elements of the
3328 array are included in the result. If pattern is specified,
3329 then only those elements whose names match pattern (using
3330 the matching rules of string match) are included. If arrayName
3331 isn&#8217;t the name of an array variable, or if the array contains
3332 no elements, then an empty list is returned.
3333 </p>
3334 </dd>
3335 <dt class="hdlist1">
3336 <code><strong>array names</strong> <em>arrayName ?pattern?</em></code>
3337 </dt>
3338 <dd>
3340 Returns a list containing the names of all of the elements
3341 in the array that match pattern. If pattern is omitted then
3342 the command returns all of the element names in the array.
3343 If pattern is specified, then only those elements whose
3344 names match pattern (using the matching rules of string
3345 match) are included. If there are no (matching) elements
3346 in the array, or if arrayName isn&#8217;t the name of an array
3347 variable, then an empty string is returned.
3348 </p>
3349 </dd>
3350 <dt class="hdlist1">
3351 <code><strong>array set</strong> <em>arrayName list</em></code>
3352 </dt>
3353 <dd>
3355 Sets the values of one or more elements in arrayName. list
3356 must have a form like that returned by array get, consisting
3357 of an even number of elements. Each odd-numbered element
3358 in list is treated as an element name within arrayName, and
3359 the following element in list is used as a new value for
3360 that array element. If the variable arrayName does not
3361 already exist and list is empty, arrayName is created with
3362 an empty array value.
3363 </p>
3364 </dd>
3365 <dt class="hdlist1">
3366 <code><strong>array size</strong> <em>arrayName</em></code>
3367 </dt>
3368 <dd>
3370 Returns the number of elements in the array. If arrayName
3371 isn&#8217;t the name of an array then 0 is returned.
3372 </p>
3373 </dd>
3374 <dt class="hdlist1">
3375 <code><strong>array unset</strong> <em>arrayName ?pattern?</em></code>
3376 </dt>
3377 <dd>
3379 Unsets all of the elements in the array that match pattern
3380 (using the matching rules of string match). If arrayName
3381 isn&#8217;t the name of an array variable or there are no matching
3382 elements in the array, no error will be raised. If pattern
3383 is omitted and arrayName is an array variable, then the
3384 command unsets the entire array. The command always returns
3385 an empty string.
3386 </p>
3387 </dd>
3388 </dl></div>
3389 </div>
3390 <div class="sect2">
3391 <h3 id="_break">break</h3>
3392 <div class="paragraph"><p><code><strong>break</strong></code></p></div>
3393 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command
3394 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
3395 to signal the innermost containing loop command to return immediately.</p></div>
3396 </div>
3397 <div class="sect2">
3398 <h3 id="_case">case</h3>
3399 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? <em>patList body ?patList body &#8230;?</em></code></p></div>
3400 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? {<em>patList body ?patList body &#8230;?</em>}</code></p></div>
3401 <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
3402 with Tcl 6.x is desired.</p></div>
3403 <div class="paragraph"><p>Match <code><em>string</em></code> against each of the <code><em>patList</em></code> arguments
3404 in order. If one matches, then evaluate the following <code><em>body</em></code> argument
3405 by passing it recursively to the Tcl interpreter, and return the result
3406 of that evaluation. Each <code><em>patList</em></code> argument consists of a single
3407 pattern or list of patterns. Each pattern may contain any of the wild-cards
3408 described under <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.</p></div>
3409 <div class="paragraph"><p>If a <code><em>patList</em></code> argument is <code>default</code>, the corresponding body will be
3410 evaluated if no <code><em>patList</em></code> matches <code><em>string</em></code>. If no <code><em>patList</em></code> argument
3411 matches <code><em>string</em></code> and no default is given, then the <a href="#_case"><strong><code>case</code></strong></a> command returns
3412 an empty string.</p></div>
3413 <div class="paragraph"><p>Two syntaxes are provided.</p></div>
3414 <div class="paragraph"><p>The first uses a separate argument for each of the patterns and commands;
3415 this form is convenient if substitutions are desired on some of the
3416 patterns or commands.</p></div>
3417 <div class="paragraph"><p>The second form places all of the patterns and commands together into
3418 a single argument; the argument must have proper list structure, with
3419 the elements of the list being the patterns and commands.</p></div>
3420 <div class="paragraph"><p>The second form makes it easy to construct multi-line case commands,
3421 since the braces around the whole list make it unnecessary to include a
3422 backslash at the end of each line.</p></div>
3423 <div class="paragraph"><p>Since the <code><em>patList</em></code> arguments are in braces in the second form,
3424 no command or variable substitutions are performed on them; this makes
3425 the behaviour of the second form different than the first form in some
3426 cases.</p></div>
3427 <div class="paragraph"><p>Below are some examples of <a href="#_case"><strong><code>case</code></strong></a> commands:</p></div>
3428 <div class="literalblock">
3429 <div class="content">
3430 <pre><code>case abc in {a b} {format 1} default {format 2} a* {format 3}</code></pre>
3431 </div></div>
3432 <div class="paragraph"><p>will return <em>3</em>,</p></div>
3433 <div class="literalblock">
3434 <div class="content">
3435 <pre><code>case a in {
3436 {a b} {format 1}
3437 default {format 2}
3438 a* {format 3}
3439 }</code></pre>
3440 </div></div>
3441 <div class="paragraph"><p>will return <em>1</em>, and</p></div>
3442 <div class="literalblock">
3443 <div class="content">
3444 <pre><code>case xyz {
3445 {a b}
3446 {format 1}
3447 default
3448 {format 2}
3450 {format 3}
3451 }</code></pre>
3452 </div></div>
3453 <div class="paragraph"><p>will return <em>2</em>.</p></div>
3454 </div>
3455 <div class="sect2">
3456 <h3 id="_catch">catch</h3>
3457 <div class="paragraph"><p><code><strong>catch</strong> ?-?no?<em>code ...</em>? ?--? <em>command ?resultVarName? ?optionsVarName?</em></code></p></div>
3458 <div class="paragraph"><p>The <a href="#_catch"><strong><code>catch</code></strong></a> command may be used to prevent errors from aborting
3459 command interpretation. <a href="#_catch"><strong><code>catch</code></strong></a> evaluates <code><em>command</em></code>, and returns a
3460 <code>JIM_OK</code> code, regardless of any errors that might occur while
3461 executing <code><em>command</em></code> (with the possible exception of <code>JIM_SIGNAL</code> -
3462 see below).</p></div>
3463 <div class="paragraph"><p>The return value from <a href="#_catch"><strong><code>catch</code></strong></a> is a decimal string giving the code
3464 returned by the Tcl interpreter after executing <code><em>command</em></code>. This
3465 will be <em>0</em> (<code>JIM_OK</code>) if there were no errors in <code><em>command</em></code>; otherwise
3466 it will have a non-zero value corresponding to one of the exceptional
3467 return codes (see jim.h for the definitions of code values, or the
3468 <a href="#_info"><strong><code>info</code></strong></a> <code>returncodes</code> command).</p></div>
3469 <div class="paragraph"><p>If the <code><em>resultVarName</em></code> argument is given, then it gives the name
3470 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to the
3471 string returned from <code><em>command</em></code> (either a result or an error message).</p></div>
3472 <div class="paragraph"><p>If the <code><em>optionsVarName</em></code> argument is given, then it gives the name
3473 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to a
3474 dictionary. For any return code other than <code>JIM_RETURN</code>, the value
3475 for the key <code>-code</code> will be set to the return code. For <code>JIM_RETURN</code>
3476 it will be set to the code given in <a href="#_return"><strong><code>return</code></strong></a> <code>-code</code>. Additionally,
3477 for the return code <code>JIM_ERR</code>, the value of the key <code>-errorinfo</code>
3478 will contain the current stack trace (the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code>),
3479 the value of the key <code>-errorcode</code> will contain the
3480 same value as the global variable $::errorCode, and the value of
3481 the key <code>-level</code> will be the current return level (see <a href="#_return"><strong><code>return</code></strong></a> <code>-level</code>).
3482 This can be useful to rethrow an error:</p></div>
3483 <div class="literalblock">
3484 <div class="content">
3485 <pre><code>if {[catch {...} msg opts]} {
3486 ...maybe do something with the error...
3487 incr opts(-level)
3488 return {*}$opts $msg
3489 }</code></pre>
3490 </div></div>
3491 <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>.
3492 The set of codes which will be caught may be modified by specifying the one more codes before
3493 <code><em>command</em></code>.</p></div>
3494 <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>
3495 <div class="literalblock">
3496 <div class="content">
3497 <pre><code>catch -exit -nobreak -nocontinue -- { ... }</code></pre>
3498 </div></div>
3499 <div class="paragraph"><p>The use of <code>--</code> is optional. It signifies that no more return code options follow.</p></div>
3500 <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
3501 (stored in <code><em>resultVarName</em></code>) is name of the signal caught.</p></div>
3502 </div>
3503 <div class="sect2">
3504 <h3 id="_cd">cd</h3>
3505 <div class="paragraph"><p><code><strong>cd</strong> <em>dirName</em></code></p></div>
3506 <div class="paragraph"><p>Change the current working directory to <code><em>dirName</em></code>.</p></div>
3507 <div class="paragraph"><p>Returns an empty string.</p></div>
3508 <div class="paragraph"><p>This command can potentially be disruptive to an application, so it may
3509 be removed in some applications.</p></div>
3510 </div>
3511 <div class="sect2">
3512 <h3 id="_clock">clock</h3>
3513 <div class="dlist"><dl>
3514 <dt class="hdlist1">
3515 <code><strong>clock seconds</strong></code>
3516 </dt>
3517 <dd>
3519 Returns the current time as seconds since the epoch.
3520 </p>
3521 </dd>
3522 <dt class="hdlist1">
3523 <code><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em></code>
3524 </dt>
3525 <dd>
3527 Format the given time (seconds since the epoch) according to the given
3528 format. See strftime(3) for supported formats.
3529 If no format is supplied, "%c" is used.
3530 </p>
3531 </dd>
3532 <dt class="hdlist1">
3533 <code><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em></code>
3534 </dt>
3535 <dd>
3537 Scan the given time string using the given format string.
3538 See strptime(3) for supported formats.
3539 </p>
3540 </dd>
3541 </dl></div>
3542 </div>
3543 <div class="sect2">
3544 <h3 id="_close">close</h3>
3545 <div class="paragraph"><p><code><strong>close</strong> <em>fileId</em></code></p></div>
3546 <div class="paragraph"><p><code><em>fileId</em> <strong>close</strong></code></p></div>
3547 <div class="paragraph"><p>Closes the file given by <code><em>fileId</em></code>.
3548 <code><em>fileId</em></code> must be the return value from a previous invocation
3549 of the <a href="#_open"><strong><code>open</code></strong></a> command; after this command, it should not be
3550 used anymore.</p></div>
3551 </div>
3552 <div class="sect2">
3553 <h3 id="_collect">collect</h3>
3554 <div class="paragraph"><p><code><strong>collect</strong></code></p></div>
3555 <div class="paragraph"><p>Normally reference garbage collection is automatically performed periodically.
3556 However it may be run immediately with the <a href="#_collect"><strong><code>collect</code></strong></a> command.</p></div>
3557 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
3558 </div>
3559 <div class="sect2">
3560 <h3 id="_concat">concat</h3>
3561 <div class="paragraph"><p><code><strong>concat</strong> <em>arg ?arg ...?</em></code></p></div>
3562 <div class="paragraph"><p>This command treats each argument as a list and concatenates them
3563 into a single list. It permits any number of arguments. For example,
3564 the command</p></div>
3565 <div class="literalblock">
3566 <div class="content">
3567 <pre><code>concat a b {c d e} {f {g h}}</code></pre>
3568 </div></div>
3569 <div class="paragraph"><p>will return</p></div>
3570 <div class="literalblock">
3571 <div class="content">
3572 <pre><code>a b c d e f {g h}</code></pre>
3573 </div></div>
3574 <div class="paragraph"><p>as its result.</p></div>
3575 </div>
3576 <div class="sect2">
3577 <h3 id="_continue">continue</h3>
3578 <div class="paragraph"><p><code><strong>continue</strong></code></p></div>
3579 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command such
3580 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
3581 signal the innermost containing loop command to skip the remainder of
3582 the loop&#8217;s body but continue with the next iteration of the loop.</p></div>
3583 </div>
3584 <div class="sect2">
3585 <h3 id="_curry">curry</h3>
3586 <div class="paragraph"><p><code><strong>alias</strong> <em>args...</em></code></p></div>
3587 <div class="paragraph"><p>Similar to <a href="#_alias"><strong><code>alias</code></strong></a> except it creates an anonymous procedure (lambda) instead of
3588 a named procedure.</p></div>
3589 <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>
3590 <div class="literalblock">
3591 <div class="content">
3592 <pre><code>set e [local curry info exists]
3593 if {[$e var]} {
3595 }</code></pre>
3596 </div></div>
3597 <div class="paragraph"><p><a href="#_curry"><strong><code>curry</code></strong></a> returns the name of the procedure.</p></div>
3598 <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>
3599 </div>
3600 <div class="sect2">
3601 <h3 id="_dict">dict</h3>
3602 <div class="paragraph"><p><code><strong>dict</strong> <em>option ?arg...?</em></code></p></div>
3603 <div class="paragraph"><p>Performs one of several operations on dictionary values.</p></div>
3604 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3605 command. The legal <code><em>options</em></code> are:</p></div>
3606 <div class="dlist"><dl>
3607 <dt class="hdlist1">
3608 <code><strong>dict create</strong> <em>?key value ...?</em></code>
3609 </dt>
3610 <dd>
3612 Create and return a new dictionary value that contains each of
3613 the key/value mappings listed as arguments (keys and values
3614 alternating, with each key being followed by its associated
3615 value.)
3616 </p>
3617 </dd>
3618 <dt class="hdlist1">
3619 <code><strong>dict exists</strong> <em>dictionary key ?key ...?</em></code>
3620 </dt>
3621 <dd>
3623 Returns a boolean value indicating whether the given key (or path
3624 of keys through a set of nested dictionaries) exists in the given
3625 dictionary value. This returns a true value exactly when <a href="#_dict"><strong><code>dict</code></strong></a> <code>get</code>
3626 on that path will succeed.
3627 </p>
3628 </dd>
3629 <dt class="hdlist1">
3630 <code><strong>dict get</strong> <em>dictionary ?key ...?</em></code>
3631 </dt>
3632 <dd>
3634 Given a dictionary value (first argument) and a key (second argument),
3635 this will retrieve the value for that key. Where several keys are
3636 supplied, the behaviour of the command shall be as if the result
3637 of "<a href="#_dict"><strong><code>dict</code></strong></a> <code>get $dictVal $key</code>" was passed as the first argument to
3638 dict get with the remaining arguments as second (and possibly
3639 subsequent) arguments. This facilitates lookups in nested dictionaries.
3640 If no keys are provided, dict would return a list containing pairs
3641 of elements in a man- ner similar to array get. That is, the first
3642 element of each pair would be the key and the second element would
3643 be the value for that key. It is an error to attempt to retrieve
3644 a value for a key that is not present in the dictionary.
3645 </p>
3646 </dd>
3647 <dt class="hdlist1">
3648 <code><strong>dict keys</strong> <em>dictionary ?pattern?</em></code>
3649 </dt>
3650 <dd>
3652 Returns a list of the keys in the dictionary.
3653 If pattern is specified, then only those keys whose
3654 names match <code><em>pattern</em></code> (using the matching rules of string
3655 match) are included.
3656 </p>
3657 </dd>
3658 <dt class="hdlist1">
3659 <code><strong>dict merge</strong> ?<em>dictionary ...</em>?</code>
3660 </dt>
3661 <dd>
3663 Return a dictionary that contains the contents of each of the
3664 <code><em>dictionary</em></code> arguments. Where two (or more) dictionaries
3665 contain a mapping for the same key, the resulting dictionary
3666 maps that key to the value according to the last dictionary on
3667 the command line containing a mapping for that key.
3668 </p>
3669 </dd>
3670 <dt class="hdlist1">
3671 <code><strong>dict set</strong> <em>dictionaryName key ?key ...? value</em></code>
3672 </dt>
3673 <dd>
3675 This operation takes the <code><em>name</em></code> of a variable containing a dictionary
3676 value and places an updated dictionary value in that variable
3677 containing a mapping from the given key to the given value. When
3678 multiple keys are present, this operation creates or updates a chain
3679 of nested dictionaries.
3680 </p>
3681 </dd>
3682 <dt class="hdlist1">
3683 <code><strong>dict size</strong> <em>dictionary</em></code>
3684 </dt>
3685 <dd>
3687 Return the number of key/value mappings in the given dictionary value.
3688 </p>
3689 </dd>
3690 <dt class="hdlist1">
3691 <code><strong>dict unset</strong> <em>dictionaryName key ?key ...? value</em></code>
3692 </dt>
3693 <dd>
3695 This operation (the companion to <a href="#_dict"><strong><code>dict</code></strong></a> <code>set</code>) takes the name of a
3696 variable containing a dictionary value and places an updated
3697 dictionary value in that variable that does not contain a mapping
3698 for the given key. Where multiple keys are present, this describes
3699 a path through nested dictionaries to the mapping to remove. At
3700 least one key must be specified, but the last key on the key-path
3701 need not exist. All other components on the path must exist.
3702 </p>
3703 </dd>
3704 <dt class="hdlist1">
3705 <code><strong>dict with</strong> <em>dictionaryName key ?key ...? script</em></code>
3706 </dt>
3707 <dd>
3709 Execute the Tcl script in <code><em>script</em></code> with the value for each
3710 key in <code><em>dictionaryName</em></code> mapped to a variable with the same
3711 name. Where one or more keys are given, these indicate a chain
3712 of nested dictionaries, with the innermost dictionary being the
3713 one opened out for the execution of body. Making <code><em>dictionaryName</em></code>
3714 unreadable will make the updates to the dictionary be discarded,
3715 and this also happens if the contents of <code><em>dictionaryName</em></code> are
3716 adjusted so that the chain of dictionaries no longer exists.
3717 The result of <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> is (unless some kind of error occurs)
3718 the result of the evaluation of body.
3719 </p>
3720 </dd>
3721 <dt class="hdlist1">
3723 </dt>
3724 <dd>
3726 The variables are mapped in the scope enclosing the <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code>;
3727 it is recommended that this command only be used in a local
3728 scope (procedure). Because of this, the variables set by
3729 <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> will continue to exist after the command finishes (unless
3730 explicitly unset). Note that changes to the contents of <code><em>dictionaryName</em></code>
3731 only happen when <code><em>script</em></code> terminates.
3732 </p>
3733 </dd>
3734 </dl></div>
3735 <div class="paragraph"><p><code><strong>dict for, values, incr, append, lappend, update, info, replace</strong></code> to be documented&#8230;</p></div>
3736 </div>
3737 <div class="sect2">
3738 <h3 id="_env">env</h3>
3739 <div class="paragraph"><p><code><strong>env</strong> <em>?name? ?default?</em></code></p></div>
3740 <div class="paragraph"><p>If <code><em>name</em></code> is supplied, returns the value of <code><em>name</em></code> from the initial
3741 environment (see getenv(3)). An error is returned if <code><em>name</em></code> does not
3742 exist in the environment, unless <code><em>default</em></code> is supplied - in which case
3743 that value is returned instead.</p></div>
3744 <div class="paragraph"><p>If no arguments are supplied, returns a list of all environment variables
3745 and their values as <code>{name value ...}</code></p></div>
3746 <div class="paragraph"><p>See also the global variable <code>::env</code></p></div>
3747 </div>
3748 <div class="sect2">
3749 <h3 id="_eof">eof</h3>
3750 <div class="paragraph"><p><code><strong>eof</strong> <em>fileId</em></code></p></div>
3751 <div class="paragraph"><p><code><em>fileId</em> <strong>eof</strong></code></p></div>
3752 <div class="paragraph"><p>Returns 1 if an end-of-file condition has occurred on <code><em>fileId</em></code>,
3753 0 otherwise.</p></div>
3754 <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>,
3755 or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one of the
3756 standard I/O channels.</p></div>
3757 </div>
3758 <div class="sect2">
3759 <h3 id="_error">error</h3>
3760 <div class="paragraph"><p><code><strong>error</strong> <em>message ?stacktrace?</em></code></p></div>
3761 <div class="paragraph"><p>Returns a <code>JIM_ERR</code> code, which causes command interpretation to be
3762 unwound. <code><em>message</em></code> is a string that is returned to the application
3763 to indicate what went wrong.</p></div>
3764 <div class="paragraph"><p>If the <code><em>stacktrace</em></code> argument is provided and is non-empty,
3765 it is used to initialize the stacktrace.</p></div>
3766 <div class="paragraph"><p>This feature is most useful in conjunction with the <a href="#_catch"><strong><code>catch</code></strong></a> command:
3767 if a caught error cannot be handled successfully, <code><em>stacktrace</em></code> can be used
3768 to return a stack trace reflecting the original point of occurrence
3769 of the error:</p></div>
3770 <div class="literalblock">
3771 <div class="content">
3772 <pre><code>catch {...} errMsg
3774 error $errMsg [info stacktrace]</code></pre>
3775 </div></div>
3776 <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>
3777 </div>
3778 <div class="sect2">
3779 <h3 id="_errorinfo">errorInfo</h3>
3780 <div class="paragraph"><p><code><strong>errorInfo</strong> <em>error ?stacktrace?</em></code></p></div>
3781 <div class="paragraph"><p>Returns a human-readable representation of the given error message and stack trace.
3782 Typical usage is:</p></div>
3783 <div class="literalblock">
3784 <div class="content">
3785 <pre><code>if {[catch {...} error]} {
3786 puts stderr [errorInfo $error [info stacktrace]]
3787 exit 1
3788 }</code></pre>
3789 </div></div>
3790 <div class="paragraph"><p>See also <a href="#_error"><strong><code>error</code></strong></a>.</p></div>
3791 </div>
3792 <div class="sect2">
3793 <h3 id="_eval">eval</h3>
3794 <div class="paragraph"><p><code><strong>eval</strong> <em>arg ?arg...?</em></code></p></div>
3795 <div class="paragraph"><p><a href="#_eval"><strong><code>eval</code></strong></a> takes one or more arguments, which together comprise a Tcl
3796 command (or collection of Tcl commands separated by newlines in the
3797 usual way). <a href="#_eval"><strong><code>eval</code></strong></a> concatenates all its arguments in the same
3798 fashion as the <a href="#_concat"><strong><code>concat</code></strong></a> command, passes the concatenated string to the
3799 Tcl interpreter recursively, and returns the result of that
3800 evaluation (or any error generated by it).</p></div>
3801 </div>
3802 <div class="sect2">
3803 <h3 id="_exec">exec</h3>
3804 <div class="paragraph"><p><code><strong>exec</strong> <em>arg ?arg...?</em></code></p></div>
3805 <div class="paragraph"><p>This command treats its arguments as the specification
3806 of one or more UNIX commands to execute as subprocesses.
3807 The commands take the form of a standard shell pipeline;
3808 <code>|</code> arguments separate commands in the
3809 pipeline and cause standard output of the preceding command
3810 to be piped into standard input of the next command (or <code>|&amp;</code> for
3811 both standard output and standard error).</p></div>
3812 <div class="paragraph"><p>Under normal conditions the result of the <a href="#_exec"><strong><code>exec</code></strong></a> command
3813 consists of the standard output produced by the last command
3814 in the pipeline.</p></div>
3815 <div class="paragraph"><p>If any of the commands in the pipeline exit abnormally or
3816 are killed or suspended, then <a href="#_exec"><strong><code>exec</code></strong></a> will return an error
3817 and the error message will include the pipeline&#8217;s output followed by
3818 error messages describing the abnormal terminations.</p></div>
3819 <div class="paragraph"><p>If any of the commands writes to its standard error file,
3820 then <a href="#_exec"><strong><code>exec</code></strong></a> will return an error, and the error message
3821 will include the pipeline&#8217;s output, followed by messages
3822 about abnormal terminations (if any), followed by the standard error
3823 output.</p></div>
3824 <div class="paragraph"><p>If the last character of the result or error message
3825 is a newline then that character is deleted from the result
3826 or error message for consistency with normal
3827 Tcl return values.</p></div>
3828 <div class="paragraph"><p>An <code><em>arg</em></code> may have one of the following special forms:</p></div>
3829 <div class="dlist"><dl>
3830 <dt class="hdlist1">
3831 <code>&gt;filename</code>
3832 </dt>
3833 <dd>
3835 The standard output of the last command in the pipeline
3836 is redirected to the file. In this situation <a href="#_exec"><strong><code>exec</code></strong></a>
3837 will normally return an empty string.
3838 </p>
3839 </dd>
3840 <dt class="hdlist1">
3841 <code>&gt;&gt;filename</code>
3842 </dt>
3843 <dd>
3845 As above, but append to the file.
3846 </p>
3847 </dd>
3848 <dt class="hdlist1">
3849 <code>&gt;@fileId</code>
3850 </dt>
3851 <dd>
3853 The standard output of the last command in the pipeline is
3854 redirected to the given (writable) file descriptor (e.g. stdout,
3855 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>
3856 will normally return an empty string.
3857 </p>
3858 </dd>
3859 <dt class="hdlist1">
3860 <code>2&gt;filename</code>
3861 </dt>
3862 <dd>
3864 The standard error of the last command in the pipeline
3865 is redirected to the file.
3866 </p>
3867 </dd>
3868 <dt class="hdlist1">
3869 <code>2&gt;&gt;filename</code>
3870 </dt>
3871 <dd>
3873 As above, but append to the file.
3874 </p>
3875 </dd>
3876 <dt class="hdlist1">
3877 <code>2&gt;@fileId</code>
3878 </dt>
3879 <dd>
3881 The standard error of the last command in the pipeline is
3882 redirected to the given (writable) file descriptor.
3883 </p>
3884 </dd>
3885 <dt class="hdlist1">
3886 <code>2&gt;@1</code>
3887 </dt>
3888 <dd>
3890 The standard error of the last command in the pipeline is
3891 redirected to the same file descriptor as the standard output.
3892 </p>
3893 </dd>
3894 <dt class="hdlist1">
3895 <code>&gt;&amp;filename</code>
3896 </dt>
3897 <dd>
3899 Both the standard output and standard error of the last command
3900 in the pipeline is redirected to the file.
3901 </p>
3902 </dd>
3903 <dt class="hdlist1">
3904 <code>&gt;&gt;&amp;filename</code>
3905 </dt>
3906 <dd>
3908 As above, but append to the file.
3909 </p>
3910 </dd>
3911 <dt class="hdlist1">
3912 <code>&lt;filename</code>
3913 </dt>
3914 <dd>
3916 The standard input of the first command in the pipeline
3917 is taken from the file.
3918 </p>
3919 </dd>
3920 <dt class="hdlist1">
3921 <code>&lt;&lt;string</code>
3922 </dt>
3923 <dd>
3925 The standard input of the first command is taken as the
3926 given immediate value.
3927 </p>
3928 </dd>
3929 <dt class="hdlist1">
3930 <code>&lt;@fileId</code>
3931 </dt>
3932 <dd>
3934 The standard input of the first command in the pipeline
3935 is taken from the given (readable) file descriptor.
3936 </p>
3937 </dd>
3938 </dl></div>
3939 <div class="paragraph"><p>If there is no redirection of standard input, standard error
3940 or standard output, these are connected to the corresponding
3941 input or output of the application.</p></div>
3942 <div class="paragraph"><p>If the last <code><em>arg</em></code> is <code>&amp;</code> then the command will be
3943 executed in background.
3944 In this case the standard output from the last command
3945 in the pipeline will
3946 go to the application&#8217;s standard output unless
3947 redirected in the command, and error output from all
3948 the commands in the pipeline will go to the application&#8217;s
3949 standard error file. The return value of exec in this case
3950 is a list of process ids (pids) in the pipeline.</p></div>
3951 <div class="paragraph"><p>Each <code><em>arg</em></code> becomes one word for a command, except for
3952 <code>|</code>, <code>&lt;</code>, <code>&lt;&lt;</code>, <code>&gt;</code>, and <code>&amp;</code> arguments, and the
3953 arguments that follow <code>&lt;</code>, <code>&lt;&lt;</code>, and <code>&gt;</code>.</p></div>
3954 <div class="paragraph"><p>The first word in each command is taken as the command name;
3955 the directories in the PATH environment variable are searched for
3956 an executable by the given name.</p></div>
3957 <div class="paragraph"><p>No <a href="#_glob"><strong><code>glob</code></strong></a> expansion or other shell-like substitutions
3958 are performed on the arguments to commands.</p></div>
3959 <div class="paragraph"><p>If the command fails, the global $::errorCode (and the -errorcode
3960 option in <a href="#_catch"><strong><code>catch</code></strong></a>) will be set to a list, as follows:</p></div>
3961 <div class="dlist"><dl>
3962 <dt class="hdlist1">
3963 <code><strong>CHILDKILLED</strong> <em>pid sigName msg</em></code>
3964 </dt>
3965 <dd>
3967 This format is used when a child process has been killed
3968 because of a signal. The pid element will be the process&#8217;s
3969 identifier (in decimal). The sigName element will be the
3970 symbolic name of the signal that caused the process to
3971 terminate; it will be one of the names from the include
3972 file signal.h, such as SIGPIPE. The msg element will be a
3973 short human-readable message describing the signal, such
3974 as "write on pipe with no readers" for SIGPIPE.
3975 </p>
3976 </dd>
3977 <dt class="hdlist1">
3978 <code><strong>CHILDSUSP</strong> <em>pid sigName msg</em></code>
3979 </dt>
3980 <dd>
3982 This format is used when a child process has been suspended
3983 because of a signal. The pid element will be the process&#8217;s
3984 identifier, in decimal. The sigName element will be the
3985 symbolic name of the signal that caused the process to
3986 suspend; this will be one of the names from the include
3987 file signal.h, such as SIGTTIN. The msg element will be a
3988 short human-readable message describing the signal, such
3989 as "background tty read" for SIGTTIN.
3990 </p>
3991 </dd>
3992 <dt class="hdlist1">
3993 <code><strong>CHILDSTATUS</strong> <em>pid code</em></code>
3994 </dt>
3995 <dd>
3997 This format is used when a child process has exited with a
3998 non-zero exit status. The pid element will be the process&#8217;s
3999 identifier (in decimal) and the code element will be the
4000 exit code returned by the process (also in decimal).
4001 </p>
4002 </dd>
4003 </dl></div>
4004 <div class="paragraph"><p>The environment for the executed command is set from $::env (unless
4005 this variable is unset, in which case the original environment is used).</p></div>
4006 </div>
4007 <div class="sect2">
4008 <h3 id="_exists">exists</h3>
4009 <div class="paragraph"><p><code><strong>exists ?-var|-proc|-command|-alias?</strong> <em>name</em></code></p></div>
4010 <div class="paragraph"><p>Checks the existence of the given variable, procedure, command
4011 or alias respectively and returns 1 if it exists or 0 if not. This command
4012 provides a more simplified/convenient version of <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>,
4013 <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>
4014 <div class="paragraph"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
4015 </div>
4016 <div class="sect2">
4017 <h3 id="_exit">exit</h3>
4018 <div class="paragraph"><p><code><strong>exit</strong> <em>?returnCode?</em></code></p></div>
4019 <div class="paragraph"><p>Terminate the process, returning <code><em>returnCode</em></code> to the
4020 parent as the exit status.</p></div>
4021 <div class="paragraph"><p>If <code><em>returnCode</em></code> isn&#8217;t specified then it defaults
4022 to 0.</p></div>
4023 <div class="paragraph"><p>Note that exit can be caught with <a href="#_catch"><strong><code>catch</code></strong></a>.</p></div>
4024 </div>
4025 <div class="sect2">
4026 <h3 id="_expr">expr</h3>
4027 <div class="paragraph"><p><code><strong>expr</strong> <em>arg</em></code></p></div>
4028 <div class="paragraph"><p>Calls the expression processor to evaluate <code><em>arg</em></code>, and returns
4029 the result as a string. See the section EXPRESSIONS above.</p></div>
4030 <div class="paragraph"><p>Note that Jim supports a shorthand syntax for <a href="#_expr"><strong><code>expr</code></strong></a> as <code>$(...)</code>
4031 The following two are identical.</p></div>
4032 <div class="literalblock">
4033 <div class="content">
4034 <pre><code>set x [expr {3 * 2 + 1}]
4035 set x $(3 * 2 + 1)</code></pre>
4036 </div></div>
4037 </div>
4038 <div class="sect2">
4039 <h3 id="_file">file</h3>
4040 <div class="paragraph"><p><code><strong>file</strong> <em>option name ?arg...?</em></code></p></div>
4041 <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>
4042 <div class="paragraph"><p><code><em>option</em></code> indicates what to do with the file name. Any unique
4043 abbreviation for <code><em>option</em></code> is acceptable. The valid options are:</p></div>
4044 <div class="dlist"><dl>
4045 <dt class="hdlist1">
4046 <code><strong>file atime</strong> <em>name</em></code>
4047 </dt>
4048 <dd>
4050 Return a decimal string giving the time at which file <code><em>name</em></code>
4051 was last accessed. The time is measured in the standard UNIX
4052 fashion as seconds from a fixed starting time (often January 1, 1970).
4053 If the file doesn&#8217;t exist or its access time cannot be queried then an
4054 error is generated.
4055 </p>
4056 </dd>
4057 <dt class="hdlist1">
4058 <code><strong>file copy ?-force?</strong> <em>source target</em></code>
4059 </dt>
4060 <dd>
4062 Copies file <code><em>source</em></code> to file <code><em>target</em></code>. The source file must exist.
4063 The target file must not exist, unless <code>-force</code> is specified.
4064 </p>
4065 </dd>
4066 <dt class="hdlist1">
4067 <code><strong>file delete ?-force? ?--?</strong> <em>name...</em></code>
4068 </dt>
4069 <dd>
4071 Deletes file or directory <code><em>name</em></code>. If the file or directory doesn&#8217;t exist, nothing happens.
4072 If it can&#8217;t be deleted, an error is generated. Non-empty directories will not be deleted
4073 unless the <code>-force</code> options is given. In this case no errors will be generated, even
4074 if the file/directory can&#8217;t be deleted. Use <code><em>--</em></code> if there is any possibility of
4075 the first name being <code><em>-force</em></code>.
4076 </p>
4077 </dd>
4078 <dt class="hdlist1">
4079 <code><strong>file dirname</strong> <em>name</em></code>
4080 </dt>
4081 <dd>
4083 Return all of the characters in <code><em>name</em></code> up to but not including
4084 the last slash character. If there are no slashes in <code><em>name</em></code>
4085 then return <code>.</code> (a single dot). If the last slash in <code><em>name</em></code> is its first
4086 character, then return <code>/</code>.
4087 </p>
4088 </dd>
4089 <dt class="hdlist1">
4090 <code><strong>file executable</strong> <em>name</em></code>
4091 </dt>
4092 <dd>
4094 Return <em>1</em> if file <code><em>name</em></code> is executable by
4095 the current user, <em>0</em> otherwise.
4096 </p>
4097 </dd>
4098 <dt class="hdlist1">
4099 <code><strong>file exists</strong> <em>name</em></code>
4100 </dt>
4101 <dd>
4103 Return <em>1</em> if file <code><em>name</em></code> exists and the current user has
4104 search privileges for the directories leading to it, <em>0</em> otherwise.
4105 </p>
4106 </dd>
4107 <dt class="hdlist1">
4108 <code><strong>file extension</strong> <em>name</em></code>
4109 </dt>
4110 <dd>
4112 Return all of the characters in <code><em>name</em></code> after and including the
4113 last dot in <code><em>name</em></code>. If there is no dot in <code><em>name</em></code> then return
4114 the empty string.
4115 </p>
4116 </dd>
4117 <dt class="hdlist1">
4118 <code><strong>file isdirectory</strong> <em>name</em></code>
4119 </dt>
4120 <dd>
4122 Return <em>1</em> if file <code><em>name</em></code> is a directory,
4123 <em>0</em> otherwise.
4124 </p>
4125 </dd>
4126 <dt class="hdlist1">
4127 <code><strong>file isfile</strong> <em>name</em></code>
4128 </dt>
4129 <dd>
4131 Return <em>1</em> if file <code><em>name</em></code> is a regular file,
4132 <em>0</em> otherwise.
4133 </p>
4134 </dd>
4135 <dt class="hdlist1">
4136 <code><strong>file join</strong> <em>arg...</em></code>
4137 </dt>
4138 <dd>
4140 Joins multiple path components. Note that if any components is
4141 an absolute path, the preceding components are ignored.
4142 Thus <code>"<a href="#_file"><strong><code>file</code></strong></a> join /tmp /root"</code> returns <code>"/root"</code>.
4143 </p>
4144 </dd>
4145 <dt class="hdlist1">
4146 <code><strong>file link</strong> ?<strong>-hard|-symbolic</strong>? <em>newname target</em></code>
4147 </dt>
4148 <dd>
4150 Creates a hard link (default) or symbolic link from <code><em>newname</em></code> to <code><em>target</em></code>.
4151 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>
4152 and also of <code>ln</code>, but this is compatible with Tcl.
4153 An error is returned if <code><em>target</em></code> doesn&#8217;t exist or <code><em>newname</em></code> already exists.
4154 </p>
4155 </dd>
4156 <dt class="hdlist1">
4157 <code><strong>file lstat</strong> <em>name varName</em></code>
4158 </dt>
4159 <dd>
4161 Same as <em>stat</em> option (see below) except uses the <code><em>lstat</em></code>
4162 kernel call instead of <code><em>stat</em></code>. This means that if <code><em>name</em></code>
4163 refers to a symbolic link the information returned in <code><em>varName</em></code>
4164 is for the link rather than the file it refers to. On systems that
4165 don&#8217;t support symbolic links this option behaves exactly the same
4166 as the <em>stat</em> option.
4167 </p>
4168 </dd>
4169 <dt class="hdlist1">
4170 <code><strong>file mkdir</strong> <em>dir1 ?dir2...?</em></code>
4171 </dt>
4172 <dd>
4174 Creates each directory specified. For each pathname <code><em>dir</em></code> specified,
4175 this command will create all non-existing parent directories
4176 as well as <code><em>dir</em></code> itself. If an existing directory is specified,
4177 then no action is taken and no error is returned. Trying to
4178 overwrite an existing file with a directory will result in an
4179 error. Arguments are processed in the order specified, halting
4180 at the first error, if any.
4181 </p>
4182 </dd>
4183 <dt class="hdlist1">
4184 <code><strong>file mtime</strong> <em>name ?time?</em></code>
4185 </dt>
4186 <dd>
4188 Return a decimal string giving the time at which file <code><em>name</em></code>
4189 was last modified. The time is measured in the standard UNIX
4190 fashion as seconds from a fixed starting time (often January 1, 1970).
4191 If the file doesn&#8217;t exist or its modified time cannot be queried then an
4192 error is generated. If <code><em>time</em></code> is given, sets the modification time
4193 of the file to the given value.
4194 </p>
4195 </dd>
4196 <dt class="hdlist1">
4197 <code><strong>file normalize</strong> <em>name</em></code>
4198 </dt>
4199 <dd>
4201 Return the normalized path of <code><em>name</em></code>. See <em>realpath(3)</em>.
4202 </p>
4203 </dd>
4204 <dt class="hdlist1">
4205 <code><strong>file owned</strong> <em>name</em></code>
4206 </dt>
4207 <dd>
4209 Return <em>1</em> if file <code><em>name</em></code> is owned by the current user,
4210 <em>0</em> otherwise.
4211 </p>
4212 </dd>
4213 <dt class="hdlist1">
4214 <code><strong>file readable</strong> <em>name</em></code>
4215 </dt>
4216 <dd>
4218 Return <em>1</em> if file <code><em>name</em></code> is readable by
4219 the current user, <em>0</em> otherwise.
4220 </p>
4221 </dd>
4222 <dt class="hdlist1">
4223 <code><strong>file readlink</strong> <em>name</em></code>
4224 </dt>
4225 <dd>
4227 Returns the value of the symbolic link given by <code><em>name</em></code> (i.e. the
4228 name of the file it points to). If
4229 <code><em>name</em></code> isn&#8217;t a symbolic link or its value cannot be read, then
4230 an error is returned. On systems that don&#8217;t support symbolic links
4231 this option is undefined.
4232 </p>
4233 </dd>
4234 <dt class="hdlist1">
4235 <code><strong>file rename</strong> ?<strong>-force</strong>? <em>oldname</em> <em>newname</em></code>
4236 </dt>
4237 <dd>
4239 Renames the file from the old name to the new name.
4240 If <code><em>newname</em></code> already exists, an error is returned unless <code><em>-force</em></code> is
4241 specified.
4242 </p>
4243 </dd>
4244 <dt class="hdlist1">
4245 <code><strong>file rootname</strong> <em>name</em></code>
4246 </dt>
4247 <dd>
4249 Return all of the characters in <code><em>name</em></code> up to but not including
4250 the last <em>.</em> character in the name. If <code><em>name</em></code> doesn&#8217;t contain
4251 a dot, then return <code><em>name</em></code>.
4252 </p>
4253 </dd>
4254 <dt class="hdlist1">
4255 <code><strong>file size</strong> <em>name</em></code>
4256 </dt>
4257 <dd>
4259 Return a decimal string giving the size of file <code><em>name</em></code> in bytes.
4260 If the file doesn&#8217;t exist or its size cannot be queried then an
4261 error is generated.
4262 </p>
4263 </dd>
4264 <dt class="hdlist1">
4265 <code><strong>file stat</strong> <em>name ?varName?</em></code>
4266 </dt>
4267 <dd>
4269 Invoke the <em>stat</em> kernel call on <code><em>name</em></code>, and return the result
4270 as a dictionary with the following keys: <em>atime</em>,
4271 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
4272 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>.
4273 Each element except <em>type</em> is a decimal string with the value of
4274 the corresponding field from the <em>stat</em> return structure; see the
4275 manual entry for <em>stat</em> for details on the meanings of the values.
4276 The <em>type</em> element gives the type of the file in the same form
4277 returned by the command <a href="#_file"><strong><code>file</code></strong></a> <code>type</code>.
4278 If <code><em>varName</em></code> is specified, it is taken to be the name of an array
4279 variable and the values are also stored into the array.
4280 </p>
4281 </dd>
4282 <dt class="hdlist1">
4283 <code><strong>file tail</strong> <em>name</em></code>
4284 </dt>
4285 <dd>
4287 Return all of the characters in <code><em>name</em></code> after the last slash.
4288 If <code><em>name</em></code> contains no slashes then return <code><em>name</em></code>.
4289 </p>
4290 </dd>
4291 <dt class="hdlist1">
4292 <code><strong>file tempfile</strong> <em>?template?</em></code>
4293 </dt>
4294 <dd>
4296 Creates and returns the name of a unique temporary file. If <code><em>template</em></code> is omitted, a
4297 default template will be used to place the file in /tmp. See <em>mkstemp(3)</em> for
4298 the format of the template and security concerns.
4299 </p>
4300 </dd>
4301 <dt class="hdlist1">
4302 <code><strong>file type</strong> <em>name</em></code>
4303 </dt>
4304 <dd>
4306 Returns a string giving the type of file <code><em>name</em></code>, which will be
4307 one of <code>file</code>, <code>directory</code>, <code>characterSpecial</code>,
4308 <code>blockSpecial</code>, <code>fifo</code>, <code>link</code>, or <code>socket</code>.
4309 </p>
4310 </dd>
4311 <dt class="hdlist1">
4312 <code><strong>file writable</strong> <em>name</em></code>
4313 </dt>
4314 <dd>
4316 Return <em>1</em> if file <code><em>name</em></code> is writable by
4317 the current user, <em>0</em> otherwise.
4318 </p>
4319 </dd>
4320 </dl></div>
4321 <div class="paragraph"><p>The <a href="#_file"><strong><code>file</code></strong></a> commands that return 0/1 results are often used in
4322 conditional or looping commands, for example:</p></div>
4323 <div class="literalblock">
4324 <div class="content">
4325 <pre><code>if {![file exists foo]} {
4326 error {bad file name}
4327 } else {
4329 }</code></pre>
4330 </div></div>
4331 </div>
4332 <div class="sect2">
4333 <h3 id="_finalize">finalize</h3>
4334 <div class="paragraph"><p><code><strong>finalize</strong> <em>reference ?command?</em></code></p></div>
4335 <div class="paragraph"><p>If <code><em>command</em></code> is omitted, returns the finalizer command for the given reference.</p></div>
4336 <div class="paragraph"><p>Otherwise, sets a new finalizer command for the given reference. <code><em>command</em></code> may be
4337 the empty string to remove the current finalizer.</p></div>
4338 <div class="paragraph"><p>The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
4339 command.</p></div>
4340 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4341 </div>
4342 <div class="sect2">
4343 <h3 id="_flush">flush</h3>
4344 <div class="paragraph"><p><code><strong>flush</strong> <em>fileId</em></code></p></div>
4345 <div class="paragraph"><p><code><em>fileId</em> <strong>flush</strong></code></p></div>
4346 <div class="paragraph"><p>Flushes any output that has been buffered for <code><em>fileId</em></code>. <code><em>fileId</em></code> must
4347 have been the return value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
4348 <code>stdout</code> or <code>stderr</code> to access one of the standard I/O streams; it must
4349 refer to a file that was opened for writing. This command returns an
4350 empty string.</p></div>
4351 </div>
4352 <div class="sect2">
4353 <h3 id="_for">for</h3>
4354 <div class="paragraph"><p><code><strong>for</strong> <em>start test next body</em></code></p></div>
4355 <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.
4356 The <code><em>start</em></code>, <code><em>next</em></code>, and <code><em>body</em></code> arguments must be Tcl command strings,
4357 and <code><em>test</em></code> is an expression string.</p></div>
4358 <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>.
4359 Then it repeatedly evaluates <code><em>test</em></code> as an expression; if the result is
4360 non-zero it invokes the Tcl interpreter on <code><em>body</em></code>, then invokes the Tcl
4361 interpreter on <code><em>next</em></code>, then repeats the loop. The command terminates
4362 when <code><em>test</em></code> evaluates to 0.</p></div>
4363 <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
4364 commands in the current execution of <code><em>body</em></code> are skipped; processing
4365 continues by invoking the Tcl interpreter on <code><em>next</em></code>, then evaluating
4366 <code><em>test</em></code>, and so on.</p></div>
4367 <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>
4368 command will return immediately.</p></div>
4369 <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
4370 statements in C.</p></div>
4371 <div class="paragraph"><p><a href="#_for"><strong><code>for</code></strong></a> returns an empty string.</p></div>
4372 </div>
4373 <div class="sect2">
4374 <h3 id="_foreach">foreach</h3>
4375 <div class="paragraph"><p><code><strong>foreach</strong> <em>varName list body</em></code></p></div>
4376 <div class="paragraph"><p><code><strong>foreach</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
4377 <div class="paragraph"><p>In this command, <code><em>varName</em></code> is the name of a variable, <code><em>list</em></code>
4378 is a list of values to assign to <code><em>varName</em></code>, and <code><em>body</em></code> is a
4379 collection of Tcl commands.</p></div>
4380 <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
4381 the contents of the field to <code><em>varName</em></code> (as if the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4382 had been used to extract the field), then calls the Tcl interpreter to
4383 execute <code><em>body</em></code>.</p></div>
4384 <div class="paragraph"><p>If instead of being a simple name, <code><em>varList</em></code> is used, multiple assignments
4385 are made each time through the loop, one for each element of <code><em>varList</em></code>.</p></div>
4386 <div class="paragraph"><p>For example, if there are two elements in <code><em>varList</em></code> and six elements in
4387 the list, the loop will be executed three times.</p></div>
4388 <div class="paragraph"><p>If the length of the list doesn&#8217;t evenly divide by the number of elements
4389 in <code><em>varList</em></code>, the value of the remaining variables in the last iteration
4390 of the loop are undefined.</p></div>
4391 <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>,
4392 with the same effect as in the <a href="#_for"><strong><code>for</code></strong></a> command.</p></div>
4393 <div class="paragraph"><p><a href="#_foreach"><strong><code>foreach</code></strong></a> returns an empty string.</p></div>
4394 </div>
4395 <div class="sect2">
4396 <h3 id="_format">format</h3>
4397 <div class="paragraph"><p><code><strong>format</strong> <em>formatString ?arg ...?</em></code></p></div>
4398 <div class="paragraph"><p>This command generates a formatted string in the same way as the
4399 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
4400 implementation). <code><em>formatString</em></code> indicates how to format
4401 the result, using <code>%</code> fields as in <em>sprintf</em>, and the additional
4402 arguments, if any, provide values to be substituted into the result.</p></div>
4403 <div class="paragraph"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
4404 man page for details. Each <code><em>arg</em></code> must match the expected type
4405 from the <code>%</code> field in <code><em>formatString</em></code>; the <a href="#_format"><strong><code>format</code></strong></a> command
4406 converts each argument to the correct type (floating, integer, etc.)
4407 before passing it to <em>sprintf</em> for formatting.</p></div>
4408 <div class="paragraph"><p>The only unusual conversion is for <code>%c</code>; in this case the argument
4409 must be a decimal string, which will then be converted to the corresponding
4410 ASCII (or UTF-8) character value.</p></div>
4411 <div class="paragraph"><p>In addition, Jim Tcl provides basic support for conversion to binary with <code>%b</code>.</p></div>
4412 <div class="paragraph"><p><a href="#_format"><strong><code>format</code></strong></a> does backslash substitution on its <code><em>formatString</em></code>
4413 argument, so backslash sequences in <code><em>formatString</em></code> will be handled
4414 correctly even if the argument is in braces.</p></div>
4415 <div class="paragraph"><p>The return value from <a href="#_format"><strong><code>format</code></strong></a> is the formatted string.</p></div>
4416 </div>
4417 <div class="sect2">
4418 <h3 id="_getref">getref</h3>
4419 <div class="paragraph"><p><code><strong>getref</strong> <em>reference</em></code></p></div>
4420 <div class="paragraph"><p>Returns the string associated with <code><em>reference</em></code>. The reference must
4421 be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a> command.</p></div>
4422 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4423 </div>
4424 <div class="sect2">
4425 <h3 id="_gets">gets</h3>
4426 <div class="paragraph"><p><code><strong>gets</strong> <em>fileId ?varName?</em></code></p></div>
4427 <div class="paragraph"><p><code><em>fileId</em> <strong>gets</strong> <em>?varName?</em></code></p></div>
4428 <div class="paragraph"><p>Reads the next line from the file given by <code><em>fileId</em></code> and discards
4429 the terminating newline character.</p></div>
4430 <div class="paragraph"><p>If <code><em>varName</em></code> is specified, then the line is placed in the variable
4431 by that name and the return value is a count of the number of characters
4432 read (not including the newline).</p></div>
4433 <div class="paragraph"><p>If the end of the file is reached before reading
4434 any characters then -1 is returned and <code><em>varName</em></code> is set to an
4435 empty string.</p></div>
4436 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified then the return value will be
4437 the line (minus the newline character) or an empty string if
4438 the end of the file is reached before reading any characters.</p></div>
4439 <div class="paragraph"><p>An empty string will also be returned if a line contains no characters
4440 except the newline, so <a href="#_eof"><strong><code>eof</code></strong></a> may have to be used to determine
4441 what really happened.</p></div>
4442 <div class="paragraph"><p>If the last character in the file is not a newline character, then
4443 <a href="#_gets"><strong><code>gets</code></strong></a> behaves as if there were an additional newline character
4444 at the end of the file.</p></div>
4445 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous
4446 call to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened
4447 for reading.</p></div>
4448 </div>
4449 <div class="sect2">
4450 <h3 id="_glob">glob</h3>
4451 <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>
4452 <div class="paragraph"><p>This command performs filename globbing, using csh rules. The returned
4453 value from <a href="#_glob"><strong><code>glob</code></strong></a> is the list of expanded filenames.</p></div>
4454 <div class="paragraph"><p>If <code>-nocomplain</code> is specified as the first argument then an empty
4455 list may be returned; otherwise an error is returned if the expanded
4456 list is empty. The <code>-nocomplain</code> argument must be provided
4457 exactly: an abbreviation will not be accepted.</p></div>
4458 <div class="paragraph"><p>If <code>-directory</code> is given, the <code><em>dir</em></code> is understood to contain a
4459 directory name to search in. This allows globbing inside directories
4460 whose names may contain glob-sensitive characters. The returned names
4461 include the directory name unless <code><em>-tails</em></code> is specified.</p></div>
4462 <div class="paragraph"><p>If <code><em>-tails</em></code> is specified, along with <code>-directory</code>, the returned names
4463 are relative to the given directory.</p></div>
4464 </div>
4465 <div class="sect2">
4466 <h3 id="_global">global</h3>
4467 <div class="paragraph"><p><code><strong>global</strong> <em>varName ?varName ...?</em></code></p></div>
4468 <div class="paragraph"><p>This command is ignored unless a Tcl procedure is being interpreted.
4469 If so, then it declares each given <code><em>varName</em></code> to be a global variable
4470 rather than a local one. For the duration of the current procedure
4471 (and only while executing in the current procedure), any reference to
4472 <code><em>varName</em></code> will be bound to a global variable instead
4473 of a local one.</p></div>
4474 <div class="paragraph"><p>An alternative to using <a href="#_global"><strong><code>global</code></strong></a> is to use the <code>::</code> prefix
4475 to explicitly name a variable in the global scope.</p></div>
4476 </div>
4477 <div class="sect2">
4478 <h3 id="_if">if</h3>
4479 <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>
4480 <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
4481 that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument). The value of the expression must
4482 be numeric; if it is non-zero then <code><em>body1</em></code> is executed by passing it to
4483 the Tcl interpreter.</p></div>
4484 <div class="paragraph"><p>Otherwise <code><em>expr2</em></code> is evaluated as an expression and if it is non-zero
4485 then <code><em>body2</em></code> is executed, and so on.</p></div>
4486 <div class="paragraph"><p>If none of the expressions evaluates to non-zero then <code><em>bodyN</em></code> is executed.</p></div>
4487 <div class="paragraph"><p>The <code>then</code> and <code>else</code> arguments are optional "noise words" to make the
4488 command easier to read.</p></div>
4489 <div class="paragraph"><p>There may be any number of <code>elseif</code> clauses, including zero. <code><em>bodyN</em></code>
4490 may also be omitted as long as <code>else</code> is omitted too.</p></div>
4491 <div class="paragraph"><p>The return value from the command is the result of the body script that
4492 was executed, or an empty string if none of the expressions was non-zero
4493 and there was no <code><em>bodyN</em></code>.</p></div>
4494 </div>
4495 <div class="sect2">
4496 <h3 id="_incr">incr</h3>
4497 <div class="paragraph"><p><code><strong>incr</strong> <em>varName ?increment?</em></code></p></div>
4498 <div class="paragraph"><p>Increment the value stored in the variable whose name is <code><em>varName</em></code>.
4499 The value of the variable must be integral.</p></div>
4500 <div class="paragraph"><p>If <code><em>increment</em></code> is supplied then its value (which must be an
4501 integer) is added to the value of variable <code><em>varName</em></code>; otherwise
4502 1 is added to <code><em>varName</em></code>.</p></div>
4503 <div class="paragraph"><p>The new value is stored as a decimal string in variable <code><em>varName</em></code>
4504 and also returned as result.</p></div>
4505 <div class="paragraph"><p>If the variable does not exist, the variable is implicitly created
4506 and set to <code>0</code> first.</p></div>
4507 </div>
4508 <div class="sect2">
4509 <h3 id="_info">info</h3>
4510 <div class="dlist"><dl>
4511 <dt class="hdlist1">
4512 <code><strong>info</strong> <em>option ?arg...?</em></code>
4513 </dt>
4514 <dd>
4516 Provide information about various internals to the Tcl interpreter.
4517 The legal <code><em>option</em></code>'s (which may be abbreviated) are:
4518 </p>
4519 </dd>
4520 <dt class="hdlist1">
4521 <code><strong>info args</strong> <em>procname</em></code>
4522 </dt>
4523 <dd>
4525 Returns a list containing the names of the arguments to procedure
4526 <code><em>procname</em></code>, in order. <code><em>procname</em></code> must be the name of a
4527 Tcl command procedure.
4528 </p>
4529 </dd>
4530 <dt class="hdlist1">
4531 <code><strong>info alias</strong> <em>command</em></code>
4532 </dt>
4533 <dd>
4535 <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
4536 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>
4537 </p>
4538 </dd>
4539 <dt class="hdlist1">
4540 <code><strong>info body</strong> <em>procname</em></code>
4541 </dt>
4542 <dd>
4544 Returns the body of procedure <code><em>procname</em></code>. <code><em>procname</em></code> must be
4545 the name of a Tcl command procedure.
4546 </p>
4547 </dd>
4548 <dt class="hdlist1">
4549 <code><strong>info channels</strong></code>
4550 </dt>
4551 <dd>
4553 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>
4554 </p>
4555 </dd>
4556 <dt class="hdlist1">
4557 <code><strong>info commands</strong> ?<em>pattern</em>?</code>
4558 </dt>
4559 <dd>
4561 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of names of all the
4562 Tcl commands, including both the built-in commands written in C and
4563 the command procedures defined using the <a href="#_proc"><strong><code>proc</code></strong></a> command.
4564 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4565 are returned. Matching is determined using the same rules as for
4566 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4567 </p>
4568 </dd>
4569 <dt class="hdlist1">
4570 <code><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</code>
4571 </dt>
4572 <dd>
4574 Returns 1 if <code><em>command</em></code> is a complete Tcl command in the sense of
4575 having no unclosed quotes, braces, brackets or array element names,
4576 If the command doesn&#8217;t appear to be complete then 0 is returned.
4577 This command is typically used in line-oriented input environments
4578 to allow users to type in commands that span multiple lines; if the
4579 command isn&#8217;t complete, the script can delay evaluating it until additional
4580 lines have been typed to complete the command. If <code><em>varName</em></code> is specified, the
4581 missing character is stored in the variable with that name.
4582 </p>
4583 </dd>
4584 <dt class="hdlist1">
4585 <code><strong>info exists</strong> <em>varName</em></code>
4586 </dt>
4587 <dd>
4589 Returns <em>1</em> if the variable named <code><em>varName</em></code> exists in the
4590 current context (either as a global or local variable), returns <em>0</em>
4591 otherwise.
4592 </p>
4593 </dd>
4594 <dt class="hdlist1">
4595 <code><strong>info frame</strong> ?<em>number</em>?</code>
4596 </dt>
4597 <dd>
4599 If <code><em>number</em></code> is not specified, this command returns a number
4600 which is the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> - the current stack frame level.
4601 If <code><em>number</em></code> is specified, then the result is a list consisting of the procedure,
4602 filename and line number for the procedure call at level <code><em>number</em></code> on the stack.
4603 If <code><em>number</em></code> is positive then it selects a particular stack level (1 refers
4604 to the top-most active procedure, 2 to the procedure it called, and
4605 so on); otherwise it gives a level relative to the current level
4606 (0 refers to the current procedure, -1 to its caller, and so on).
4607 The level has an identical meaning to <a href="#_info"><strong><code>info</code></strong></a> <code>level</code>.
4608 </p>
4609 </dd>
4610 <dt class="hdlist1">
4611 <code><strong>info globals</strong> ?<em>pattern</em>?</code>
4612 </dt>
4613 <dd>
4615 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4616 of currently-defined global variables.
4617 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4618 are returned. Matching is determined using the same rules as for
4619 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4620 </p>
4621 </dd>
4622 <dt class="hdlist1">
4623 <code><strong>info hostname</strong></code>
4624 </dt>
4625 <dd>
4627 An alias for <a href="#cmd_1"><strong><code>os.gethostname</code></strong></a> for compatibility with Tcl 6.x
4628 </p>
4629 </dd>
4630 <dt class="hdlist1">
4631 <code><strong>info level</strong> ?<em>number</em>?</code>
4632 </dt>
4633 <dd>
4635 If <code><em>number</em></code> is not specified, this command returns a number
4636 giving the stack level of the invoking procedure, or 0 if the
4637 command is invoked at top-level. If <code><em>number</em></code> is specified,
4638 then the result is a list consisting of the name and arguments for the
4639 procedure call at level <code><em>number</em></code> on the stack. If <code><em>number</em></code>
4640 is positive then it selects a particular stack level (1 refers
4641 to the top-most active procedure, 2 to the procedure it called, and
4642 so on); otherwise it gives a level relative to the current level
4643 (0 refers to the current procedure, -1 to its caller, and so on).
4644 See the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command for more information on what stack
4645 levels mean.
4646 </p>
4647 </dd>
4648 <dt class="hdlist1">
4649 <code><strong>info locals</strong> ?<em>pattern</em>?</code>
4650 </dt>
4651 <dd>
4653 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4654 of currently-defined local variables, including arguments to the
4655 current procedure, if any. Variables defined with the <a href="#_global"><strong><code>global</code></strong></a>
4656 and <a href="#_upvar"><strong><code>upvar</code></strong></a> commands will not be returned. If <code><em>pattern</em></code> is
4657 specified, only those names matching <code><em>pattern</em></code> are returned.
4658 Matching is determined using the same rules as for <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4659 </p>
4660 </dd>
4661 <dt class="hdlist1">
4662 <code><strong>info nameofexecutable</strong></code>
4663 </dt>
4664 <dd>
4666 Returns the name of the binary file from which the application
4667 was invoked. A full path will be returned, unless the path
4668 can&#8217;t be determined, in which case the empty string will be returned.
4669 </p>
4670 </dd>
4671 <dt class="hdlist1">
4672 <code><strong>info procs</strong> ?<em>pattern</em>?</code>
4673 </dt>
4674 <dd>
4676 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the
4677 names of Tcl command procedures.
4678 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4679 are returned. Matching is determined using the same rules as for
4680 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4681 </p>
4682 </dd>
4683 <dt class="hdlist1">
4684 <code><strong>info references</strong></code>
4685 </dt>
4686 <dd>
4688 Returns a list of all references which have not yet been garbage
4689 collected.
4690 </p>
4691 </dd>
4692 <dt class="hdlist1">
4693 <code><strong>info returncodes</strong> ?<em>code</em>?</code>
4694 </dt>
4695 <dd>
4697 Returns a list representing the mapping of standard return codes
4698 to names. e.g. <code>{0 ok 1 error 2 return ...}</code>. If a code is given,
4699 instead returns the name for the given code.
4700 </p>
4701 </dd>
4702 <dt class="hdlist1">
4703 <code><strong>info script</strong></code>
4704 </dt>
4705 <dd>
4707 If a Tcl script file is currently being evaluated (i.e. there is a
4708 call to <em>Jim_EvalFile</em> active or there is an active invocation
4709 of the <a href="#_source"><strong><code>source</code></strong></a> command), then this command returns the name
4710 of the innermost file being processed. Otherwise the command returns an
4711 empty string.
4712 </p>
4713 </dd>
4714 <dt class="hdlist1">
4715 <code><strong>info source</strong> <em>script ?filename line?</em></code>
4716 </dt>
4717 <dd>
4719 With a single argument, returns the original source location of the given script as a list of
4720 <code>{filename linenumber}</code>. If the source location can&#8217;t be determined, the
4721 list <code>{{} 0}</code> is returned. If <code><em>filename</em></code> and <code><em>line</em></code> are given, returns a copy
4722 of <code><em>script</em></code> with the associate source information. This can be useful to produce
4723 useful messages from <a href="#_eval"><strong><code>eval</code></strong></a>, etc. if the original source information may be lost.
4724 </p>
4725 </dd>
4726 <dt class="hdlist1">
4727 <code><strong>info stacktrace</strong></code>
4728 </dt>
4729 <dd>
4731 After an error is caught with <a href="#_catch"><strong><code>catch</code></strong></a>, returns the stack trace as a list
4732 of <code>{procedure filename line ...}</code>.
4733 </p>
4734 </dd>
4735 <dt class="hdlist1">
4736 <code><strong>info statics</strong> <em>procname</em></code>
4737 </dt>
4738 <dd>
4740 Returns a dictionary of the static variables of procedure
4741 <code><em>procname</em></code>. <code><em>procname</em></code> must be the name of a Tcl command
4742 procedure. An empty dictionary is returned if the procedure has
4743 no static variables.
4744 </p>
4745 </dd>
4746 <dt class="hdlist1">
4747 <code><strong>info version</strong></code>
4748 </dt>
4749 <dd>
4751 Returns the version number for this version of Jim in the form <code><strong>x.yy</strong></code>.
4752 </p>
4753 </dd>
4754 <dt class="hdlist1">
4755 <code><strong>info vars</strong> ?<em>pattern</em>?</code>
4756 </dt>
4757 <dd>
4759 If <code><em>pattern</em></code> isn&#8217;t specified,
4760 returns a list of all the names of currently-visible variables, including
4761 both locals and currently-visible globals.
4762 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4763 are returned. Matching is determined using the same rules as for
4764 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4765 </p>
4766 </dd>
4767 </dl></div>
4768 </div>
4769 <div class="sect2">
4770 <h3 id="_join">join</h3>
4771 <div class="paragraph"><p><code><strong>join</strong> <em>list ?joinString?</em></code></p></div>
4772 <div class="paragraph"><p>The <code><em>list</em></code> argument must be a valid Tcl list. This command returns the
4773 string formed by joining all of the elements of <code><em>list</em></code> together with
4774 <code><em>joinString</em></code> separating each adjacent pair of elements.</p></div>
4775 <div class="paragraph"><p>The <code><em>joinString</em></code> argument defaults to a space character.</p></div>
4776 </div>
4777 <div class="sect2">
4778 <h3 id="_kill">kill</h3>
4779 <div class="paragraph"><p><code><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></code></p></div>
4780 <div class="paragraph"><p>Sends the given signal to the process identified by <code><em>pid</em></code>.</p></div>
4781 <div class="paragraph"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4782 <div class="ulist"><ul>
4783 <li>
4785 <code>TERM</code>
4786 </p>
4787 </li>
4788 <li>
4790 <code>SIGTERM</code>
4791 </p>
4792 </li>
4793 <li>
4795 <code>-TERM</code>
4796 </p>
4797 </li>
4798 <li>
4800 <code>15</code>
4801 </p>
4802 </li>
4803 <li>
4805 <code>-15</code>
4806 </p>
4807 </li>
4808 </ul></div>
4809 <div class="paragraph"><p>The signal name may be in either upper or lower case.</p></div>
4810 <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>
4811 <div class="paragraph"><p>If no signal is specified, SIGTERM is used.</p></div>
4812 <div class="paragraph"><p>An error is raised if the signal could not be delivered.</p></div>
4813 </div>
4814 <div class="sect2">
4815 <h3 id="_lambda_2">lambda</h3>
4816 <div class="paragraph"><p><code><strong>lambda</strong> <em>args ?statics? body</em></code></p></div>
4817 <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
4818 creating a named procedure, it creates an anonymous procedure and returns
4819 the name of the procedure.</p></div>
4820 <div class="paragraph"><p>See <a href="#_proc"><strong><code>proc</code></strong></a> and GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4821 </div>
4822 <div class="sect2">
4823 <h3 id="_lappend">lappend</h3>
4824 <div class="paragraph"><p><code><strong>lappend</strong> <em>varName value ?value value ...?</em></code></p></div>
4825 <div class="paragraph"><p>Treat the variable given by <code><em>varName</em></code> as a list and append each of
4826 the <code><em>value</em></code> arguments to that list as a separate element, with spaces
4827 between elements.</p></div>
4828 <div class="paragraph"><p>If <code><em>varName</em></code> doesn&#8217;t exist, it is created as a list with elements given
4829 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
4830 each <code><em>value</em></code> is appended as a list element rather than raw text.</p></div>
4831 <div class="paragraph"><p>This command provides a relatively efficient way to build up large lists.
4832 For example,</p></div>
4833 <div class="literalblock">
4834 <div class="content">
4835 <pre><code>lappend a $b</code></pre>
4836 </div></div>
4837 <div class="paragraph"><p>is much more efficient than</p></div>
4838 <div class="literalblock">
4839 <div class="content">
4840 <pre><code>set a [concat $a [list $b]]</code></pre>
4841 </div></div>
4842 <div class="paragraph"><p>when <code>$a</code> is long.</p></div>
4843 </div>
4844 <div class="sect2">
4845 <h3 id="_lassign">lassign</h3>
4846 <div class="paragraph"><p><code><strong>lassign</strong> <em>list varName ?varName ...?</em></code></p></div>
4847 <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
4848 the variables given by the <code><em>varName</em></code> arguments in order. If there are more variable names than
4849 list elements, the remaining variables are set to the empty string. If there are more list ele-
4850 ments than variables, a list of unassigned elements is returned.</p></div>
4851 <div class="literalblock">
4852 <div class="content">
4853 <pre><code>jim&gt; lassign {1 2 3} a b; puts a=$a,b=$b
4855 a=1,b=2</code></pre>
4856 </div></div>
4857 </div>
4858 <div class="sect2">
4859 <h3 id="_local">local</h3>
4860 <div class="paragraph"><p><code><strong>local</strong> <em>cmd ?arg...?</em></code></p></div>
4861 <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
4862 be the name of an existing command, which is marked as having local scope.
4863 This means that when the current procedure exits, the specified
4864 command is deleted. This can be useful with <a href="#_lambda"><strong><code>lambda</code></strong></a>, local procedures or
4865 to automatically close a filehandle.</p></div>
4866 <div class="paragraph"><p>In addition, if a command already exists with the same name,
4867 the existing command will be kept rather than deleted, and may be called
4868 via <a href="#_upcall"><strong><code>upcall</code></strong></a>. The previous command will be restored when the current
4869 procedure exits. See <a href="#_upcall"><strong><code>upcall</code></strong></a> for more details.</p></div>
4870 <div class="paragraph"><p>In this example, a local procedure is created. Note that the procedure
4871 continues to have global scope while it is active.</p></div>
4872 <div class="literalblock">
4873 <div class="content">
4874 <pre><code>proc outer {} {
4875 # proc ... returns "inner" which is marked local
4876 local proc inner {} {
4877 # will be deleted when 'outer' exits
4878 }</code></pre>
4879 </div></div>
4880 <div class="literalblock">
4881 <div class="content">
4882 <pre><code> inner
4884 }</code></pre>
4885 </div></div>
4886 <div class="paragraph"><p>In this example, the lambda is deleted at the end of the procedure rather
4887 than waiting until garbage collection.</p></div>
4888 <div class="literalblock">
4889 <div class="content">
4890 <pre><code>proc outer {} {
4891 set x [lambda inner {args} {
4892 # will be deleted when 'outer' exits
4894 # Use 'function' here which simply returns $x
4895 local function $x</code></pre>
4896 </div></div>
4897 <div class="literalblock">
4898 <div class="content">
4899 <pre><code> $x ...
4901 }</code></pre>
4902 </div></div>
4903 </div>
4904 <div class="sect2">
4905 <h3 id="_loop">loop</h3>
4906 <div class="paragraph"><p><code><strong>loop</strong> <em>var first limit ?incr? body</em></code></p></div>
4907 <div class="paragraph"><p>Similar to <a href="#_for"><strong><code>for</code></strong></a> except simpler and possibly more efficient.
4908 With a positive increment, equivalent to:</p></div>
4909 <div class="literalblock">
4910 <div class="content">
4911 <pre><code>for {set var $first} {$var &lt; $limit} {incr var $incr} $body</code></pre>
4912 </div></div>
4913 <div class="paragraph"><p>If <code><em>incr</em></code> is not specified, 1 is used.
4914 Note that setting the loop variable inside the loop does not
4915 affect the loop count.</p></div>
4916 </div>
4917 <div class="sect2">
4918 <h3 id="_lindex">lindex</h3>
4919 <div class="paragraph"><p><code><strong>lindex</strong> <em>list ?index &#8230;?</em></code></p></div>
4920 <div class="paragraph"><p>Treats <code><em>list</em></code> as a Tcl list and returns element <code><em>index</em></code> from it
4921 (0 refers to the first element of the list).
4922 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4923 <div class="paragraph"><p>In extracting the element, <code><em>lindex</em></code> observes the same rules concerning
4924 braces and quotes and backslashes as the Tcl command interpreter; however,
4925 variable substitution and command substitution do not occur.</p></div>
4926 <div class="paragraph"><p>If no index values are given, simply returns <code><em>list</em></code></p></div>
4927 <div class="paragraph"><p>If <code><em>index</em></code> is negative or greater than or equal to the number of elements
4928 in <code><em>list</em></code>, then an empty string is returned.</p></div>
4929 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
4930 used in turn to select an element from the previous indexing
4931 operation, allowing the script to select elements from sublists.</p></div>
4932 </div>
4933 <div class="sect2">
4934 <h3 id="_linsert">linsert</h3>
4935 <div class="paragraph"><p><code><strong>linsert</strong> <em>list index element ?element element ...?</em></code></p></div>
4936 <div class="paragraph"><p>This command produces a new list from <code><em>list</em></code> by inserting all
4937 of the <code><em>element</em></code> arguments just before the element <code><em>index</em></code>
4938 of <code><em>list</em></code>. Each <code><em>element</em></code> argument will become
4939 a separate element of the new list. If <code><em>index</em></code> is less than
4940 or equal to zero, then the new elements are inserted at the
4941 beginning of the list. If <code><em>index</em></code> is greater than or equal
4942 to the number of elements in the list, then the new elements are
4943 appended to the list.</p></div>
4944 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4945 </div>
4946 <div class="sect2">
4947 <h3 id="_list">list</h3>
4948 <div class="paragraph"><p><code><strong>list</strong> <em>arg ?arg ...?</em></code></p></div>
4949 <div class="paragraph"><p>This command returns a list comprised of all the arguments, <code><em>arg</em></code>. Braces
4950 and backslashes get added as necessary, so that the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4951 may be used on the result to re-extract the original arguments, and also
4952 so that <a href="#_eval"><strong><code>eval</code></strong></a> may be used to execute the resulting list, with
4953 <code><em>arg1</em></code> comprising the command&#8217;s name and the other args comprising
4954 its arguments. <a href="#_list"><strong><code>list</code></strong></a> produces slightly different results than
4955 <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
4956 the list, while <a href="#_list"><strong><code>list</code></strong></a> works directly from the original arguments.
4957 For example, the command</p></div>
4958 <div class="literalblock">
4959 <div class="content">
4960 <pre><code>list a b {c d e} {f {g h}}</code></pre>
4961 </div></div>
4962 <div class="paragraph"><p>will return</p></div>
4963 <div class="literalblock">
4964 <div class="content">
4965 <pre><code>a b {c d e} {f {g h}}</code></pre>
4966 </div></div>
4967 <div class="paragraph"><p>while <a href="#_concat"><strong><code>concat</code></strong></a> with the same arguments will return</p></div>
4968 <div class="literalblock">
4969 <div class="content">
4970 <pre><code>a b c d e f {g h}</code></pre>
4971 </div></div>
4972 </div>
4973 <div class="sect2">
4974 <h3 id="_llength">llength</h3>
4975 <div class="paragraph"><p><code><strong>llength</strong> <em>list</em></code></p></div>
4976 <div class="paragraph"><p>Treats <code><em>list</em></code> as a list and returns a decimal string giving
4977 the number of elements in it.</p></div>
4978 </div>
4979 <div class="sect2">
4980 <h3 id="_lset">lset</h3>
4981 <div class="paragraph"><p><code><strong>lset</strong> <em>varName ?index ..? newValue</em></code></p></div>
4982 <div class="paragraph"><p>Sets an element in a list.</p></div>
4983 <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
4984 as the name of a variable containing a Tcl list. It also accepts
4985 zero or more indices into the list. Finally, it accepts a new value
4986 for an element of varName. If no indices are presented, the command
4987 takes the form:</p></div>
4988 <div class="literalblock">
4989 <div class="content">
4990 <pre><code>lset varName newValue</code></pre>
4991 </div></div>
4992 <div class="paragraph"><p>In this case, newValue replaces the old value of the variable
4993 varName.</p></div>
4994 <div class="paragraph"><p>When presented with a single index, the <a href="#_lset"><strong><code>lset</code></strong></a> command
4995 treats the content of the varName variable as a Tcl list. It addresses
4996 the index&#8217;th element in it (0 refers to the first element of the
4997 list). When interpreting the list, <a href="#_lset"><strong><code>lset</code></strong></a> observes the same rules
4998 concerning braces and quotes and backslashes as the Tcl command
4999 interpreter; however, variable substitution and command substitution
5000 do not occur. The command constructs a new list in which the
5001 designated element is replaced with newValue. This new list is
5002 stored in the variable varName, and is also the return value from
5003 the <a href="#_lset"><strong><code>lset</code></strong></a> command.</p></div>
5004 <div class="paragraph"><p>If index is negative or greater than or equal to the number of
5005 elements in $varName, then an error occurs.</p></div>
5006 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
5007 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
5008 used in turn to address an element within a sublist designated by
5009 the previous indexing operation, allowing the script to alter
5010 elements in sublists. The command,</p></div>
5011 <div class="literalblock">
5012 <div class="content">
5013 <pre><code>lset a 1 2 newValue</code></pre>
5014 </div></div>
5015 <div class="paragraph"><p>replaces element 2 of sublist 1 with <code><em>newValue</em></code>.</p></div>
5016 <div class="paragraph"><p>The integer appearing in each index argument must be greater than
5017 or equal to zero. The integer appearing in each index argument must
5018 be strictly less than the length of the corresponding list. In other
5019 words, the <a href="#_lset"><strong><code>lset</code></strong></a> command cannot change the size of a list. If an
5020 index is outside the permitted range, an error is reported.</p></div>
5021 </div>
5022 <div class="sect2">
5023 <h3 id="_lmap">lmap</h3>
5024 <div class="paragraph"><p><code><strong>lmap</strong> <em>varName list body</em></code></p></div>
5025 <div class="paragraph"><p><code><strong>lmap</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
5026 <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>
5027 <div class="paragraph"><p>For example:</p></div>
5028 <div class="literalblock">
5029 <div class="content">
5030 <pre><code>jim&gt; lmap i {1 2 3 4 5} {expr $i*$i}
5031 1 4 9 16 25
5032 jim&gt; lmap a {1 2 3} b {A B C} {list $a $b}
5033 {1 A} {2 B} {3 C}</code></pre>
5034 </div></div>
5035 <div class="paragraph"><p>If the body invokes <a href="#_continue"><strong><code>continue</code></strong></a>, no value is added for this iteration.
5036 If the body invokes <a href="#_break"><strong><code>break</code></strong></a>, the loop ends and no more values are added.</p></div>
5037 </div>
5038 <div class="sect2">
5039 <h3 id="_load">load</h3>
5040 <div class="paragraph"><p><code><strong>load</strong> <em>filename</em></code></p></div>
5041 <div class="paragraph"><p>Loads the dynamic extension, <code><em>filename</em></code>. Generally the filename should have
5042 the extension <code>.so</code>. The initialisation function for the module must be based
5043 on the name of the file. For example loading <code>hwaccess.so</code> will invoke
5044 the initialisation function, <code>Jim_hwaccessInit</code>. Normally the <a href="#_load"><strong><code>load</code></strong></a> command
5045 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>
5046 </div>
5047 <div class="sect2">
5048 <h3 id="_lrange">lrange</h3>
5049 <div class="paragraph"><p><code><strong>lrange</strong> <em>list first last</em></code></p></div>
5050 <div class="paragraph"><p><code><em>list</em></code> must be a valid Tcl list. This command will return a new
5051 list consisting of elements <code><em>first</em></code> through <code><em>last</em></code>, inclusive.</p></div>
5052 <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>
5053 <div class="paragraph"><p>If <code><em>last</em></code> is greater than or equal to the number of elements
5054 in the list, then it is treated as if it were <code>end</code>.</p></div>
5055 <div class="paragraph"><p>If <code><em>first</em></code> is greater than <code><em>last</em></code> then an empty string
5056 is returned.</p></div>
5057 <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
5058 same result as <code>"<a href="#_lindex"><strong><code>lindex</code></strong></a> <em>list first</em>"</code> (although it often does
5059 for simple fields that aren&#8217;t enclosed in braces); it does, however,
5060 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>
5061 </div>
5062 <div class="sect2">
5063 <h3 id="_lreplace">lreplace</h3>
5064 <div class="paragraph"><p><code><strong>lreplace</strong> <em>list first last ?element element ...?</em></code></p></div>
5065 <div class="paragraph"><p>Returns a new list formed by replacing one or more elements of
5066 <code><em>list</em></code> with the <code><em>element</em></code> arguments.</p></div>
5067 <div class="paragraph"><p><code><em>first</em></code> gives the index in <code><em>list</em></code> of the first element
5068 to be replaced.</p></div>
5069 <div class="paragraph"><p>If <code><em>first</em></code> is less than zero then it refers to the first
5070 element of <code><em>list</em></code>; the element indicated by <code><em>first</em></code>
5071 must exist in the list.</p></div>
5072 <div class="paragraph"><p><code><em>last</em></code> gives the index in <code><em>list</em></code> of the last element
5073 to be replaced; it must be greater than or equal to <code><em>first</em></code>.</p></div>
5074 <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>
5075 <div class="paragraph"><p>The <code><em>element</em></code> arguments specify zero or more new arguments to
5076 be added to the list in place of those that were deleted.</p></div>
5077 <div class="paragraph"><p>Each <code><em>element</em></code> argument will become a separate element of
5078 the list.</p></div>
5079 <div class="paragraph"><p>If no <code><em>element</em></code> arguments are specified, then the elements
5080 between <code><em>first</em></code> and <code><em>last</em></code> are simply deleted.</p></div>
5081 </div>
5082 <div class="sect2">
5083 <h3 id="_lrepeat">lrepeat</h3>
5084 <div class="paragraph"><p><code><strong>lrepeat</strong> <em>number element1 ?element2 ...?</em></code></p></div>
5085 <div class="paragraph"><p>Build a list by repeating elements <code><em>number</em></code> times (which must be
5086 a positive integer).</p></div>
5087 <div class="literalblock">
5088 <div class="content">
5089 <pre><code>jim&gt; lrepeat 3 a b
5090 a b a b a b</code></pre>
5091 </div></div>
5092 </div>
5093 <div class="sect2">
5094 <h3 id="_lreverse">lreverse</h3>
5095 <div class="paragraph"><p><code><strong>lreverse</strong> <em>list</em></code></p></div>
5096 <div class="paragraph"><p>Returns the list in reverse order.</p></div>
5097 <div class="literalblock">
5098 <div class="content">
5099 <pre><code>jim&gt; lreverse {1 2 3}
5100 3 2 1</code></pre>
5101 </div></div>
5102 </div>
5103 <div class="sect2">
5104 <h3 id="_lsearch">lsearch</h3>
5105 <div class="paragraph"><p><code><strong>lsearch</strong> <em>?options? list pattern</em></code></p></div>
5106 <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
5107 command returns the index of the first matching element (unless the options <code>-all</code>, <code>-inline</code> or <code>-bool</code> are
5108 specified.) If not, the command returns -1. The option arguments indicates how the elements of
5109 the list are to be matched against pattern and must have one of the values below:</p></div>
5110 <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>
5111 <div class="dlist"><dl>
5112 <dt class="hdlist1">
5113 <code><strong>-exact</strong></code>
5114 </dt>
5115 <dd>
5117 <code><em>pattern</em></code> is a literal string that is compared for exact equality against each list element.
5118 This is the default.
5119 </p>
5120 </dd>
5121 <dt class="hdlist1">
5122 <code><strong>-glob</strong></code>
5123 </dt>
5124 <dd>
5126 <code><em>pattern</em></code> is a glob-style pattern which is matched against each list element using the same
5127 rules as the string match command.
5128 </p>
5129 </dd>
5130 <dt class="hdlist1">
5131 <code><strong>-regexp</strong></code>
5132 </dt>
5133 <dd>
5135 <code><em>pattern</em></code> is treated as a regular expression and matched against each list element using
5136 the rules described by <a href="#_regexp"><strong><code>regexp</code></strong></a>.
5137 </p>
5138 </dd>
5139 <dt class="hdlist1">
5140 <code><strong>-command</strong> <em>cmdname</em></code>
5141 </dt>
5142 <dd>
5144 <code><em>cmdname</em></code> is a command which is used to match the pattern against each element of the
5145 list. It is invoked as <code><em>cmdname</em> ?<strong>-nocase</strong>? <em>pattern listvalue</em></code> and should return 1
5146 for a match, or 0 for no match.
5147 </p>
5148 </dd>
5149 <dt class="hdlist1">
5150 <code><strong>-all</strong></code>
5151 </dt>
5152 <dd>
5154 Changes the result to be the list of all matching indices (or all matching values if
5155 <code>-inline</code> is specified as well). If indices are returned, the indices will be in numeric
5156 order. If values are returned, the order of the values will be the order of those values
5157 within the input list.
5158 </p>
5159 </dd>
5160 <dt class="hdlist1">
5161 <code><strong>-inline</strong></code>
5162 </dt>
5163 <dd>
5165 The matching value is returned instead of its index (or an empty string if no value
5166 matches). If <code>-all</code> is also specified, then the result of the command is the list of all
5167 values that matched. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5168 </p>
5169 </dd>
5170 <dt class="hdlist1">
5171 <code><strong>-bool</strong></code>
5172 </dt>
5173 <dd>
5175 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <code>-all</code> is also specified,
5176 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
5177 the corresponding element matches. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5178 </p>
5179 </dd>
5180 <dt class="hdlist1">
5181 <code><strong>-not</strong></code>
5182 </dt>
5183 <dd>
5185 This negates the sense of the match, returning the index (or value
5186 if <code>-inline</code> is specified) of the first non-matching value in the
5187 list. If <code>-bool</code> is also specified, the <em>0</em> will be returned if a
5188 match is found, or <em>1</em> otherwise. If <code>-all</code> is also specified,
5189 non-matches will be returned rather than matches.
5190 </p>
5191 </dd>
5192 <dt class="hdlist1">
5193 <code><strong>-nocase</strong></code>
5194 </dt>
5195 <dd>
5197 Causes comparisons to be handled in a case-insensitive manner.
5198 </p>
5199 </dd>
5200 </dl></div>
5201 </div>
5202 <div class="sect2">
5203 <h3 id="_lsort">lsort</h3>
5204 <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>
5205 <div class="paragraph"><p>Sort the elements of <code><em>list</em></code>, returning a new list in sorted order.
5206 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.</p></div>
5207 <div class="paragraph"><p>If <code>-nocase</code> is specified, comparisons are case-insenstive.</p></div>
5208 <div class="paragraph"><p>If <code>-integer</code> is specified, numeric sorting is used.</p></div>
5209 <div class="paragraph"><p>If <code>-real</code> is specified, floating point number sorting is used.</p></div>
5210 <div class="paragraph"><p>If <code>-command <em>cmdname</em></code> is specified, <code><em>cmdname</em></code> is treated as a command
5211 name. For each comparison, <code><em>cmdname $value1 $value2</code></em> is called which
5212 should compare the values and return an integer less than, equal
5213 to, or greater than zero if the <code><em>$value1</em></code> is to be considered less
5214 than, equal to, or greater than <code><em>$value2</em></code>, respectively.</p></div>
5215 <div class="paragraph"><p>If <code>-decreasing</code> is specified, the resulting list is in the opposite
5216 order to what it would be otherwise. <code>-increasing</code> is the default.</p></div>
5217 <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.
5218 Note that duplicates are determined relative to the comparison used in the sort. Thus if <code>-index 0</code> is used,
5219 <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>
5220 <div class="paragraph"><p>If <code>-index <em>listindex</em></code> is specified, each element of the list is treated as a list and
5221 the given index is extracted from the list for comparison. The list index may
5222 be any valid list index, such as <code>1</code>, <code>end</code> or <code>end-2</code>.</p></div>
5223 </div>
5224 <div class="sect2">
5225 <h3 id="_open">open</h3>
5226 <div class="paragraph"><p><code><strong>open</strong> <em>fileName ?access?</em></code></p></div>
5227 <div class="paragraph"><p><code><strong>open</strong> <em>|command-pipeline ?access?</em></code></p></div>
5228 <div class="paragraph"><p>Opens a file and returns an identifier
5229 that may be used in future invocations
5230 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>.
5231 <code><em>fileName</em></code> gives the name of the file to open.</p></div>
5232 <div class="paragraph"><p>The <code><em>access</em></code> argument indicates the way in which the file is to be accessed.
5233 It may have any of the following values:</p></div>
5234 <div class="dlist"><dl>
5235 <dt class="hdlist1">
5236 <code>r</code>
5237 </dt>
5238 <dd>
5240 Open the file for reading only; the file must already exist.
5241 </p>
5242 </dd>
5243 <dt class="hdlist1">
5244 <code>r</code>+
5245 </dt>
5246 <dd>
5248 Open the file for both reading and writing; the file must
5249 already exist.
5250 </p>
5251 </dd>
5252 <dt class="hdlist1">
5253 <code>w</code>
5254 </dt>
5255 <dd>
5257 Open the file for writing only. Truncate it if it exists. If it doesn&#8217;t
5258 exist, create a new file.
5259 </p>
5260 </dd>
5261 <dt class="hdlist1">
5262 <code>w</code>+
5263 </dt>
5264 <dd>
5266 Open the file for reading and writing. Truncate it if it exists.
5267 If it doesn&#8217;t exist, create a new file.
5268 </p>
5269 </dd>
5270 <dt class="hdlist1">
5271 <code>a</code>
5272 </dt>
5273 <dd>
5275 Open the file for writing only. The file must already exist, and the file
5276 is positioned so that new data is appended to the file.
5277 </p>
5278 </dd>
5279 <dt class="hdlist1">
5280 <code>a</code>+
5281 </dt>
5282 <dd>
5284 Open the file for reading and writing. If the file doesn&#8217;t
5285 exist, create a new empty file. Set the initial access position
5286 to the end of the file.
5287 </p>
5288 </dd>
5289 </dl></div>
5290 <div class="paragraph"><p><code><em>access</em></code> defaults to <em>r</em>.</p></div>
5291 <div class="paragraph"><p>If a file is opened for both reading and writing, then <a href="#_seek"><strong><code>seek</code></strong></a>
5292 must be invoked between a read and a write, or vice versa.</p></div>
5293 <div class="paragraph"><p>If the first character of <code><em>fileName</em></code> is "|" then the remaining
5294 characters of <code><em>fileName</em></code> are treated as a list of arguments that
5295 describe a command pipeline to invoke, in the same style as the
5296 arguments for exec. In this case, the channel identifier returned
5297 by open may be used to write to the command&#8217;s input pipe or read
5298 from its output pipe, depending on the value of <code><em>access</em></code>. If write-only
5299 access is used (e.g. <code><em>access</em></code> is <em>w</em>), then standard output for the
5300 pipeline is directed to the current standard output unless overridden
5301 by the command. If read-only access is used (e.g. <code><em>access</em></code> is r),
5302 standard input for the pipeline is taken from the current standard
5303 input unless overridden by the command.</p></div>
5304 <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
5305 forming the command pipeline.</p></div>
5306 <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>
5307 </div>
5308 <div class="sect2">
5309 <h3 id="_package">package</h3>
5310 <div class="paragraph"><p><code><strong>package provide</strong> <em>name ?version?</em></code></p></div>
5311 <div class="paragraph"><p>Indicates that the current script provides the package named <code><em>name</em></code>.
5312 If no version is specified, <em>1.0</em> is used.</p></div>
5313 <div class="paragraph"><p>Any script which provides a package may include this statement
5314 as the first statement, although it is not required.</p></div>
5315 <div class="paragraph"><p><code><strong>package require</strong> <em>name ?version?</em>*</code></p></div>
5316 <div class="paragraph"><p>Searches for the package with the given <code><em>name</em></code> by examining each path
5317 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
5318 or <em>$path/$name.tcl</em> as a script package.</p></div>
5319 <div class="paragraph"><p>The first such file which is found is considered to provide the the package.
5320 (The version number is ignored).</p></div>
5321 <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,
5322 otherwise if <em>$name.tcl</em> exists it is loaded with the <a href="#_source"><strong><code>source</code></strong></a> command.</p></div>
5323 <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.
5324 No further attempt will be made to locate the file.</p></div>
5325 </div>
5326 <div class="sect2">
5327 <h3 id="_pid">pid</h3>
5328 <div class="paragraph"><p><code><strong>pid</strong></code></p></div>
5329 <div class="paragraph"><p><code><strong>pid</strong> <em>fileId</em></code></p></div>
5330 <div class="paragraph"><p>The first form returns the process identifier of the current process.</p></div>
5331 <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
5332 of the process ids forming the pipeline in the same form as <a href="#_exec"><strong><code>exec</code></strong></a> <code>... &amp;</code>.
5333 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
5334 the empty string is returned instead.</p></div>
5335 <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>
5336 </div>
5337 <div class="sect2">
5338 <h3 id="_proc">proc</h3>
5339 <div class="paragraph"><p><code><strong>proc</strong> <em>name args ?statics? body</em></code></p></div>
5340 <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>.
5341 When the new command is invoked, the contents of <code><em>body</em></code> will be executed.
5342 Tcl interpreter. <code><em>args</em></code> specifies the formal arguments to the procedure.
5343 If specified, <code><em>static</em></code>, declares static variables which are bound to the
5344 procedure.</p></div>
5345 <div class="paragraph"><p>See PROCEDURES for detailed information about Tcl procedures.</p></div>
5346 <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>
5347 <div class="paragraph"><p>When a procedure is invoked, the procedure&#8217;s return value is the
5348 value specified in a <a href="#_return"><strong><code>return</code></strong></a> command. If the procedure doesn&#8217;t
5349 execute an explicit <a href="#_return"><strong><code>return</code></strong></a>, then its return value is the value
5350 of the last command executed in the procedure&#8217;s body.</p></div>
5351 <div class="paragraph"><p>If an error occurs while executing the procedure body, then the
5352 procedure-as-a-whole will return that same error.</p></div>
5353 </div>
5354 <div class="sect2">
5355 <h3 id="_puts">puts</h3>
5356 <div class="paragraph"><p><code><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></code></p></div>
5357 <div class="paragraph"><p><code><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></code></p></div>
5358 <div class="paragraph"><p>Writes the characters given by <code><em>string</em></code> to the file given
5359 by <code><em>fileId</em></code>. <code><em>fileId</em></code> must have been the return
5360 value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
5361 <code>stdout</code> or <code>stderr</code> to refer to one of the standard I/O
5362 channels; it must refer to a file that was opened for
5363 writing.</p></div>
5364 <div class="paragraph"><p>In the first form, if no <code><em>fileId</em></code> is specified then it defaults to <code>stdout</code>.
5365 <a href="#_puts"><strong><code>puts</code></strong></a> normally outputs a newline character after <code><em>string</em></code>,
5366 but this feature may be suppressed by specifying the <code>-nonewline</code>
5367 switch.</p></div>
5368 <div class="paragraph"><p>Output to files is buffered internally by Tcl; the <a href="#_flush"><strong><code>flush</code></strong></a>
5369 command may be used to force buffered characters to be output.</p></div>
5370 </div>
5371 <div class="sect2">
5372 <h3 id="_pwd">pwd</h3>
5373 <div class="paragraph"><p><code><strong>pwd</strong></code></p></div>
5374 <div class="paragraph"><p>Returns the path name of the current working directory.</p></div>
5375 </div>
5376 <div class="sect2">
5377 <h3 id="_rand">rand</h3>
5378 <div class="paragraph"><p><code><strong>rand</strong> <em>?min? ?max?</em></code></p></div>
5379 <div class="paragraph"><p>Returns a random integer between <code><em>min</em></code> (defaults to 0) and <code><em>max</em></code>
5380 (defaults to the maximum integer).</p></div>
5381 <div class="paragraph"><p>If only one argument is given, it is interpreted as <code><em>max</em></code>.</p></div>
5382 </div>
5383 <div class="sect2">
5384 <h3 id="_range">range</h3>
5385 <div class="paragraph"><p><code><strong>range</strong> <em>?start? end ?step?</em></code></p></div>
5386 <div class="paragraph"><p>Returns a list of integers starting at <code><em>start</em></code> (defaults to 0)
5387 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>
5388 <div class="literalblock">
5389 <div class="content">
5390 <pre><code>jim&gt; range 5
5391 0 1 2 3 4
5392 jim&gt; range 2 5
5393 2 3 4
5394 jim&gt; range 2 10 4
5396 jim&gt; range 7 4 -2
5397 7 5</code></pre>
5398 </div></div>
5399 </div>
5400 <div class="sect2">
5401 <h3 id="_read">read</h3>
5402 <div class="paragraph"><p><code><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></code></p></div>
5403 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</code></p></div>
5404 <div class="paragraph"><p><code><strong>read</strong> <em>fileId numBytes</em></code></p></div>
5405 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> <em>numBytes</em></code></p></div>
5406 <div class="paragraph"><p>In the first form, all of the remaining bytes are read from the file
5407 given by <code><em>fileId</em></code>; they are returned as the result of the command.
5408 If the <code>-nonewline</code> switch is specified then the last
5409 character of the file is discarded if it is a newline.</p></div>
5410 <div class="paragraph"><p>In the second form, the extra argument specifies how many bytes to read;
5411 exactly this many bytes will be read and returned, unless there are fewer than
5412 <code><em>numBytes</em></code> bytes left in the file; in this case, all the remaining
5413 bytes are returned.</p></div>
5414 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous call
5415 to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened for reading.</p></div>
5416 </div>
5417 <div class="sect2">
5418 <h3 id="_regexp">regexp</h3>
5419 <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>
5420 <div class="paragraph"><p>Determines whether the regular expression <code><em>exp</em></code> matches part or
5421 all of <code><em>string</em></code> and returns 1 if it does, 0 if it doesn&#8217;t.</p></div>
5422 <div class="paragraph"><p>See REGULAR EXPRESSIONS above for complete information on the
5423 syntax of <code><em>exp</em></code> and how it is matched against <code><em>string</em></code>.</p></div>
5424 <div class="paragraph"><p>If additional arguments are specified after <code><em>string</em></code> then they
5425 are treated as the names of variables to use to return
5426 information about which part(s) of <code><em>string</em></code> matched <code><em>exp</em></code>.
5427 <code><em>matchVar</em></code> will be set to the range of <code><em>string</em></code> that
5428 matched all of <code><em>exp</em></code>. The first <code><em>subMatchVar</em></code> will contain
5429 the characters in <code><em>string</em></code> that matched the leftmost parenthesized
5430 subexpression within <code><em>exp</em></code>, the next <code><em>subMatchVar</em></code> will
5431 contain the characters that matched the next parenthesized
5432 subexpression to the right in <code><em>exp</em></code>, and so on.</p></div>
5433 <div class="paragraph"><p>Normally, <code><em>matchVar</em></code> and the each <code><em>subMatchVar</em></code> are set to hold the
5434 matching characters from <a href="#_string"><strong><code>string</code></strong></a>, however see <code>-indices</code> and
5435 <code>-inline</code> below.</p></div>
5436 <div class="paragraph"><p>If there are more values for <code><em>subMatchVar</em></code> than parenthesized subexpressions
5437 within <code><em>exp</em></code>, or if a particular subexpression in <code><em>exp</em></code> doesn&#8217;t
5438 match the string (e.g. because it was in a portion of the expression
5439 that wasn&#8217;t matched), then the corresponding <code><em>subMatchVar</em></code> will be
5440 set to <code>"-1 -1"</code> if <code>-indices</code> has been specified or to an empty
5441 string otherwise.</p></div>
5442 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regexp</em></code></p></div>
5443 <div class="dlist"><dl>
5444 <dt class="hdlist1">
5445 <code><strong>-nocase</strong></code>
5446 </dt>
5447 <dd>
5449 Causes upper-case and lower-case characters to be treated as
5450 identical during the matching process.
5451 </p>
5452 </dd>
5453 <dt class="hdlist1">
5454 <code><strong>-line</strong></code>
5455 </dt>
5456 <dd>
5458 Use newline-sensitive matching. By default, newline
5459 is a completely ordinary character with no special meaning in
5460 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5461 and <code>.</code> never match newline, a <code></sup></code> anchor matches the null
5462 string after any newline in the string in addition to its normal
5463 function, and the <code>$</code> anchor matches the null string before any
5464 newline in the string in addition to its normal function.
5465 </p>
5466 </dd>
5467 <dt class="hdlist1">
5468 <code><strong>-indices</strong></code>
5469 </dt>
5470 <dd>
5472 Changes what is stored in the subMatchVars. Instead of
5473 storing the matching characters from string, each variable
5474 will contain a list of two decimal strings giving the indices
5475 in string of the first and last characters in the matching
5476 range of characters.
5477 </p>
5478 </dd>
5479 <dt class="hdlist1">
5480 <code><strong>-start</strong> <em>offset</em></code>
5481 </dt>
5482 <dd>
5484 Specifies a character index offset into the string at which to start
5485 matching the regular expression. If <code>-indices</code> is
5486 specified, the indices will be indexed starting from the
5487 absolute beginning of the input string. <code><em>offset</em></code> will be
5488 constrained to the bounds of the input string.
5489 </p>
5490 </dd>
5491 <dt class="hdlist1">
5492 <code><strong>-all</strong></code>
5493 </dt>
5494 <dd>
5496 Causes the regular expression to be matched as many times as possible
5497 in the string, returning the total number of matches found. If this
5498 is specified with match variables, they will contain information
5499 for the last match only.
5500 </p>
5501 </dd>
5502 <dt class="hdlist1">
5503 <code><strong>-inline</strong></code>
5504 </dt>
5505 <dd>
5507 Causes the command to return, as a list, the data that would otherwise
5508 be placed in match variables. When using <code>-inline</code>, match variables
5509 may not be specified. If used with <code>-all</code>, the list will be concatenated
5510 at each iteration, such that a flat list is always returned. For
5511 each match iteration, the command will append the overall match
5512 data, plus one element for each subexpression in the regular
5513 expression.
5514 </p>
5515 </dd>
5516 <dt class="hdlist1">
5517 <code><strong>--</strong></code>
5518 </dt>
5519 <dd>
5521 Marks the end of switches. The argument following this one will be
5522 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5523 </p>
5524 </dd>
5525 </dl></div>
5526 </div>
5527 <div class="sect2">
5528 <h3 id="_regsub">regsub</h3>
5529 <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>
5530 <div class="paragraph"><p>This command matches the regular expression <code><em>exp</em></code> against
5531 <code><em>string</em></code> using the rules described in REGULAR EXPRESSIONS
5532 above.</p></div>
5533 <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>
5534 with the substitutions detailed below, and returns the number of
5535 substitutions made (normally 1 unless <code>-all</code> is specified).
5536 This is 0 if there were no matches.</p></div>
5537 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified, the substituted string will be returned
5538 instead.</p></div>
5539 <div class="paragraph"><p>When copying <code><em>string</em></code>, the portion of <code><em>string</em></code> that
5540 matched <code><em>exp</em></code> is replaced with <code><em>subSpec</em></code>.
5541 If <code><em>subSpec</em></code> contains a <code>&amp;</code> or <code>\0</code>, then it is replaced
5542 in the substitution with the portion of <code><em>string</em></code> that
5543 matched <code><em>exp</em></code>.</p></div>
5544 <div class="paragraph"><p>If <code><em>subSpec</em></code> contains a <code>\n</code>, where <code><em>n</em></code> is a digit
5545 between 1 and 9, then it is replaced in the substitution with
5546 the portion of <code><em>string</em></code> that matched the <code><em>n</em></code>'-th
5547 parenthesized subexpression of <code><em>exp</em></code>.
5548 Additional backslashes may be used in <code><em>subSpec</em></code> to prevent special
5549 interpretation of <code>&amp;</code> or <code>\0</code> or <code>\n</code> or
5550 backslash.</p></div>
5551 <div class="paragraph"><p>The use of backslashes in <code><em>subSpec</em></code> tends to interact badly
5552 with the Tcl parser&#8217;s use of backslashes, so it&#8217;s generally
5553 safest to enclose <code><em>subSpec</em></code> in braces if it includes
5554 backslashes.</p></div>
5555 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regsub</em></code></p></div>
5556 <div class="dlist"><dl>
5557 <dt class="hdlist1">
5558 <code><strong>-nocase</strong></code>
5559 </dt>
5560 <dd>
5562 Upper-case characters in <code><em>string</em></code> are converted to lower-case
5563 before matching against <code><em>exp</em></code>; however, substitutions
5564 specified by <code><em>subSpec</em></code> use the original unconverted form
5565 of <code><em>string</em></code>.
5566 </p>
5567 </dd>
5568 <dt class="hdlist1">
5569 <code><strong>-all</strong></code>
5570 </dt>
5571 <dd>
5573 All ranges in <code><em>string</em></code> that match <code><em>exp</em></code> are found and substitution
5574 is performed for each of these ranges, rather than only the
5575 first. The <code>&amp;</code> and <code>\n</code> sequences are handled for
5576 each substitution using the information from the corresponding
5577 match.
5578 </p>
5579 </dd>
5580 <dt class="hdlist1">
5581 <code><strong>-line</strong></code>
5582 </dt>
5583 <dd>
5585 Use newline-sensitive matching. By default, newline
5586 is a completely ordinary character with no special meaning in
5587 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5588 and <code>.</code> never match newline, a <code></sup></code> anchor matches the null
5589 string after any newline in the string in addition to its normal
5590 function, and the <code>$</code> anchor matches the null string before any
5591 newline in the string in addition to its normal function.
5592 </p>
5593 </dd>
5594 <dt class="hdlist1">
5595 <code><strong>-start</strong> <em>offset</em></code>
5596 </dt>
5597 <dd>
5599 Specifies a character index offset into the string at which to
5600 start matching the regular expression. <code><em>offset</em></code> will be
5601 constrained to the bounds of the input string.
5602 </p>
5603 </dd>
5604 <dt class="hdlist1">
5605 <code><strong>--</strong></code>
5606 </dt>
5607 <dd>
5609 Marks the end of switches. The argument following this one will be
5610 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5611 </p>
5612 </dd>
5613 </dl></div>
5614 </div>
5615 <div class="sect2">
5616 <h3 id="_ref">ref</h3>
5617 <div class="paragraph"><p><code><strong>ref</strong> <em>string tag ?finalizer?</em></code></p></div>
5618 <div class="paragraph"><p>Create a new reference containing <code><em>string</em></code> of type <code><em>tag</em></code>.
5619 If <code><em>finalizer</em></code> is specified, it is a command which will be invoked
5620 when the a garbage collection cycle runs and this reference is
5621 no longer accessible.</p></div>
5622 <div class="paragraph"><p>The finalizer is invoked as:</p></div>
5623 <div class="literalblock">
5624 <div class="content">
5625 <pre><code>finalizer reference string</code></pre>
5626 </div></div>
5627 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5628 </div>
5629 <div class="sect2">
5630 <h3 id="_rename">rename</h3>
5631 <div class="paragraph"><p><code><strong>rename</strong> <em>oldName newName</em></code></p></div>
5632 <div class="paragraph"><p>Rename the command that used to be called <code><em>oldName</em></code> so that it
5633 is now called <code><em>newName</em></code>. If <code><em>newName</em></code> is an empty string
5634 (e.g. {}) then <code><em>oldName</em></code> is deleted. The <a href="#_rename"><strong><code>rename</code></strong></a> command
5635 returns an empty string as result.</p></div>
5636 </div>
5637 <div class="sect2">
5638 <h3 id="_return">return</h3>
5639 <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>
5640 <div class="paragraph"><p>Return immediately from the current procedure (or top-level command
5641 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>
5642 is not specified, an empty string will be returned as result.</p></div>
5643 <div class="paragraph"><p>If <code>-code</code> is specified (as either a number or ok, error, break,
5644 continue, signal, return or exit), this code will be used instead
5645 of <code>JIM_OK</code>. This is generally useful when implementing flow of control
5646 commands.</p></div>
5647 <div class="paragraph"><p>If <code>-level</code> is specified and greater than 1, it has the effect of delaying
5648 the new return code from <code>-code</code>. This is useful when rethrowing an error
5649 from <a href="#_catch"><strong><code>catch</code></strong></a>. See the implementation of try/catch in tclcompat.tcl for
5650 an example of how this is done.</p></div>
5651 <div class="paragraph"><p>Note: The following options are only used when <code>-code</code> is JIM_ERR.</p></div>
5652 <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>)
5653 it is used to initialize the stacktrace.</p></div>
5654 <div class="paragraph"><p>If <code>-errorcode</code> is specified, it is used to set the global variable $::errorCode.</p></div>
5655 </div>
5656 <div class="sect2">
5657 <h3 id="_scan">scan</h3>
5658 <div class="paragraph"><p><code><strong>scan</strong> <em>string format varName1 ?varName2 ...?</em></code></p></div>
5659 <div class="paragraph"><p>This command parses fields from an input string in the same fashion
5660 as the C <em>sscanf</em> procedure. <code><em>string</em></code> gives the input to be parsed
5661 and <code><em>format</em></code> indicates how to parse it, using <em>%</em> fields as in
5662 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5663 man page for details. Each <code><em>varName</em></code> gives the name of a variable;
5664 when a field is scanned from <code><em>string</em></code>, the result is converted back
5665 into a string and assigned to the corresponding <code><em>varName</em></code>. The
5666 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5667 character value is converted to a decimal string, which is then
5668 assigned to the corresponding <code><em>varName</em></code>; no field width may be
5669 specified for this conversion.</p></div>
5670 </div>
5671 <div class="sect2">
5672 <h3 id="_seek">seek</h3>
5673 <div class="paragraph"><p><code><strong>seek</strong> <em>fileId offset ?origin?</em></code></p></div>
5674 <div class="paragraph"><p><code><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></code></p></div>
5675 <div class="paragraph"><p>Change the current access position for <code><em>fileId</em></code>.
5676 The <code><em>offset</em></code> and <code><em>origin</em></code> arguments specify the position at
5677 which the next read or write will occur for <code><em>fileId</em></code>.
5678 <code><em>offset</em></code> must be a number (which may be negative) and <code><em>origin</em></code>
5679 must be one of the following:</p></div>
5680 <div class="dlist"><dl>
5681 <dt class="hdlist1">
5682 <code><strong>start</strong></code>
5683 </dt>
5684 <dd>
5686 The new access position will be <code><em>offset</em></code> bytes from the start
5687 of the file.
5688 </p>
5689 </dd>
5690 <dt class="hdlist1">
5691 <code><strong>current</strong></code>
5692 </dt>
5693 <dd>
5695 The new access position will be <code><em>offset</em></code> bytes from the current
5696 access position; a negative <code><em>offset</em></code> moves the access position
5697 backwards in the file.
5698 </p>
5699 </dd>
5700 <dt class="hdlist1">
5701 <code><strong>end</strong></code>
5702 </dt>
5703 <dd>
5705 The new access position will be <code><em>offset</em></code> bytes from the end of
5706 the file. A negative <code><em>offset</em></code> places the access position before
5707 the end-of-file, and a positive <code><em>offset</em></code> places the access position
5708 after the end-of-file.
5709 </p>
5710 </dd>
5711 </dl></div>
5712 <div class="paragraph"><p>The <code><em>origin</em></code> argument defaults to <code>start</code>.</p></div>
5713 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
5714 <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
5715 of the standard I/O channels.</p></div>
5716 <div class="paragraph"><p>This command returns an empty string.</p></div>
5717 </div>
5718 <div class="sect2">
5719 <h3 id="_set">set</h3>
5720 <div class="paragraph"><p><code><strong>set</strong> <em>varName ?value?</em></code></p></div>
5721 <div class="paragraph"><p>Returns the value of variable <code><em>varName</em></code>.</p></div>
5722 <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>,
5723 creating a new variable if one doesn&#8217;t already exist, and return
5724 its value.</p></div>
5725 <div class="paragraph"><p>If <code><em>varName</em></code> contains an open parenthesis and ends with a
5726 close parenthesis, then it refers to an array element: the characters
5727 before the open parenthesis are the name of the array, and the characters
5728 between the parentheses are the index within the array.
5729 Otherwise <code><em>varName</em></code> refers to a scalar variable.</p></div>
5730 <div class="paragraph"><p>If no procedure is active, then <code><em>varName</em></code> refers to a global
5731 variable.</p></div>
5732 <div class="paragraph"><p>If a procedure is active, then <code><em>varName</em></code> refers to a parameter
5733 or local variable of the procedure, unless the <code><em>global</em></code> command
5734 has been invoked to declare <code><em>varName</em></code> to be global.</p></div>
5735 <div class="paragraph"><p>The <code>::</code> prefix may also be used to explicitly reference a variable
5736 in the global scope.</p></div>
5737 </div>
5738 <div class="sect2">
5739 <h3 id="_setref">setref</h3>
5740 <div class="paragraph"><p><code><strong>setref</strong> <em>reference string</em></code></p></div>
5741 <div class="paragraph"><p>Store a new string in <code><em>reference</em></code>, replacing the existing string.
5742 The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
5743 command.</p></div>
5744 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5745 </div>
5746 <div class="sect2">
5747 <h3 id="_signal">signal</h3>
5748 <div class="paragraph"><p>Command for signal handling.</p></div>
5749 <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>
5750 <div class="paragraph"><p>Commands which return a list of signal names do so using the canonical form:
5751 "<code>SIGINT SIGTERM</code>".</p></div>
5752 <div class="dlist"><dl>
5753 <dt class="hdlist1">
5754 <code><strong>signal handle</strong> ?<em>signals ...</em>?</code>
5755 </dt>
5756 <dd>
5758 If no signals are given, returns a list of all signals which are currently
5759 being handled.
5760 If signals are specified, these are added to the list of signals currently
5761 being handled.
5762 </p>
5763 </dd>
5764 <dt class="hdlist1">
5765 <code><strong>signal ignore</strong> ?<em>signals ...</em>?</code>
5766 </dt>
5767 <dd>
5769 If no signals are given, returns a lists all signals which are currently
5770 being ignored.
5771 If signals are specified, these are added to the list of signals
5772 currently being ignored. These signals are still delivered, but
5773 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
5774 <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to determine which signals have occurred but
5775 been ignored.
5776 </p>
5777 </dd>
5778 <dt class="hdlist1">
5779 <code><strong>signal default</strong> ?<em>signals ...</em>?</code>
5780 </dt>
5781 <dd>
5783 If no signals are given, returns a lists all signals which are currently have
5784 the default behaviour.
5785 If signals are specified, these are added to the list of signals which have
5786 the default behaviour.
5787 </p>
5788 </dd>
5789 <dt class="hdlist1">
5790 <code><strong>signal check ?-clear?</strong> ?<em>signals ...</em>?</code>
5791 </dt>
5792 <dd>
5794 Returns a list of signals which have been delivered to the process
5795 but are <em>ignored</em>. If signals are specified, only that set of signals will
5796 be checked, otherwise all signals will be checked.
5797 If <code>-clear</code> is specified, any signals returned are removed and will not be
5798 returned by subsequent calls to <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> unless delivered again.
5799 </p>
5800 </dd>
5801 <dt class="hdlist1">
5802 <code><strong>signal throw</strong> ?<em>signal</em>?</code>
5803 </dt>
5804 <dd>
5806 Raises the given signal, which defaults to <code>SIGINT</code> if not specified.
5807 The behaviour is identical to:
5808 </p>
5809 <div class="literalblock">
5810 <div class="content">
5811 <pre><code>kill signal [pid]</code></pre>
5812 </div></div>
5813 </dd>
5814 </dl></div>
5815 <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
5816 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>
5817 to immediately abort execution when the signal is delivered. Alternatively, <a href="#_signal"><strong><code>signal</code></strong></a> <code>ignore</code>
5818 is used in conjunction with <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to handle signal synchronously. Consider the
5819 two examples below.</p></div>
5820 <div class="paragraph"><p>Prevent a processing from taking too long</p></div>
5821 <div class="literalblock">
5822 <div class="content">
5823 <pre><code>signal handle SIGALRM
5824 alarm 20
5825 try -signal {
5826 .. possibly long running process ..
5827 alarm 0
5828 } on signal {sig} {
5829 puts stderr "Process took too long"
5830 }</code></pre>
5831 </div></div>
5832 <div class="paragraph"><p>Handle SIGHUP to reconfigure:</p></div>
5833 <div class="literalblock">
5834 <div class="content">
5835 <pre><code>signal ignore SIGHUP
5836 while {1} {
5837 ... handle configuration/reconfiguration ...
5838 while {[signal check -clear SIGHUP] eq ""} {
5839 ... do processing ..
5841 # Received SIGHUP, so reconfigure
5842 }</code></pre>
5843 </div></div>
5844 </div>
5845 <div class="sect2">
5846 <h3 id="_sleep">sleep</h3>
5847 <div class="paragraph"><p><code><strong>sleep</strong> <em>seconds</em></code></p></div>
5848 <div class="paragraph"><p>Pauses for the given number of seconds, which may be a floating
5849 point value less than one to sleep for less than a second, or an
5850 integer to sleep for one or more seconds.</p></div>
5851 </div>
5852 <div class="sect2">
5853 <h3 id="_source">source</h3>
5854 <div class="paragraph"><p><code><strong>source</strong> <em>fileName</em></code></p></div>
5855 <div class="paragraph"><p>Read file <code><em>fileName</em></code> and pass the contents to the Tcl interpreter
5856 as a sequence of commands to execute in the normal fashion. The return
5857 value of <a href="#_source"><strong><code>source</code></strong></a> is the return value of the last command executed
5858 from the file. If an error occurs in executing the contents of the
5859 file, then the <a href="#_source"><strong><code>source</code></strong></a> command will return that error.</p></div>
5860 <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
5861 the file will be skipped and the <a href="#_source"><strong><code>source</code></strong></a> command will return
5862 normally with the result from the <a href="#_return"><strong><code>return</code></strong></a> command.</p></div>
5863 </div>
5864 <div class="sect2">
5865 <h3 id="_split">split</h3>
5866 <div class="paragraph"><p><code><strong>split</strong> <em>string ?splitChars?</em></code></p></div>
5867 <div class="paragraph"><p>Returns a list created by splitting <code><em>string</em></code> at each character
5868 that is in the <code><em>splitChars</em></code> argument.</p></div>
5869 <div class="paragraph"><p>Each element of the result list will consist of the
5870 characters from <code><em>string</em></code> between instances of the
5871 characters in <code><em>splitChars</em></code>.</p></div>
5872 <div class="paragraph"><p>Empty list elements will be generated if <code><em>string</em></code> contains
5873 adjacent characters in <code><em>splitChars</em></code>, or if the first or last
5874 character of <code><em>string</em></code> is in <code><em>splitChars</em></code>.</p></div>
5875 <div class="paragraph"><p>If <code><em>splitChars</em></code> is an empty string then each character of
5876 <code><em>string</em></code> becomes a separate element of the result list.</p></div>
5877 <div class="paragraph"><p><code><em>splitChars</em></code> defaults to the standard white-space characters.
5878 For example,</p></div>
5879 <div class="literalblock">
5880 <div class="content">
5881 <pre><code>split "comp.unix.misc" .</code></pre>
5882 </div></div>
5883 <div class="paragraph"><p>returns <code><em>"comp unix misc"</em></code> and</p></div>
5884 <div class="literalblock">
5885 <div class="content">
5886 <pre><code>split "Hello world" {}</code></pre>
5887 </div></div>
5888 <div class="paragraph"><p>returns <code><em>"H e l l o { } w o r l d"</em></code>.</p></div>
5889 </div>
5890 <div class="sect2">
5891 <h3 id="_stackdump">stackdump</h3>
5892 <div class="paragraph"><p><code><strong>stackdump</strong> <em>stacktrace</em></code></p></div>
5893 <div class="paragraph"><p>Creates a human readable representation of a stack trace.</p></div>
5894 </div>
5895 <div class="sect2">
5896 <h3 id="_stacktrace">stacktrace</h3>
5897 <div class="paragraph"><p><code><strong>stacktrace</strong></code></p></div>
5898 <div class="paragraph"><p>Returns a live stack trace as a list of <code>proc file line proc file line ...</code>.
5899 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
5900 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>
5901 <div class="paragraph"><p>See also <a href="#_stackdump"><strong><code>stackdump</code></strong></a>.</p></div>
5902 </div>
5903 <div class="sect2">
5904 <h3 id="_string">string</h3>
5905 <div class="paragraph"><p><code><strong>string</strong> <em>option arg ?arg ...?</em></code></p></div>
5906 <div class="paragraph"><p>Perform one of several string operations, depending on <code><em>option</em></code>.
5907 The legal options (which may be abbreviated) are:</p></div>
5908 <div class="dlist"><dl>
5909 <dt class="hdlist1">
5910 <code><strong>string bytelength</strong> <em>string</em></code>
5911 </dt>
5912 <dd>
5914 Returns the length of the string in bytes. This will return
5915 the same value as <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> if UTF-8 support is not enabled,
5916 or if the string is composed entirely of ASCII characters.
5917 See UTF-8 AND UNICODE.
5918 </p>
5919 </dd>
5920 <dt class="hdlist1">
5921 <code><strong>string byterange</strong> <em>string first last</em></code>
5922 </dt>
5923 <dd>
5925 Like <a href="#_string"><strong><code>string</code></strong></a> <code>range</code> except works on bytes rather than characters.
5926 These commands are identical if UTF-8 support is not enabled.
5927 </p>
5928 </dd>
5929 <dt class="hdlist1">
5930 <code><strong>string cat</strong> <em>?string1 string2 ...?</em></code>
5931 </dt>
5932 <dd>
5934 Concatenates the given strings into a single string.
5935 </p>
5936 </dd>
5937 <dt class="hdlist1">
5938 <code><strong>string compare ?-nocase?</strong> ?<strong>-length</strong> <em>len? string1 string2</em></code>
5939 </dt>
5940 <dd>
5942 Perform a character-by-character comparison of strings <code><em>string1</em></code> and
5943 <code><em>string2</em></code> in the same way as the C <em>strcmp</em> procedure. Return
5944 -1, 0, or 1, depending on whether <code><em>string1</em></code> is lexicographically
5945 less than, equal to, or greater than <code><em>string2</em></code>. If <code>-length</code>
5946 is specified, then only the first <code><em>len</em></code> characters are used
5947 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5948 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5949 </p>
5950 </dd>
5951 <dt class="hdlist1">
5952 <code><strong>string equal ?-nocase?</strong> <em>?<strong>-length</strong> len?</em> <em>string1 string2</em></code>
5953 </dt>
5954 <dd>
5956 Returns 1 if the strings are equal, or 0 otherwise. If <code>-length</code>
5957 is specified, then only the first <code><em>len</em></code> characters are used
5958 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5959 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5960 </p>
5961 </dd>
5962 <dt class="hdlist1">
5963 <code><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></code>
5964 </dt>
5965 <dd>
5967 Search <code><em>string2</em></code> for a sequence of characters that exactly match
5968 the characters in <code><em>string1</em></code>. If found, return the index of the
5969 first character in the first such match within <code><em>string2</em></code>. If not
5970 found, return -1. If <code><em>firstIndex</em></code> is specified, matching will start
5971 from <code><em>firstIndex</em></code> of <code><em>string1</em></code>.
5972 </p>
5973 </dd>
5974 <dt class="hdlist1">
5976 </dt>
5977 <dd>
5979 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>firstIndex</em></code>.
5980 </p>
5981 </dd>
5982 <dt class="hdlist1">
5983 <code><strong>string index</strong> <em>string charIndex</em></code>
5984 </dt>
5985 <dd>
5987 Returns the <code><em>charIndex</em></code><em>th character of the <code>'string</em></code>
5988 argument. A <code><em>charIndex</em></code> of 0 corresponds to the first
5989 character of the string.
5990 If <code><em>charIndex</em></code> is less than 0 or greater than
5991 or equal to the length of the string then an empty string is
5992 returned.
5993 </p>
5994 </dd>
5995 <dt class="hdlist1">
5997 </dt>
5998 <dd>
6000 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>charIndex</em></code>.
6001 </p>
6002 </dd>
6003 <dt class="hdlist1">
6004 <code><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></code>
6005 </dt>
6006 <dd>
6008 Returns 1 if <code><em>string</em></code> is a valid member of the specified character
6009 class, otherwise returns 0. If <code>-strict</code> is specified, then an
6010 empty string returns 0, otherwise an empty string will return 1
6011 on any class. The following character classes are recognized
6012 (the class name can be abbreviated):
6013 </p>
6014 </dd>
6015 <dt class="hdlist1">
6017 </dt>
6018 <dd>
6019 <div class="dlist"><dl>
6020 <dt class="hdlist1">
6021 <code>alnum</code>
6022 </dt>
6023 <dd>
6025 Any alphabet or digit character.
6026 </p>
6027 </dd>
6028 <dt class="hdlist1">
6029 <code>alpha</code>
6030 </dt>
6031 <dd>
6033 Any alphabet character.
6034 </p>
6035 </dd>
6036 <dt class="hdlist1">
6037 <code>ascii</code>
6038 </dt>
6039 <dd>
6041 Any character with a value less than 128 (those that are in the 7-bit ascii range).
6042 </p>
6043 </dd>
6044 <dt class="hdlist1">
6045 <code>control</code>
6046 </dt>
6047 <dd>
6049 Any control character.
6050 </p>
6051 </dd>
6052 <dt class="hdlist1">
6053 <code>digit</code>
6054 </dt>
6055 <dd>
6057 Any digit character.
6058 </p>
6059 </dd>
6060 <dt class="hdlist1">
6061 <code>double</code>
6062 </dt>
6063 <dd>
6065 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
6066 In case of under/overflow in the value, 0 is returned.
6067 </p>
6068 </dd>
6069 <dt class="hdlist1">
6070 <code>graph</code>
6071 </dt>
6072 <dd>
6074 Any printing character, except space.
6075 </p>
6076 </dd>
6077 <dt class="hdlist1">
6078 <code>integer</code>
6079 </dt>
6080 <dd>
6082 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
6083 </p>
6084 </dd>
6085 <dt class="hdlist1">
6086 <code>lower</code>
6087 </dt>
6088 <dd>
6090 Any lower case alphabet character.
6091 </p>
6092 </dd>
6093 <dt class="hdlist1">
6094 <code>print</code>
6095 </dt>
6096 <dd>
6098 Any printing character, including space.
6099 </p>
6100 </dd>
6101 <dt class="hdlist1">
6102 <code>punct</code>
6103 </dt>
6104 <dd>
6106 Any punctuation character.
6107 </p>
6108 </dd>
6109 <dt class="hdlist1">
6110 <code>space</code>
6111 </dt>
6112 <dd>
6114 Any space character.
6115 </p>
6116 </dd>
6117 <dt class="hdlist1">
6118 <code>upper</code>
6119 </dt>
6120 <dd>
6122 Any upper case alphabet character.
6123 </p>
6124 </dd>
6125 <dt class="hdlist1">
6126 <code>xdigit</code>
6127 </dt>
6128 <dd>
6130 Any hexadecimal digit character ([0-9A-Fa-f]).
6131 </p>
6132 </dd>
6133 </dl></div>
6134 </dd>
6135 <dt class="hdlist1">
6137 </dt>
6138 <dd>
6140 Note that string classification does <code><em>not</em></code> respect UTF-8. See UTF-8 AND UNICODE
6141 </p>
6142 </dd>
6143 <dt class="hdlist1">
6144 <code><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></code>
6145 </dt>
6146 <dd>
6148 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6149 the characters in <code><em>string1</em></code>. If found, return the index of the
6150 first character in the last such match within <code><em>string2</em></code>. If there
6151 is no match, then return -1. If <code><em>lastIndex</em></code> is specified, only characters
6152 up to <code><em>lastIndex</em></code> of <code><em>string2</em></code> will be considered in the match.
6153 </p>
6154 </dd>
6155 <dt class="hdlist1">
6157 </dt>
6158 <dd>
6160 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>lastIndex</em></code>.
6161 </p>
6162 </dd>
6163 <dt class="hdlist1">
6164 <code><strong>string length</strong> <em>string</em></code>
6165 </dt>
6166 <dd>
6168 Returns a decimal string giving the number of characters in <code><em>string</em></code>.
6169 If UTF-8 support is enabled, this may be different than the number of bytes.
6170 See UTF-8 AND UNICODE
6171 </p>
6172 </dd>
6173 <dt class="hdlist1">
6174 <code><strong>string map ?-nocase?</strong> <em>mapping string</em></code>
6175 </dt>
6176 <dd>
6178 Replaces substrings in <code><em>string</em></code> based on the key-value pairs in
6179 <code><em>mapping</em></code>, which is a list of <code>key value key value ...</code> as in the form
6180 returned by <a href="#_array"><strong><code>array</code></strong></a> <code>get</code>. Each instance of a key in the string will be
6181 replaced with its corresponding value. If <code>-nocase</code> is specified, then
6182 matching is done without regard to case differences. Both key and value may
6183 be multiple characters. Replacement is done in an ordered manner, so the
6184 key appearing first in the list will be checked first, and so on. <code><em>string</em></code> is
6185 only iterated over once, so earlier key replacements will have no affect for
6186 later key matches. For example,
6187 </p>
6188 <div class="literalblock">
6189 <div class="content">
6190 <pre><code>string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc</code></pre>
6191 </div></div>
6192 </dd>
6193 <dt class="hdlist1">
6195 </dt>
6196 <dd>
6198 will return the string <code>01321221</code>.
6199 </p>
6200 </dd>
6201 <dt class="hdlist1">
6203 </dt>
6204 <dd>
6206 Note that if an earlier key is a prefix of a later one, it will completely mask the later
6207 one. So if the previous example is reordered like this,
6208 </p>
6209 <div class="literalblock">
6210 <div class="content">
6211 <pre><code>string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc</code></pre>
6212 </div></div>
6213 </dd>
6214 <dt class="hdlist1">
6216 </dt>
6217 <dd>
6219 it will return the string <code>02c322c222c</code>.
6220 </p>
6221 </dd>
6222 <dt class="hdlist1">
6223 <code><strong>string match ?-nocase?</strong> <em>pattern string</em></code>
6224 </dt>
6225 <dd>
6227 See if <code><em>pattern</em></code> matches <code><em>string</em></code>; return 1 if it does, 0
6228 if it doesn&#8217;t. Matching is done in a fashion similar to that
6229 used by the C-shell. For the two strings to match, their contents
6230 must be identical except that the following special sequences
6231 may appear in <code><em>pattern</em></code>:
6232 </p>
6233 <div class="dlist"><dl>
6234 <dt class="hdlist1">
6235 <code>*</code>
6236 </dt>
6237 <dd>
6239 Matches any sequence of characters in <code><em>string</em></code>,
6240 including a null string.
6241 </p>
6242 </dd>
6243 <dt class="hdlist1">
6244 <code>?</code>
6245 </dt>
6246 <dd>
6248 Matches any single character in <code><em>string</em></code>.
6249 </p>
6250 </dd>
6251 <dt class="hdlist1">
6252 <code>[<em>chars</em>]</code>
6253 </dt>
6254 <dd>
6256 Matches any character in the set given by <code><em>chars</em></code>.
6257 If a sequence of the form <code><em>x-y</em></code> appears in <code><em>chars</em></code>,
6258 then any character between <code><em>x</em></code> and <code><em>y</em></code>, inclusive,
6259 will match.
6260 </p>
6261 </dd>
6262 <dt class="hdlist1">
6263 <code>\x</code>
6264 </dt>
6265 <dd>
6267 Matches the single character <code><em>x</em></code>. This provides a way of
6268 avoiding the special interpretation of the characters <code>\*?[]</code>
6269 in <code><em>pattern</em></code>.
6270 </p>
6271 </dd>
6272 </dl></div>
6273 </dd>
6274 <dt class="hdlist1">
6276 </dt>
6277 <dd>
6279 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6280 </p>
6281 </dd>
6282 <dt class="hdlist1">
6283 <code><strong>string range</strong> <em>string first last</em></code>
6284 </dt>
6285 <dd>
6287 Returns a range of consecutive characters from <code><em>string</em></code>, starting
6288 with the character whose index is <code><em>first</em></code> and ending with the
6289 character whose index is <code><em>last</em></code>. An index of 0 refers to the
6290 first character of the string.
6291 </p>
6292 </dd>
6293 <dt class="hdlist1">
6295 </dt>
6296 <dd>
6298 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.
6299 </p>
6300 </dd>
6301 <dt class="hdlist1">
6303 </dt>
6304 <dd>
6306 If <code><em>first</em></code> is less than zero then it is treated as if it were zero, and
6307 if <code><em>last</em></code> is greater than or equal to the length of the string then
6308 it is treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than
6309 <code><em>last</em></code> then an empty string is returned.
6310 </p>
6311 </dd>
6312 <dt class="hdlist1">
6313 <code><strong>string repeat</strong> <em>string count</em></code>
6314 </dt>
6315 <dd>
6317 Returns a new string consisting of <code><em>string</em></code> repeated <code><em>count</em></code> times.
6318 </p>
6319 </dd>
6320 <dt class="hdlist1">
6321 <code><strong>string replace</strong> <em>string first last ?newstring?</em></code>
6322 </dt>
6323 <dd>
6325 Removes a range of consecutive characters from <code><em>string</em></code>, starting
6326 with the character whose index is <code><em>first</em></code> and ending with the
6327 character whose index is <code><em>last</em></code>. If <code><em>newstring</em></code> is specified,
6328 then it is placed in the removed character range. If <code><em>first</em></code> is
6329 less than zero then it is treated as if it were zero, and if <code><em>last</em></code>
6330 is greater than or equal to the length of the string then it is
6331 treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than <code><em>last</em></code>
6332 or the length of the initial string, or <code><em>last</em></code> is less than 0,
6333 then the initial string is returned untouched.
6334 </p>
6335 </dd>
6336 <dt class="hdlist1">
6337 <code><strong>string reverse</strong> <em>string</em></code>
6338 </dt>
6339 <dd>
6341 Returns a string that is the same length as <code><em>string</em></code> but
6342 with its characters in the reverse order.
6343 </p>
6344 </dd>
6345 <dt class="hdlist1">
6346 <code><strong>string tolower</strong> <em>string</em></code>
6347 </dt>
6348 <dd>
6350 Returns a value equal to <code><em>string</em></code> except that all upper case
6351 letters have been converted to lower case.
6352 </p>
6353 </dd>
6354 <dt class="hdlist1">
6355 <code><strong>string totitle</strong> <em>string</em></code>
6356 </dt>
6357 <dd>
6359 Returns a value equal to <code><em>string</em></code> except that the first character
6360 is converted to title case (or upper case if there is no UTF-8 titlecase variant)
6361 and all remaining characters have been converted to lower case.
6362 </p>
6363 </dd>
6364 <dt class="hdlist1">
6365 <code><strong>string toupper</strong> <em>string</em></code>
6366 </dt>
6367 <dd>
6369 Returns a value equal to <code><em>string</em></code> except that all lower case
6370 letters have been converted to upper case.
6371 </p>
6372 </dd>
6373 <dt class="hdlist1">
6374 <code><strong>string trim</strong> <em>string ?chars?</em></code>
6375 </dt>
6376 <dd>
6378 Returns a value equal to <code><em>string</em></code> except that any leading
6379 or trailing characters from the set given by <code><em>chars</em></code> are
6380 removed.
6381 If <code><em>chars</em></code> is not specified then white space is removed
6382 (spaces, tabs, newlines, and carriage returns).
6383 </p>
6384 </dd>
6385 <dt class="hdlist1">
6386 <code><strong>string trimleft</strong> <em>string ?chars?</em></code>
6387 </dt>
6388 <dd>
6390 Returns a value equal to <code><em>string</em></code> except that any
6391 leading characters from the set given by <code><em>chars</em></code> are
6392 removed.
6393 If <code><em>chars</em></code> is not specified then white space is removed
6394 (spaces, tabs, newlines, and carriage returns).
6395 </p>
6396 </dd>
6397 <dt class="hdlist1">
6398 <code><strong>string trimright</strong> <em>string ?chars?</em></code>
6399 </dt>
6400 <dd>
6402 Returns a value equal to <code><em>string</em></code> except that any
6403 trailing characters from the set given by <code><em>chars</em></code> are
6404 removed.
6405 If <code><em>chars</em></code> is not specified then white space is removed
6406 (spaces, tabs, newlines, and carriage returns).
6407 Null characters are always removed.
6408 </p>
6409 </dd>
6410 </dl></div>
6411 </div>
6412 <div class="sect2">
6413 <h3 id="_subst">subst</h3>
6414 <div class="paragraph"><p><code><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></code></p></div>
6415 <div class="paragraph"><p>This command performs variable substitutions, command substitutions,
6416 and backslash substitutions on its string argument and returns the
6417 fully-substituted result. The substitutions are performed in exactly
6418 the same way as for Tcl commands. As a result, the string argument
6419 is actually substituted twice, once by the Tcl parser in the usual
6420 fashion for Tcl commands, and again by the subst command.</p></div>
6421 <div class="paragraph"><p>If any of the <code>-nobackslashes</code>, <code>-nocommands</code>, or <code>-novariables</code> are
6422 specified, then the corresponding substitutions are not performed.
6423 For example, if <code>-nocommands</code> is specified, no command substitution
6424 is performed: open and close brackets are treated as ordinary
6425 characters with no special interpretation.</p></div>
6426 <div class="paragraph"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
6427 special treatment to double quotes or curly braces. For example,
6428 the following script returns <code>xyz {44}</code>, not <code>xyz {$a}</code>.</p></div>
6429 <div class="literalblock">
6430 <div class="content">
6431 <pre><code>set a 44
6432 subst {xyz {$a}}</code></pre>
6433 </div></div>
6434 </div>
6435 <div class="sect2">
6436 <h3 id="_switch">switch</h3>
6437 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string pattern body ?pattern body ...?</em></code></p></div>
6438 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string {pattern body ?pattern body ...?}</em></code></p></div>
6439 <div class="paragraph"><p>The <a href="#_switch"><strong><code>switch</code></strong></a> command matches its string argument against each of
6440 the pattern arguments in order. As soon as it finds a pattern that
6441 matches string it evaluates the following body and returns the
6442 result of that evaluation. If the last pattern argument is default
6443 then it matches anything. If no pattern argument matches string and
6444 no default is given, then the <a href="#_switch"><strong><code>switch</code></strong></a> command returns an empty string.
6445 If the initial arguments to switch start with - then they are treated
6446 as options. The following options are currently supported:</p></div>
6447 <div class="dlist"><dl>
6448 <dt class="hdlist1">
6449 <code>-exact</code>
6450 </dt>
6451 <dd>
6453 Use exact matching when comparing string to a
6454 pattern. This is the default.
6455 </p>
6456 </dd>
6457 <dt class="hdlist1">
6458 <code>-glob</code>
6459 </dt>
6460 <dd>
6462 When matching string to the patterns, use glob-style
6463 matching (i.e. the same as implemented by the string
6464 match command).
6465 </p>
6466 </dd>
6467 <dt class="hdlist1">
6468 <code>-regexp</code>
6469 </dt>
6470 <dd>
6472 When matching string to the patterns, use regular
6473 expression matching (i.e. the same as implemented
6474 by the regexp command).
6475 </p>
6476 </dd>
6477 <dt class="hdlist1">
6478 <code>-command <em>commandname</em></code>
6479 </dt>
6480 <dd>
6482 When matching string to the patterns, use the given command, which
6483 must be a single word. The command is invoked as
6484 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
6485 and must return 1 if matched, or 0 if not.
6486 </p>
6487 </dd>
6488 <dt class="hdlist1">
6489 <code>--</code>
6490 </dt>
6491 <dd>
6493 Marks the end of options. The argument following
6494 this one will be treated as string even if it starts
6495 with a <code>-</code>.
6496 </p>
6497 </dd>
6498 </dl></div>
6499 <div class="paragraph"><p>Two syntaxes are provided for the pattern and body arguments. The
6500 first uses a separate argument for each of the patterns and commands;
6501 this form is convenient if substitutions are desired on some of the
6502 patterns or commands. The second form places all of the patterns
6503 and commands together into a single argument; the argument must
6504 have proper list structure, with the elements of the list being the
6505 patterns and commands. The second form makes it easy to construct
6506 multi-line <a href="#_switch"><strong><code>switch</code></strong></a> commands, since the braces around the whole list
6507 make it unnecessary to include a backslash at the end of each line.
6508 Since the pattern arguments are in braces in the second form, no
6509 command or variable substitutions are performed on them; this makes
6510 the behaviour of the second form different than the first form in
6511 some cases.</p></div>
6512 <div class="paragraph"><p>If a body is specified as <code>-</code> it means that the body for the next
6513 pattern should also be used as the body for this pattern (if the
6514 next pattern also has a body of <code>-</code> then the body after that is
6515 used, and so on). This feature makes it possible to share a single
6516 body among several patterns.</p></div>
6517 <div class="paragraph"><p>Below are some examples of <a href="#_switch"><strong><code>switch</code></strong></a> commands:</p></div>
6518 <div class="literalblock">
6519 <div class="content">
6520 <pre><code>switch abc a - b {format 1} abc {format 2} default {format 3}</code></pre>
6521 </div></div>
6522 <div class="paragraph"><p>will return 2,</p></div>
6523 <div class="literalblock">
6524 <div class="content">
6525 <pre><code>switch -regexp aaab {
6526 ^a.*b$ -
6527 b {format 1}
6528 a* {format 2}
6529 default {format 3}
6530 }</code></pre>
6531 </div></div>
6532 <div class="paragraph"><p>will return 1, and</p></div>
6533 <div class="literalblock">
6534 <div class="content">
6535 <pre><code>switch xyz {
6537 b {format 1}
6538 a* {format 2}
6539 default {format 3}
6540 }</code></pre>
6541 </div></div>
6542 <div class="paragraph"><p>will return 3.</p></div>
6543 </div>
6544 <div class="sect2">
6545 <h3 id="_tailcall">tailcall</h3>
6546 <div class="paragraph"><p><code><strong>tailcall</strong> <em>cmd ?arg...?</em></code></p></div>
6547 <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
6548 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
6549 <div class="paragraph"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
6550 <div class="literalblock">
6551 <div class="content">
6552 <pre><code>tailcall a b c</code></pre>
6553 </div></div>
6554 <div class="literalblock">
6555 <div class="content">
6556 <pre><code>return [uplevel 1 [list a b c]]</code></pre>
6557 </div></div>
6558 <div class="paragraph"><p><a href="#_tailcall"><strong><code>tailcall</code></strong></a> is useful as a dispatch mechanism:</p></div>
6559 <div class="literalblock">
6560 <div class="content">
6561 <pre><code>proc a {cmd args} {
6562 tailcall sub_$cmd {*}$args
6564 proc sub_cmd1 ...
6565 proc sub_cmd2 ...</code></pre>
6566 </div></div>
6567 </div>
6568 <div class="sect2">
6569 <h3 id="_tell">tell</h3>
6570 <div class="paragraph"><p><code><strong>tell</strong> <em>fileId</em></code></p></div>
6571 <div class="paragraph"><p><code><em>fileId</em> <strong>tell</strong></code></p></div>
6572 <div class="paragraph"><p>Returns a decimal string giving the current access position in
6573 <code><em>fileId</em></code>.</p></div>
6574 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
6575 <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
6576 of the standard I/O channels.</p></div>
6577 </div>
6578 <div class="sect2">
6579 <h3 id="_throw">throw</h3>
6580 <div class="paragraph"><p><code><strong>throw</strong> <em>code ?msg?</em></code></p></div>
6581 <div class="paragraph"><p>This command throws an exception (return) code along with an optional message.
6582 This command is mostly for convenient usage with <a href="#_try"><strong><code>try</code></strong></a>.</p></div>
6583 <div class="paragraph"><p>The command <code>throw break</code> is equivalent to <code>break</code>.
6584 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>
6585 </div>
6586 <div class="sect2">
6587 <h3 id="_time">time</h3>
6588 <div class="paragraph"><p><code><strong>time</strong> <em>command ?count?</em></code></p></div>
6589 <div class="paragraph"><p>This command will call the Tcl interpreter <code><em>count</em></code>
6590 times to execute <code><em>command</em></code> (or once if <code><em>count</em></code> isn&#8217;t
6591 specified). It will then return a string of the form</p></div>
6592 <div class="literalblock">
6593 <div class="content">
6594 <pre><code>503 microseconds per iteration</code></pre>
6595 </div></div>
6596 <div class="paragraph"><p>which indicates the average amount of time required per iteration,
6597 in microseconds.</p></div>
6598 <div class="paragraph"><p>Time is measured in elapsed time, not CPU time.</p></div>
6599 </div>
6600 <div class="sect2">
6601 <h3 id="_try">try</h3>
6602 <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>
6603 <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>
6604 <div class="paragraph"><p>This interpeter first evaluates <code><em>tryscript</em></code> under the effect of the catch
6605 options <code><em>catchopts</em></code> (e.g. <code>-signal -noexit --</code>, see <a href="#_catch"><strong><code>catch</code></strong></a>).</p></div>
6606 <div class="paragraph"><p>It then evaluates the script for the first matching <em>on</em> handler
6607 (there many be zero or more) based on the return code from the <a href="#_try"><strong><code>try</code></strong></a>
6608 section. For example a normal <code>JIM_ERR</code> error will be matched by
6609 an <em>on error</em> handler.</p></div>
6610 <div class="paragraph"><p>Finally, any <code><em>finalscript</em></code> is evaluated.</p></div>
6611 <div class="paragraph"><p>The result of this command is the result of <code><em>tryscript</em></code>, except in the
6612 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
6613 in which case the result is this new exception.</p></div>
6614 <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.)
6615 or as integers.</p></div>
6616 <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
6617 the matching handler.</p></div>
6618 <div class="paragraph"><p>For example:</p></div>
6619 <div class="literalblock">
6620 <div class="content">
6621 <pre><code>set f [open input]
6622 try -signal {
6623 process $f
6624 } on {continue break} {} {
6625 error "Unexpected break/continue"
6626 } on error {msg opts} {
6627 puts "Dealing with error"
6628 return {*}$opts $msg
6629 } on signal sig {
6630 puts "Got signal: $sig"
6631 } finally {
6632 $f close
6633 }</code></pre>
6634 </div></div>
6635 <div class="paragraph"><p>If break, continue or error are raised, they are dealt with by the matching
6636 handler.</p></div>
6637 <div class="paragraph"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6638 <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>
6639 </div>
6640 <div class="sect2">
6641 <h3 id="_unknown">unknown</h3>
6642 <div class="paragraph"><p><code><strong>unknown</strong> <em>cmdName ?arg arg &#8230;?</em></code></p></div>
6643 <div class="paragraph"><p>This command doesn&#8217;t actually exist as part of Tcl, but Tcl will
6644 invoke it if it does exist.</p></div>
6645 <div class="paragraph"><p>If the Tcl interpreter encounters a command name for which there
6646 is not a defined command, then Tcl checks for the existence of
6647 a command named <a href="#_unknown"><strong><code>unknown</code></strong></a>.</p></div>
6648 <div class="paragraph"><p>If there is no such command, then the interpreter returns an
6649 error.</p></div>
6650 <div class="paragraph"><p>If the <a href="#_unknown"><strong><code>unknown</code></strong></a> command exists, then it is invoked with
6651 arguments consisting of the fully-substituted name and arguments
6652 for the original non-existent command.</p></div>
6653 <div class="paragraph"><p>The <a href="#_unknown"><strong><code>unknown</code></strong></a> command typically does things like searching
6654 through library directories for a command procedure with the name
6655 <code><em>cmdName</em></code>, or expanding abbreviated command names to full-length,
6656 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6657 <div class="paragraph"><p>In some cases (such as expanding abbreviations) <a href="#_unknown"><strong><code>unknown</code></strong></a> will
6658 change the original command slightly and then (re-)execute it.
6659 The result of the <a href="#_unknown"><strong><code>unknown</code></strong></a> command is used as the result for
6660 the original non-existent command.</p></div>
6661 </div>
6662 <div class="sect2">
6663 <h3 id="_unset">unset</h3>
6664 <div class="paragraph"><p><code><strong>unset ?-nocomplain? ?--?</strong> <em>?name name &#8230;?</em></code></p></div>
6665 <div class="paragraph"><p>Remove variables.
6666 Each <code><em>name</em></code> is a variable name, specified in any of the
6667 ways acceptable to the <a href="#_set"><strong><code>set</code></strong></a> command.</p></div>
6668 <div class="paragraph"><p>If a <code><em>name</em></code> refers to an element of an array, then that
6669 element is removed without affecting the rest of the array.</p></div>
6670 <div class="paragraph"><p>If a <code><em>name</em></code> consists of an array name with no parenthesized
6671 index, then the entire array is deleted.</p></div>
6672 <div class="paragraph"><p>The <a href="#_unset"><strong><code>unset</code></strong></a> command returns an empty string as result.</p></div>
6673 <div class="paragraph"><p>An error occurs if any of the variables doesn&#8217;t exist, unless <em>-nocomplain</em>
6674 is specified. The <em>--</em> argument may be specified to stop option processing
6675 in case the variable name may be <em>-nocomplain</em>.</p></div>
6676 </div>
6677 <div class="sect2">
6678 <h3 id="_upcall">upcall</h3>
6679 <div class="paragraph"><p><code><strong>upcall</strong> <em>command ?args &#8230;?</em></code></p></div>
6680 <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
6681 the previous, hidden version of the same command.</p></div>
6682 <div class="paragraph"><p>If there is no previous definition of the command, an error is returned.</p></div>
6683 </div>
6684 <div class="sect2">
6685 <h3 id="_uplevel">uplevel</h3>
6686 <div class="paragraph"><p><code><strong>uplevel</strong> <em>?level? command ?command &#8230;?</em></code></p></div>
6687 <div class="paragraph"><p>All of the <code><em>command</em></code> arguments are concatenated as if they had
6688 been passed to <a href="#_concat"><strong><code>concat</code></strong></a>; the result is then evaluated in the
6689 variable context indicated by <code><em>level</em></code>. <a href="#_uplevel"><strong><code>uplevel</code></strong></a> returns
6690 the result of that evaluation. If <code><em>level</em></code> is an integer, then
6691 it gives a distance (up the procedure calling stack) to move before
6692 executing the command. If <code><em>level</em></code> consists of <code>#</code> followed by
6693 a number then the number gives an absolute level number. If <code><em>level</em></code>
6694 is omitted then it defaults to <code>1</code>. <code><em>level</em></code> cannot be
6695 defaulted if the first <code><em>command</em></code> argument starts with a digit or <code>#</code>.</p></div>
6696 <div class="paragraph"><p>For example, suppose that procedure <em>a</em> was invoked
6697 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6698 Suppose that <em>c</em> invokes the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command. If <code><em>level</em></code>
6699 is <code>1</code> or <code>#2</code> or omitted, then the command will be executed
6700 in the variable context of <em>b</em>. If <code><em>level</em></code> is <code>2</code> or <code>#1</code>
6701 then the command will be executed in the variable context of <em>a</em>.</p></div>
6702 <div class="paragraph"><p>If <code><em>level</em></code> is <em>3</em> or <code>#0</code> then the command will be executed
6703 at top-level (only global variables will be visible).
6704 The <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command causes the invoking procedure to disappear
6705 from the procedure calling stack while the command is being executed.
6706 In the above example, suppose <em>c</em> invokes the command</p></div>
6707 <div class="literalblock">
6708 <div class="content">
6709 <pre><code>uplevel 1 {set x 43; d}</code></pre>
6710 </div></div>
6711 <div class="paragraph"><p>where <em>d</em> is another Tcl procedure. The <a href="#_set"><strong><code>set</code></strong></a> command will
6712 modify the variable <em>x</em> in <em>b&#8217;s context, and 'd</em> will execute
6713 at level 3, as if called from <em>b</em>. If it in turn executes
6714 the command</p></div>
6715 <div class="literalblock">
6716 <div class="content">
6717 <pre><code>uplevel {set x 42}</code></pre>
6718 </div></div>
6719 <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
6720 context: the procedure 'c</em> does not appear to be on the call stack
6721 when <em>d</em> is executing. The command <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> may
6722 be used to obtain the level of the current procedure.</p></div>
6723 <div class="paragraph"><p><a href="#_uplevel"><strong><code>uplevel</code></strong></a> makes it possible to implement new control
6724 constructs as Tcl procedures (for example, <a href="#_uplevel"><strong><code>uplevel</code></strong></a> could
6725 be used to implement the <a href="#_while"><strong><code>while</code></strong></a> construct as a Tcl procedure).</p></div>
6726 </div>
6727 <div class="sect2">
6728 <h3 id="_upvar">upvar</h3>
6729 <div class="paragraph"><p><code><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar &#8230;?</em></code></p></div>
6730 <div class="paragraph"><p>This command arranges for one or more local variables in the current
6731 procedure to refer to variables in an enclosing procedure call or
6732 to global variables.</p></div>
6733 <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>
6734 command, and may be omitted if the first letter of the first <code><em>otherVar</em></code>
6735 isn&#8217;t <code>#</code> or a digit (it defaults to <em>1</em>).</p></div>
6736 <div class="paragraph"><p>For each <code><em>otherVar</em></code> argument, <a href="#_upvar"><strong><code>upvar</code></strong></a> makes the variable
6737 by that name in the procedure frame given by <code><em>level</em></code> (or at
6738 global level, if <code><em>level</em></code> is <code>#0</code>) accessible
6739 in the current procedure by the name given in the corresponding
6740 <code><em>myVar</em></code> argument.</p></div>
6741 <div class="paragraph"><p>The variable named by <code><em>otherVar</em></code> need not exist at the time of the
6742 call; it will be created the first time <code><em>myVar</em></code> is referenced, just like
6743 an ordinary variable.</p></div>
6744 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> may only be invoked from within procedures.</p></div>
6745 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> returns an empty string.</p></div>
6746 <div class="paragraph"><p>The <a href="#_upvar"><strong><code>upvar</code></strong></a> command simplifies the implementation of call-by-name
6747 procedure calling and also makes it easier to build new control constructs
6748 as Tcl procedures.
6749 For example, consider the following procedure:</p></div>
6750 <div class="literalblock">
6751 <div class="content">
6752 <pre><code>proc add2 name {
6753 upvar $name x
6754 set x [expr $x+2]
6755 }</code></pre>
6756 </div></div>
6757 <div class="paragraph"><p><em>add2</em> is invoked with an argument giving the name of a variable,
6758 and it adds two to the value of that variable.
6759 Although <em>add2</em> could have been implemented using <a href="#_uplevel"><strong><code>uplevel</code></strong></a>
6760 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>
6761 to access the variable in the caller&#8217;s procedure frame.</p></div>
6762 </div>
6763 <div class="sect2">
6764 <h3 id="_while">while</h3>
6765 <div class="paragraph"><p><code><strong>while</strong> <em>test body</em></code></p></div>
6766 <div class="paragraph"><p>The <code><em>while</em></code> command evaluates <code><em>test</em></code> as an expression
6767 (in the same way that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument).
6768 The value of the expression must be numeric; if it is non-zero
6769 then <code><em>body</em></code> is executed by passing it to the Tcl interpreter.</p></div>
6770 <div class="paragraph"><p>Once <code><em>body</em></code> has been executed then <code><em>test</em></code> is evaluated
6771 again, and the process repeats until eventually <code><em>test</em></code>
6772 evaluates to a zero numeric value. <a href="#_continue"><strong><code>continue</code></strong></a>
6773 commands may be executed inside <code><em>body</em></code> to terminate the current
6774 iteration of the loop, and <a href="#_break"><strong><code>break</code></strong></a>
6775 commands may be executed inside <code><em>body</em></code> to cause immediate
6776 termination of the <a href="#_while"><strong><code>while</code></strong></a> command.</p></div>
6777 <div class="paragraph"><p>The <a href="#_while"><strong><code>while</code></strong></a> command always returns an empty string.</p></div>
6778 </div>
6779 </div>
6780 </div>
6781 <div class="sect1">
6782 <h2 id="_optional_extensions">OPTIONAL-EXTENSIONS</h2>
6783 <div class="sectionbody">
6784 <div class="paragraph"><p>The following extensions may or may not be available depending upon
6785 what options were selected when Jim Tcl was built.</p></div>
6786 <div class="sect2">
6787 <h3 id="cmd_1">posix: os.fork, os.wait, os.gethostname, os.getids, os.uptime</h3>
6788 <div class="dlist"><dl>
6789 <dt class="hdlist1">
6790 <code><strong>os.fork</strong></code>
6791 </dt>
6792 <dd>
6794 Invokes <em>fork(2)</em> and returns the result.
6795 </p>
6796 </dd>
6797 <dt class="hdlist1">
6798 <code><strong>os.wait -nohang</strong> <em>pid</em></code>
6799 </dt>
6800 <dd>
6802 Invokes waitpid(2), with WNOHANG if <code>-nohang</code> is specified.
6803 Returns a list of 3 elements.
6804 </p>
6805 <div class="literalblock">
6806 <div class="content">
6807 <pre><code>{0 none 0} if -nohang is specified, and the process is still alive.</code></pre>
6808 </div></div>
6809 <div class="literalblock">
6810 <div class="content">
6811 <pre><code>{-1 error &lt;error-description&gt;} if the process does not exist or has already been waited for.</code></pre>
6812 </div></div>
6813 <div class="literalblock">
6814 <div class="content">
6815 <pre><code>{&lt;pid&gt; exit &lt;exit-status&gt;} if the process exited normally.</code></pre>
6816 </div></div>
6817 <div class="literalblock">
6818 <div class="content">
6819 <pre><code>{&lt;pid&gt; signal &lt;signal-number&gt;} if the process terminated on a signal.</code></pre>
6820 </div></div>
6821 <div class="literalblock">
6822 <div class="content">
6823 <pre><code>{&lt;pid&gt; other 0} otherwise (core dump, stopped, continued, etc.)</code></pre>
6824 </div></div>
6825 </dd>
6826 <dt class="hdlist1">
6827 <code><strong>os.gethostname</strong></code>
6828 </dt>
6829 <dd>
6831 Invokes <em>gethostname(3)</em> and returns the result.
6832 </p>
6833 </dd>
6834 <dt class="hdlist1">
6835 <code><strong>os.getids</strong></code>
6836 </dt>
6837 <dd>
6839 Returns the various user/group ids for the current process.
6840 </p>
6841 <div class="literalblock">
6842 <div class="content">
6843 <pre><code>jim&gt; os.getids
6844 uid 1000 euid 1000 gid 100 egid 100</code></pre>
6845 </div></div>
6846 </dd>
6847 <dt class="hdlist1">
6848 <code><strong>os.uptime</strong></code>
6849 </dt>
6850 <dd>
6852 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
6853 </p>
6854 </dd>
6855 </dl></div>
6856 </div>
6857 </div>
6858 </div>
6859 <div class="sect1">
6860 <h2 id="_ansi_i_o_aio_and_eventloop_api">ANSI I/O (aio) and EVENTLOOP API</h2>
6861 <div class="sectionbody">
6862 <div class="paragraph"><p>Jim provides an alternative object-based API for I/O.</p></div>
6863 <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>
6864 <div class="sect2">
6865 <h3 id="_aio">aio</h3>
6866 <div class="dlist"><dl>
6867 <dt class="hdlist1">
6868 <code>$handle <strong>accept</strong> ?addrvar?</code>
6869 </dt>
6870 <dd>
6872 Server socket only: Accept a connection and return stream.
6873 If <code><em>addrvar</em></code> is specified, the address of the connected client is stored
6874 in the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
6875 </p>
6876 </dd>
6877 <dt class="hdlist1">
6878 <code>$handle <strong>buffering none|line|full</strong></code>
6879 </dt>
6880 <dd>
6882 Sets the buffering mode of the stream.
6883 </p>
6884 </dd>
6885 <dt class="hdlist1">
6886 <code>$handle <strong>close</strong> ?r(ead)|w(rite)?</code>
6887 </dt>
6888 <dd>
6890 Closes the stream.
6891 The two-argument form is a "half-close" on a socket. See the <code>shutdown(2)</code> man page.
6892 </p>
6893 </dd>
6894 <dt class="hdlist1">
6895 <code>$handle <strong>copyto</strong> <em>tofd ?size?</em></code>
6896 </dt>
6897 <dd>
6899 Copy bytes to the file descriptor <code><em>tofd</em></code>. If <code><em>size</em></code> is specified, at most
6900 that many bytes will be copied. Otherwise copying continues until the end
6901 of the input file. Returns the number of bytes actually copied.
6902 </p>
6903 </dd>
6904 <dt class="hdlist1">
6905 <code>$handle <strong>eof</strong></code>
6906 </dt>
6907 <dd>
6909 Returns 1 if stream is at eof
6910 </p>
6911 </dd>
6912 <dt class="hdlist1">
6913 <code>$handle <strong>filename</strong></code>
6914 </dt>
6915 <dd>
6917 Returns the original filename associated with the handle.
6918 Handles returned by <a href="#_socket"><strong><code>socket</code></strong></a> give the socket type instead of a filename.
6919 </p>
6920 </dd>
6921 <dt class="hdlist1">
6922 <code>$handle <strong>flush</strong></code>
6923 </dt>
6924 <dd>
6926 Flush the stream
6927 </p>
6928 </dd>
6929 <dt class="hdlist1">
6930 <code>$handle <strong>gets</strong> <em>?var?</em></code>
6931 </dt>
6932 <dd>
6934 Read one line and return it or store it in the var
6935 </p>
6936 </dd>
6937 <dt class="hdlist1">
6938 <code>$handle <strong>isatty</strong></code>
6939 </dt>
6940 <dd>
6942 Returns 1 if the stream is a tty device.
6943 </p>
6944 </dd>
6945 <dt class="hdlist1">
6946 <code>$handle <strong>ndelay ?0|1?</strong></code>
6947 </dt>
6948 <dd>
6950 Set O_NDELAY (if arg). Returns current/new setting.
6951 Note that in general ANSI I/O interacts badly with non-blocking I/O.
6952 Use with care.
6953 </p>
6954 </dd>
6955 <dt class="hdlist1">
6956 <code>$handle <strong>puts ?-nonewline?</strong> <em>str</em></code>
6957 </dt>
6958 <dd>
6960 Write the string, with newline unless -nonewline
6961 </p>
6962 </dd>
6963 <dt class="hdlist1">
6964 <code>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></code>
6965 </dt>
6966 <dd>
6968 Read and return bytes from the stream. To eof if no len.
6969 </p>
6970 </dd>
6971 <dt class="hdlist1">
6972 <code>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></code>
6973 </dt>
6974 <dd>
6976 Receives a message from the handle via recvfrom(2) and returns it.
6977 At most <code><em>maxlen</em></code> bytes are read.
6978 If <code><em>addrvar</em></code> is specified, the sending address of the message is stored in
6979 the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
6980 </p>
6981 </dd>
6982 <dt class="hdlist1">
6983 <code>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></code>
6984 </dt>
6985 <dd>
6987 Seeks in the stream (default <em>current</em>)
6988 </p>
6989 </dd>
6990 <dt class="hdlist1">
6991 <code>$handle <strong>sendto</strong> <em>str ?addr:?port</em></code>
6992 </dt>
6993 <dd>
6995 Sends the string, <code><em>str</em></code>, to the given address via the socket using sendto(2).
6996 This is intended for udp/dgram sockets and may give an error or behave in unintended
6997 ways for other handle types.
6998 Returns the number of bytes written.
6999 </p>
7000 </dd>
7001 <dt class="hdlist1">
7002 <code>$handle <strong>tell</strong></code>
7003 </dt>
7004 <dd>
7006 Returns the current seek position
7007 </p>
7008 </dd>
7009 </dl></div>
7010 </div>
7011 <div class="sect2">
7012 <h3 id="_fconfigure">fconfigure</h3>
7013 <div class="dlist"><dl>
7014 <dt class="hdlist1">
7015 <code><strong>fconfigure</strong> <em>handle</em> <strong>?-blocking 0|1? ?-buffering noneline|full? ?-translation</strong> <em>mode</em>?</code>
7016 </dt>
7017 <dd>
7019 For compatibility with Tcl, a limited form of the <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a>
7020 command is supported.
7021 </p>
7022 <div class="ulist"><ul>
7023 <li>
7025 <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>
7026 </p>
7027 </li>
7028 <li>
7030 <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>
7031 </p>
7032 </li>
7033 <li>
7035 <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a> <code>... -translation</code> is accepted but ignored
7036 </p>
7037 </li>
7038 </ul></div>
7039 </dd>
7040 </dl></div>
7041 </div>
7042 <div class="sect2">
7043 <h3 id="cmd_2">eventloop: after, vwait, update</h3>
7044 <div class="paragraph"><p>The following commands allow a script to be invoked when the given condition occurs.
7045 If no script is given, returns the current script. If the given script is the empty, the
7046 handler is removed.</p></div>
7047 <div class="dlist"><dl>
7048 <dt class="hdlist1">
7049 <code>$handle <strong>readable</strong> <em>?readable-script?</em></code>
7050 </dt>
7051 <dd>
7053 Sets or returns the script for when the socket is readable.
7054 </p>
7055 </dd>
7056 <dt class="hdlist1">
7057 <code>$handle <strong>writable</strong> <em>?writable-script?</em></code>
7058 </dt>
7059 <dd>
7061 Sets or returns the script for when the socket is writable.
7062 </p>
7063 </dd>
7064 <dt class="hdlist1">
7065 <code>$handle <strong>onexception</strong> <em>?exception-script?</em></code>
7066 </dt>
7067 <dd>
7069 Sets or returns the script for when when oob data received.
7070 </p>
7071 </dd>
7072 </dl></div>
7073 <div class="paragraph"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <code>fileevent</code>. e.g.</p></div>
7074 <div class="dlist"><dl>
7075 <dt class="hdlist1">
7077 </dt>
7078 <dd>
7080 <code>fileevent $handle <strong>readable</strong> <em>...</em></code>
7081 </p>
7082 </dd>
7083 </dl></div>
7084 <div class="paragraph"><p>Time-based execution is also available via the eventloop API.</p></div>
7085 <div class="dlist"><dl>
7086 <dt class="hdlist1">
7087 <code><strong>after</strong> <em>ms</em></code>
7088 </dt>
7089 <dd>
7091 Sleeps for the given number of milliseconds. No events are
7092 processed during this time.
7093 </p>
7094 </dd>
7095 <dt class="hdlist1">
7096 <code><strong>after</strong> <em>ms</em>|<strong>idle</strong> script ?script ...?'</code>
7097 </dt>
7098 <dd>
7100 The scripts are concatenated and executed after the given
7101 number of milliseconds have elapsed. If <em>idle</em> is specified,
7102 the script will run the next time the event loop is processed
7103 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
7104 then removed. Returns an event id.
7105 </p>
7106 </dd>
7107 <dt class="hdlist1">
7108 <code><strong>after cancel</strong> <em>id|command</em></code>
7109 </dt>
7110 <dd>
7112 Cancels an <a href="#cmd_2"><strong><code>after</code></strong></a> event with the given event id or matching
7113 command (script). Returns the number of milliseconds
7114 remaining until the event would have fired. Returns the
7115 empty string if no matching event is found.
7116 </p>
7117 </dd>
7118 <dt class="hdlist1">
7119 <code><strong>after info</strong> <em>?id?</em></code>
7120 </dt>
7121 <dd>
7123 If <code><em>id</em></code> is not given, returns a list of current <a href="#cmd_2"><strong><code>after</code></strong></a>
7124 events. If <code><em>id</em></code> is given, returns a list containing the
7125 associated script and either <em>timer</em> or <em>idle</em> to indicated
7126 the type of the event. An error occurs if <code><em>id</em></code> does not
7127 match an event.
7128 </p>
7129 </dd>
7130 <dt class="hdlist1">
7131 <code><strong>vwait</strong> <em>variable</em></code>
7132 </dt>
7133 <dd>
7135 A call to <a href="#cmd_2"><strong><code>vwait</code></strong></a> is enters the eventloop. <a href="#cmd_2"><strong><code>vwait</code></strong></a> processes
7136 events until the named (global) variable changes or all
7137 event handlers are removed. The variable need not exist
7138 beforehand. If there are no event handlers defined, <a href="#cmd_2"><strong><code>vwait</code></strong></a>
7139 returns immediately.
7140 </p>
7141 </dd>
7142 <dt class="hdlist1">
7143 <code><strong>update ?idletasks?</strong></code>
7144 </dt>
7145 <dd>
7147 A call to <a href="#cmd_2"><strong><code>update</code></strong></a> enters the eventloop to process expired events, but
7148 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
7149 not file events.
7150 Returns once handlers have been run for all expired events.
7151 </p>
7152 </dd>
7153 </dl></div>
7154 <div class="paragraph"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
7155 an attempt is made to call (the user-defined command) <code>bgerror</code> with the details of the error.
7156 If the <code>bgerror</code> command does not exist, the error message details are printed to stderr instead.</p></div>
7157 <div class="paragraph"><p>If a file event handler script generates an error, the handler is automatically removed
7158 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
7159 <div class="dlist"><dl>
7160 <dt class="hdlist1">
7161 <code><strong>bgerror</strong> <em>msg</em></code>
7162 </dt>
7163 <dd>
7165 Called when an event handler script generates an error. Note that the normal command resolution
7166 rules are used for bgerror. First the name is resolved in the current namespace, then in the
7167 global scope.
7168 </p>
7169 </dd>
7170 </dl></div>
7171 </div>
7172 <div class="sect2">
7173 <h3 id="_socket">socket</h3>
7174 <div class="paragraph"><p>Various socket types may be created.</p></div>
7175 <div class="dlist"><dl>
7176 <dt class="hdlist1">
7177 <code><strong>socket unix</strong> <em>path</em></code>
7178 </dt>
7179 <dd>
7181 A unix domain socket client.
7182 </p>
7183 </dd>
7184 <dt class="hdlist1">
7185 <code><strong>socket unix.server</strong> <em>path</em></code>
7186 </dt>
7187 <dd>
7189 A unix domain socket server.
7190 </p>
7191 </dd>
7192 <dt class="hdlist1">
7193 <code><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></code>
7194 </dt>
7195 <dd>
7197 A TCP socket client. (See the forms for <code><em>addr</em></code> below)
7198 </p>
7199 </dd>
7200 <dt class="hdlist1">
7201 <code><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></code>
7202 </dt>
7203 <dd>
7205 A TCP socket server (<code><em>addr</em></code> defaults to <code>0.0.0.0</code> for IPv4 or <code>[::]</code> for IPv6).
7206 </p>
7207 </dd>
7208 <dt class="hdlist1">
7209 <code><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</code>
7210 </dt>
7211 <dd>
7213 A UDP socket client. If the address is not specified,
7214 the client socket will be unbound and <em>sendto</em> must be used
7215 to indicated the destination.
7216 </p>
7217 </dd>
7218 <dt class="hdlist1">
7219 <code><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></code>
7220 </dt>
7221 <dd>
7223 A UDP socket server.
7224 </p>
7225 </dd>
7226 <dt class="hdlist1">
7227 <code><strong>socket pipe</strong></code>
7228 </dt>
7229 <dd>
7231 A pipe. Note that unlike all other socket types, this command returns
7232 a list of two channels: {read write}
7233 </p>
7234 </dd>
7235 <dt class="hdlist1">
7236 <code><strong>socket pair</strong></code>
7237 </dt>
7238 <dd>
7240 A socketpair (see socketpair(2)). Like <a href="#_socket"><strong><code>socket</code></strong></a> <code>pipe</code>, this command returns
7241 a list of two channels: {s1 s2}. These channels are both readable and writable.
7242 </p>
7243 </dd>
7244 </dl></div>
7245 <div class="paragraph"><p>This command creates a socket connected (client) or bound (server) to the given
7246 address.</p></div>
7247 <div class="paragraph"><p>The returned value is channel and may generally be used with the various file I/O
7248 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
7249 <div class="literalblock">
7250 <div class="content">
7251 <pre><code>set f [socket stream www.google.com:80]
7252 aio.sockstream1
7253 $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
7254 $f gets
7255 HTTP/1.0 302 Found
7256 $f close</code></pre>
7257 </div></div>
7258 <div class="paragraph"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
7259 the EVENTLOOP API.</p></div>
7260 <div class="literalblock">
7261 <div class="content">
7262 <pre><code>set f [socket stream.server 80]
7263 $f readable {
7264 set client [$f accept]
7265 $client gets $buf
7267 $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
7268 $client close
7270 vwait done</code></pre>
7271 </div></div>
7272 <div class="paragraph"><p>The address, <code><em>addr</em></code>, can be given in one of the following forms:</p></div>
7273 <div class="olist arabic"><ol class="arabic">
7274 <li>
7276 For IPv4 socket types, an IPv4 address such as 192.168.1.1
7277 </p>
7278 </li>
7279 <li>
7281 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
7282 </p>
7283 </li>
7284 <li>
7286 A hostname
7287 </p>
7288 </li>
7289 </ol></div>
7290 <div class="paragraph"><p>Note that on many systems, listening on an IPv6 address such as [::] will
7291 also accept requests via IPv4.</p></div>
7292 <div class="paragraph"><p>Where a hostname is specified, the <code><em>first</em></code> returned address is used
7293 which matches the socket type is used.</p></div>
7294 <div class="paragraph"><p>The special type <em>pipe</em> isn&#8217;t really a socket.</p></div>
7295 <div class="literalblock">
7296 <div class="content">
7297 <pre><code>lassign [socket pipe] r w</code></pre>
7298 </div></div>
7299 <div class="literalblock">
7300 <div class="content">
7301 <pre><code># Must close $w after exec
7302 exec ps &gt;@$w &amp;
7303 $w close</code></pre>
7304 </div></div>
7305 <div class="literalblock">
7306 <div class="content">
7307 <pre><code>$r readable ...</code></pre>
7308 </div></div>
7309 </div>
7310 <div class="sect2">
7311 <h3 id="_syslog">syslog</h3>
7312 <div class="paragraph"><p><code><strong>syslog</strong> <em>?options? ?priority? message</em></code></p></div>
7313 <div class="paragraph"><p>This command sends message to system syslog facility with given
7314 priority. Valid priorities are:</p></div>
7315 <div class="literalblock">
7316 <div class="content">
7317 <pre><code>emerg, alert, crit, err, error, warning, notice, info, debug</code></pre>
7318 </div></div>
7319 <div class="paragraph"><p>If a message is specified, but no priority is specified, then a
7320 priority of info is used.</p></div>
7321 <div class="paragraph"><p>By default, facility user is used and the value of global tcl variable
7322 argv0 is used as ident string. However, any of the following options
7323 may be specified before priority to control these parameters:</p></div>
7324 <div class="dlist"><dl>
7325 <dt class="hdlist1">
7326 <code><strong>-facility</strong> <em>value</em></code>
7327 </dt>
7328 <dd>
7330 Use specified facility instead of user. The following
7331 values for facility are recognized:
7332 </p>
7333 <div class="literalblock">
7334 <div class="content">
7335 <pre><code>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
7336 uucp, local0-local7</code></pre>
7337 </div></div>
7338 </dd>
7339 <dt class="hdlist1">
7340 <code><strong>-ident</strong> <em>string</em></code>
7341 </dt>
7342 <dd>
7344 Use given string instead of argv0 variable for ident string.
7345 </p>
7346 </dd>
7347 <dt class="hdlist1">
7348 <code><strong>-options</strong> <em>integer</em></code>
7349 </dt>
7350 <dd>
7352 Set syslog options such as <code>LOG_CONS</code>, <code>LOG_NDELAY</code>. You should
7353 use numeric values of those from your system syslog.h file,
7354 because I haven&#8217;t got time to implement yet another hash
7355 table.
7356 </p>
7357 </dd>
7358 </dl></div>
7359 </div>
7360 <div class="sect2">
7361 <h3 id="cmd_3">pack: pack, unpack</h3>
7362 <div class="paragraph"><p>The optional <em>pack</em> extension provides commands to encode and decode binary strings.</p></div>
7363 <div class="dlist"><dl>
7364 <dt class="hdlist1">
7365 <code><strong>pack</strong> <em>varName value</em> <strong>-intle|-intbe|-floatle|-floatbe|-str</strong> <em>bitwidth ?bitoffset?</em></code>
7366 </dt>
7367 <dd>
7369 Packs the binary representation of <code><em>value</em></code> into the variable
7370 <code><em>varName</em></code>. The value is packed according to the given type
7371 (integer/floating point/string, big-endian/little-endian), width and bit offset.
7372 The variable is created if necessary (like <a href="#_append"><strong><code>append</code></strong></a>).
7373 Ihe variable is expanded if necessary.
7374 </p>
7375 </dd>
7376 <dt class="hdlist1">
7377 <code><strong>unpack</strong> <em>binvalue</em> <strong>-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str</strong> <em>bitpos bitwidth</em></code>
7378 </dt>
7379 <dd>
7381 Unpacks bits from <code><em>binvalue</em></code> at bit position <code><em>bitpos</em></code> and with <code><em>bitwidth</em></code>.
7382 Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
7383 and signed/unsigned) and returns it. For integer types, <code><em>bitwidth</em></code>
7384 may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
7385 <code><em>bitwidth</em></code> may be 32 bits (for single precision numbers) or 64 bits (for double precision).
7386 For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
7387 access outside the length of the value will return 0 for integer types, 0.0 for floating point types
7388 or the empty string for the string type.
7389 </p>
7390 </dd>
7391 </dl></div>
7392 </div>
7393 <div class="sect2">
7394 <h3 id="_binary">binary</h3>
7395 <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>
7396 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>
7397 <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>
7398 <div class="paragraph"><p>Note that <em>binary format</em> with f/r/R specifiers (single-precision float) uses the value of Infinity
7399 in case of overflow.</p></div>
7400 </div>
7401 <div class="sect2">
7402 <h3 id="cmd_4">oo: class, super</h3>
7403 <div class="paragraph"><p>The optional, pure-Tcl <em>oo</em> extension provides object-oriented (OO) support for Jim Tcl.</p></div>
7404 <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>
7405 <div class="dlist"><dl>
7406 <dt class="hdlist1">
7407 <code><strong>class</strong> <em>classname ?baseclasses? classvars</em></code>
7408 </dt>
7409 <dd>
7411 Create a new class, <code><em>classname</em></code>, with the given dictionary
7412 (<code><em>classvars</em></code>) as class variables. These are the initial variables
7413 which all newly created objects of this class are initialised with.
7414 If a list of baseclasses is given, methods and instance variables
7415 are inherited.
7416 </p>
7417 </dd>
7418 <dt class="hdlist1">
7419 <code><strong>super</strong> <em>method ?args ...?</em></code>
7420 </dt>
7421 <dd>
7423 From within a method, invokes the given method on the base class.
7424 Note that this will only call the last baseclass given.
7425 </p>
7426 </dd>
7427 </dl></div>
7428 </div>
7429 <div class="sect2">
7430 <h3 id="_tree">tree</h3>
7431 <div class="paragraph"><p>The optional, pure-Tcl <em>tree</em> extension implements an OO, general purpose tree structure
7432 similar to that provided by tcllib ::struct::tree (<a href="http://tcllib.sourceforge.net/doc/struct_tree.html">http://tcllib.sourceforge.net/doc/struct_tree.html</a>)</p></div>
7433 <div class="paragraph"><p>A tree is a collection of nodes, where each node (except the root node) has a single parent
7434 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.</p></div>
7435 <div class="dlist"><dl>
7436 <dt class="hdlist1">
7437 <code><strong>tree</strong></code>
7438 </dt>
7439 <dd>
7441 Creates and returns a new tree object with a single node named "root".
7442 All operations on the tree are invoked through this object.
7443 </p>
7444 </dd>
7445 <dt class="hdlist1">
7446 <code>$tree <strong>destroy</strong></code>
7447 </dt>
7448 <dd>
7450 Destroy the tree and all it&#8217;s nodes. (Note that the the tree will also
7451 be automatically garbage collected once it goes out of scope).
7452 </p>
7453 </dd>
7454 <dt class="hdlist1">
7455 <code>$tree <strong>set</strong> <em>nodename key value</em></code>
7456 </dt>
7457 <dd>
7459 Set the value for the given attribute key.
7460 </p>
7461 </dd>
7462 <dt class="hdlist1">
7463 <code>$tree <strong>lappend</strong> <em>nodename key value ...</em></code>
7464 </dt>
7465 <dd>
7467 Append to the (list) value(s) for the given attribute key, or set if not yet set.
7468 </p>
7469 </dd>
7470 <dt class="hdlist1">
7471 <code>$tree <strong>keyexists</strong> <em>nodename key</em></code>
7472 </dt>
7473 <dd>
7475 Returns 1 if the given attribute key exists.
7476 </p>
7477 </dd>
7478 <dt class="hdlist1">
7479 <code>$tree <strong>get</strong> <em>nodename key</em></code>
7480 </dt>
7481 <dd>
7483 Returns the value associated with the given attribute key.
7484 </p>
7485 </dd>
7486 <dt class="hdlist1">
7487 <code>$tree <strong>getall</strong> <em>nodename</em></code>
7488 </dt>
7489 <dd>
7491 Returns the entire attribute dictionary associated with the given key.
7492 </p>
7493 </dd>
7494 <dt class="hdlist1">
7495 <code>$tree <strong>depth</strong> <em>nodename</em></code>
7496 </dt>
7497 <dd>
7499 Returns the depth of the given node. The depth of "root" is 0.
7500 </p>
7501 </dd>
7502 <dt class="hdlist1">
7503 <code>$tree <strong>parent</strong> <em>nodename</em></code>
7504 </dt>
7505 <dd>
7507 Returns the node name of the parent node, or "" for the root node.
7508 </p>
7509 </dd>
7510 <dt class="hdlist1">
7511 <code>$tree <strong>numchildren</strong> <em>nodename</em></code>
7512 </dt>
7513 <dd>
7515 Returns the number of child nodes.
7516 </p>
7517 </dd>
7518 <dt class="hdlist1">
7519 <code>$tree <strong>children</strong> <em>nodename</em></code>
7520 </dt>
7521 <dd>
7523 Returns a list of the child nodes.
7524 </p>
7525 </dd>
7526 <dt class="hdlist1">
7527 <code>$tree <strong>next</strong> <em>nodename</em></code>
7528 </dt>
7529 <dd>
7531 Returns the next sibling node, or "" if none.
7532 </p>
7533 </dd>
7534 <dt class="hdlist1">
7535 <code>$tree <strong>insert</strong> <em>nodename ?index?</em></code>
7536 </dt>
7537 <dd>
7539 Add a new child node to the given node. The index is a list index
7540 such as <code>3</code> or <code>end-2</code>. The default index is <code>end</code>.
7541 Returns the name of the newly added node.
7542 </p>
7543 </dd>
7544 <dt class="hdlist1">
7545 <code>$tree <strong>walk</strong> <em>nodename</em> <strong>dfs|bfs</strong> {<em>actionvar nodevar</em>} <em>script</em></code>
7546 </dt>
7547 <dd>
7549 Walks the tree starting from the given node, either breadth first (<code>bfs</code>)
7550 depth first (<code>dfs</code>).
7551 The value <code>"enter"</code> or <code>"exit"</code> is stored in variable <code><em>actionvar</em></code>.
7552 The name of each node is stored in <code><em>nodevar</em></code>.
7553 The script is evaluated twice for each node, on entry and exit.
7554 </p>
7555 </dd>
7556 <dt class="hdlist1">
7557 <code>$tree <strong>dump</strong></code>
7558 </dt>
7559 <dd>
7561 Dumps the tree contents to stdout
7562 </p>
7563 </dd>
7564 </dl></div>
7565 </div>
7566 <div class="sect2">
7567 <h3 id="_tcl_prefix">tcl::prefix</h3>
7568 <div class="paragraph"><p>The optional tclprefix extension provides the Tcl8.6-compatible <em>tcl::prefix</em> command
7569 (<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
7570 of possible values (typically commands or options).</p></div>
7571 <div class="dlist"><dl>
7572 <dt class="hdlist1">
7573 <code><strong>tcl::prefix all</strong> <em>table string</em></code>
7574 </dt>
7575 <dd>
7577 Returns a list of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7578 </p>
7579 </dd>
7580 <dt class="hdlist1">
7581 <code><strong>tcl::prefix longest</strong> <em>table string</em></code>
7582 </dt>
7583 <dd>
7585 Returns the longest common prefix of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7586 </p>
7587 </dd>
7588 <dt class="hdlist1">
7589 <code><strong>tcl::prefix match</strong> <em>?options? table string</em></code>
7590 </dt>
7591 <dd>
7593 If <code><em>string</em></code> equals one element in <code><em>table</em></code> or is a prefix to
7594 exactly one element, the matched element is returned. If not, the
7595 result depends on the <code>-error</code> option.
7596 </p>
7597 <div class="ulist"><ul>
7598 <li>
7600 <code><strong>-exact</strong></code> Accept only exact matches.
7601 </p>
7602 </li>
7603 <li>
7605 <code><strong>-message</strong> <em>string</em></code> Use <code><em>string</em></code> in the error message at a mismatch. Default is "option".
7606 </p>
7607 </li>
7608 <li>
7610 <code><strong>-error</strong> <em>options</em></code> The options are used when no match is found. If <code><em>options</em></code> is
7611 empty, no error is generated and an empty string is returned.
7612 Otherwise the options are used as return options when
7613 generating the error message. The default corresponds to
7614 setting <code>-level 0</code>.
7615 </p>
7616 </li>
7617 </ul></div>
7618 </dd>
7619 </dl></div>
7620 </div>
7621 <div class="sect2">
7622 <h3 id="_history">history</h3>
7623 <div class="paragraph"><p>The optional history extension provides script access to the command line editing
7624 and history support available in <em>jimsh</em>. See <em>examples/jtclsh.tcl</em> for an example.
7625 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
7626 the remaining subcommands do nothing.</p></div>
7627 <div class="dlist"><dl>
7628 <dt class="hdlist1">
7629 <code><strong>history load</strong> <em>filename</em></code>
7630 </dt>
7631 <dd>
7633 Load history from a (text) file. If the file does not exist or is not readable,
7634 it is ignored.
7635 </p>
7636 </dd>
7637 <dt class="hdlist1">
7638 <code><strong>history getline</strong> <em>prompt ?varname?</em></code>
7639 </dt>
7640 <dd>
7642 Displays the given prompt and allows a line to be entered. Similarly to <a href="#_gets"><strong><code>gets</code></strong></a>,
7643 if <code><em>varname</em></code> is given, it receives the line and the length of the line is returned,
7644 or -1 on EOF. If <code><em>varname</em></code> is not given, the line is returned directly.
7645 </p>
7646 </dd>
7647 <dt class="hdlist1">
7648 <code><strong>history add</strong> <em>line</em></code>
7649 </dt>
7650 <dd>
7652 Adds the given line to the history buffer.
7653 </p>
7654 </dd>
7655 <dt class="hdlist1">
7656 <code><strong>history save</strong> <em>filename</em></code>
7657 </dt>
7658 <dd>
7660 Saves the current history buffer to the given file.
7661 </p>
7662 </dd>
7663 <dt class="hdlist1">
7664 <code><strong>history show</strong></code>
7665 </dt>
7666 <dd>
7668 Displays the current history buffer to standard output.
7669 </p>
7670 </dd>
7671 </dl></div>
7672 </div>
7673 <div class="sect2">
7674 <h3 id="_namespace">namespace</h3>
7675 <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>
7676 <div class="dlist"><dl>
7677 <dt class="hdlist1">
7678 <code><strong>namespace code</strong> <em>script</em></code>
7679 </dt>
7680 <dd>
7682 Captures the current namespace context for later execution of
7683 the script <code><em>script</em></code>. It returns a new script in which script has
7684 been wrapped in a <code><strong>namespace inscope</strong></code> command.
7685 </p>
7686 </dd>
7687 <dt class="hdlist1">
7688 <code><strong>namespace current</strong></code>
7689 </dt>
7690 <dd>
7692 Returns the fully-qualified name for the current namespace.
7693 </p>
7694 </dd>
7695 <dt class="hdlist1">
7696 <code><strong>namespace delete</strong> <em>?namespace &#8230;?</em></code>
7697 </dt>
7698 <dd>
7700 Deletes all commands and variables with the given namespace prefixes.
7701 </p>
7702 </dd>
7703 <dt class="hdlist1">
7704 <code><strong>namespace eval</strong> <em>namespace arg ?arg&#8230;?</em></code>
7705 </dt>
7706 <dd>
7708 Activates a namespace called <code><em>namespace</em></code> and evaluates some code in that context.
7709 </p>
7710 </dd>
7711 <dt class="hdlist1">
7712 <code><strong>namespace origin</strong> <em>command</em></code>
7713 </dt>
7714 <dd>
7716 Returns the fully-qualified name of the original command to which the imported command <code><em>command</em></code> refers.
7717 </p>
7718 </dd>
7719 <dt class="hdlist1">
7720 <code><strong>namespace parent</strong> ?namespace?</code>
7721 </dt>
7722 <dd>
7724 Returns the fully-qualified name of the parent namespace for namespace <code><em>namespace</em></code>, if given, otherwise
7725 for the current namespace.
7726 </p>
7727 </dd>
7728 <dt class="hdlist1">
7729 <code><strong>namespace qualifiers</strong> <em>string</em></code>
7730 </dt>
7731 <dd>
7733 Returns any leading namespace qualifiers for <code><em>string</em></code>
7734 </p>
7735 </dd>
7736 <dt class="hdlist1">
7737 <code><strong>namespace tail</strong> <em>string</em></code>
7738 </dt>
7739 <dd>
7741 Returns the simple name at the end of a qualified string.
7742 </p>
7743 </dd>
7744 <dt class="hdlist1">
7745 <code><strong>namespace upvar</strong> <em>namespace ?arg&#8230;?</em></code>
7746 </dt>
7747 <dd>
7749 This command arranges for zero or more local variables in the current procedure to refer to variables in <code><em>namespace</em></code>
7750 </p>
7751 </dd>
7752 <dt class="hdlist1">
7753 <code><strong>namespace which</strong> <em>?-command|-variable? name</em></code>
7754 </dt>
7755 <dd>
7757 Looks up <code><em>name</em></code> as either a command (the default) or variable and returns its fully-qualified name.
7758 </p>
7759 </dd>
7760 </dl></div>
7761 </div>
7762 </div>
7763 </div>
7764 <div class="sect1">
7765 <h2 id="BuiltinVariables">BUILT-IN VARIABLES</h2>
7766 <div class="sectionbody">
7767 <div class="paragraph"><p>The following global variables are created automatically
7768 by the Tcl library.</p></div>
7769 <div class="dlist"><dl>
7770 <dt class="hdlist1">
7771 <code><strong>env</strong></code>
7772 </dt>
7773 <dd>
7775 This variable is set by Jim as an array
7776 whose elements are the environment variables for the process.
7777 Reading an element will return the value of the corresponding
7778 environment variable.
7779 This array is initialised at startup from the <a href="#_env"><strong><code>env</code></strong></a> command.
7780 It may be modified and will affect the environment passed to
7781 commands invoked with <a href="#_exec"><strong><code>exec</code></strong></a>.
7782 </p>
7783 </dd>
7784 <dt class="hdlist1">
7785 <code><strong>platform_tcl</strong></code>
7786 </dt>
7787 <dd>
7789 This variable is set by Jim as an array containing information
7790 about the platform on which Jim was built. Currently this includes
7791 <em>os</em> and <em>platform</em>.
7792 </p>
7793 </dd>
7794 <dt class="hdlist1">
7795 <code><strong>auto_path</strong></code>
7796 </dt>
7797 <dd>
7799 This variable contains a list of paths to search for packages.
7800 It defaults to a location based on where jim is installed
7801 (e.g. <code>/usr/local/lib/jim</code>), but may be changed by <code>jimsh</code>
7802 or the embedding application. Note that <code>jimsh</code> will consider
7803 the environment variable <code>$JIMLIB</code> to be a list of colon-separated
7804 list of paths to add to <code><strong>auto_path</strong></code>.
7805 </p>
7806 </dd>
7807 <dt class="hdlist1">
7808 <code><strong>errorCode</strong></code>
7809 </dt>
7810 <dd>
7812 This variable holds the value of the -errorcode return
7813 option set by the most recent error that occurred in this
7814 interpreter. This list value represents additional information
7815 about the error in a form that is easy to process with
7816 programs. The first element of the list identifies a general
7817 class of errors, and determines the format of the rest of
7818 the list. The following formats for -errorcode return options
7819 are used by the Tcl core; individual applications may define
7820 additional formats. Currently only <a href="#_exec"><strong><code>exec</code></strong></a> sets this variable.
7821 Otherwise it will be <code>NONE</code>.
7822 </p>
7823 </dd>
7824 </dl></div>
7825 <div class="paragraph"><p>The following global variables are set by jimsh.</p></div>
7826 <div class="dlist"><dl>
7827 <dt class="hdlist1">
7828 <code><strong>tcl_interactive</strong></code>
7829 </dt>
7830 <dd>
7832 This variable is set to 1 if jimsh is started in interactive mode
7833 or 0 otherwise.
7834 </p>
7835 </dd>
7836 <dt class="hdlist1">
7837 <code><strong>tcl_platform</strong></code>
7838 </dt>
7839 <dd>
7841 This variable is set by Jim as an array containing information
7842 about the platform upon which Jim was built. The following is an
7843 example of the contents of this array.
7844 </p>
7845 <div class="literalblock">
7846 <div class="content">
7847 <pre><code>tcl_platform(byteOrder) = littleEndian
7848 tcl_platform(os) = Darwin
7849 tcl_platform(platform) = unix
7850 tcl_platform(pointerSize) = 8
7851 tcl_platform(threaded) = 0
7852 tcl_platform(wordSize) = 8
7853 tcl_platform(pathSeparator) = :</code></pre>
7854 </div></div>
7855 </dd>
7856 <dt class="hdlist1">
7857 <code><strong>argv0</strong></code>
7858 </dt>
7859 <dd>
7861 If jimsh is invoked to run a script, this variable contains the name
7862 of the script.
7863 </p>
7864 </dd>
7865 <dt class="hdlist1">
7866 <code><strong>argv</strong></code>
7867 </dt>
7868 <dd>
7870 If jimsh is invoked to run a script, this variable contains a list
7871 of any arguments supplied to the script.
7872 </p>
7873 </dd>
7874 <dt class="hdlist1">
7875 <code><strong>argc</strong></code>
7876 </dt>
7877 <dd>
7879 If jimsh is invoked to run a script, this variable contains the number
7880 of arguments supplied to the script.
7881 </p>
7882 </dd>
7883 <dt class="hdlist1">
7884 <code><strong>jim::argv0</strong></code>
7885 </dt>
7886 <dd>
7888 The value of argv[0] when jimsh was invoked.
7889 </p>
7890 </dd>
7891 </dl></div>
7892 </div>
7893 </div>
7894 <div class="sect1">
7895 <h2 id="_changes_in_previous_releases">CHANGES IN PREVIOUS RELEASES</h2>
7896 <div class="sectionbody">
7897 <div class="sect2">
7898 <h3 id="_in_v0_70">In v0.70</h3>
7899 <div class="olist arabic"><ol class="arabic">
7900 <li>
7902 <code>platform_tcl()</code> settings are now automatically determined
7903 </p>
7904 </li>
7905 <li>
7907 Add aio <code>$handle filename</code>
7908 </p>
7909 </li>
7910 <li>
7912 Add <a href="#_info"><strong><code>info</code></strong></a> <code>channels</code>
7913 </p>
7914 </li>
7915 <li>
7917 The <em>bio</em> extension is gone. Now <a href="#_aio"><strong><code>aio</code></strong></a> supports <em>copyto</em>.
7918 </p>
7919 </li>
7920 <li>
7922 Add <a href="#_exists"><strong><code>exists</code></strong></a> command
7923 </p>
7924 </li>
7925 <li>
7927 Add the pure-Tcl <em>oo</em> extension
7928 </p>
7929 </li>
7930 <li>
7932 The <a href="#_exec"><strong><code>exec</code></strong></a> command now only uses vfork(), not fork()
7933 </p>
7934 </li>
7935 <li>
7937 Unit test framework is less verbose and more Tcl-compatible
7938 </p>
7939 </li>
7940 <li>
7942 Optional UTF-8 support
7943 </p>
7944 </li>
7945 <li>
7947 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
7948 </p>
7949 </li>
7950 <li>
7952 Command line editing in interactive mode, e.g. <em>jimsh</em>
7953 </p>
7954 </li>
7955 </ol></div>
7956 </div>
7957 <div class="sect2">
7958 <h3 id="_in_v0_63">In v0.63</h3>
7959 <div class="olist arabic"><ol class="arabic">
7960 <li>
7962 <a href="#_source"><strong><code>source</code></strong></a> now checks that a script is complete (.i.e. not missing a brace)
7963 </p>
7964 </li>
7965 <li>
7967 <em>info complete</em> now uses the real parser and so is 100% accurate
7968 </p>
7969 </li>
7970 <li>
7972 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>
7973 </p>
7974 </li>
7975 <li>
7977 <a href="#_tailcall"><strong><code>tailcall</code></strong></a> no longer loses stack trace information
7978 </p>
7979 </li>
7980 <li>
7982 Add <a href="#_alias"><strong><code>alias</code></strong></a> and <a href="#_curry"><strong><code>curry</code></strong></a>
7983 </p>
7984 </li>
7985 <li>
7987 <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
7988 </p>
7989 </li>
7990 <li>
7992 <a href="#_local"><strong><code>local</code></strong></a> allows procedures to be deleted automatically at the end of the current procedure
7993 </p>
7994 </li>
7995 <li>
7997 udp sockets are now supported for both clients and servers.
7998 </p>
7999 </li>
8000 <li>
8002 vfork-based exec is now working correctly
8003 </p>
8004 </li>
8005 <li>
8007 Add <em>file tempfile</em>
8008 </p>
8009 </li>
8010 <li>
8012 Add <em>socket pipe</em>
8013 </p>
8014 </li>
8015 <li>
8017 Enhance <em>try &#8230; on &#8230; finally</em> to be more Tcl 8.6 compatible
8018 </p>
8019 </li>
8020 <li>
8022 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>
8023 </p>
8024 </li>
8025 <li>
8027 IPv6 support is now included
8028 </p>
8029 </li>
8030 <li>
8032 Add <em>string is</em>
8033 </p>
8034 </li>
8035 <li>
8037 Event handlers works better if an error occurs. eof handler has been removed.
8038 </p>
8039 </li>
8040 <li>
8042 <a href="#_exec"><strong><code>exec</code></strong></a> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
8043 </p>
8044 </li>
8045 <li>
8047 Command pipelines via open "|&#8230;" are now supported
8048 </p>
8049 </li>
8050 <li>
8052 <a href="#_pid"><strong><code>pid</code></strong></a> can now return pids of a command pipeline
8053 </p>
8054 </li>
8055 <li>
8057 Add <em>info references</em>
8058 </p>
8059 </li>
8060 <li>
8062 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>
8063 </p>
8064 </li>
8065 <li>
8067 <a href="#_exec"><strong><code>exec</code></strong></a> now sets environment based on $::env
8068 </p>
8069 </li>
8070 <li>
8072 Add <em>dict keys</em>
8073 </p>
8074 </li>
8075 <li>
8077 Add support for <em>lsort -index</em>
8078 </p>
8079 </li>
8080 </ol></div>
8081 </div>
8082 <div class="sect2">
8083 <h3 id="_in_v0_62">In v0.62</h3>
8084 <div class="olist arabic"><ol class="arabic">
8085 <li>
8087 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>
8088 </p>
8089 </li>
8090 <li>
8092 Fix <a href="#_exec"><strong><code>exec</code></strong></a> error messages when special token (e.g. <em>&gt;</em>) is the last token
8093 </p>
8094 </li>
8095 <li>
8097 Fix <a href="#_subst"><strong><code>subst</code></strong></a> handling of backslash escapes.
8098 </p>
8099 </li>
8100 <li>
8102 Allow abbreviated options for <a href="#_subst"><strong><code>subst</code></strong></a>
8103 </p>
8104 </li>
8105 <li>
8107 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
8108 </p>
8109 </li>
8110 <li>
8112 Many <a href="#_expr"><strong><code>expr</code></strong></a> bug fixes
8113 </p>
8114 </li>
8115 <li>
8117 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
8118 </p>
8119 </li>
8120 <li>
8122 The variable name argument to <a href="#_regsub"><strong><code>regsub</code></strong></a> is now optional
8123 </p>
8124 </li>
8125 <li>
8127 Add support for <em>unset -nocomplain</em>
8128 </p>
8129 </li>
8130 <li>
8132 Add support for list commands: <a href="#_lassign"><strong><code>lassign</code></strong></a>, <a href="#_lrepeat"><strong><code>lrepeat</code></strong></a>
8133 </p>
8134 </li>
8135 <li>
8137 Fully-functional <a href="#_lsearch"><strong><code>lsearch</code></strong></a> is now implemented
8138 </p>
8139 </li>
8140 <li>
8142 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
8143 </p>
8144 </li>
8145 <li>
8147 Allow <a href="#_catch"><strong><code>catch</code></strong></a> to determine what return codes are caught
8148 </p>
8149 </li>
8150 <li>
8152 Allow <a href="#_incr"><strong><code>incr</code></strong></a> to increment an unset variable by first setting to 0
8153 </p>
8154 </li>
8155 <li>
8157 Allow <em>args</em> and optional arguments to the left or required arguments in <a href="#_proc"><strong><code>proc</code></strong></a>
8158 </p>
8159 </li>
8160 <li>
8162 Add <em>file copy</em>
8163 </p>
8164 </li>
8165 <li>
8167 Add <em>try &#8230; finally</em> command
8168 </p>
8169 </li>
8170 </ol></div>
8171 </div>
8172 </div>
8173 </div>
8174 <div class="sect1">
8175 <h2 id="_licence">LICENCE</h2>
8176 <div class="sectionbody">
8177 <div class="literalblock">
8178 <div class="content">
8179 <pre><code>Copyright 2005 Salvatore Sanfilippo &lt;antirez@invece.org&gt;
8180 Copyright 2005 Clemens Hintze &lt;c.hintze@gmx.net&gt;
8181 Copyright 2005 patthoyts - Pat Thoyts &lt;patthoyts@users.sf.net&gt;
8182 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
8183 Copyright 2008 Andrew Lunn &lt;andrew@lunn.ch&gt;
8184 Copyright 2008 Duane Ellis &lt;openocd@duaneellis.com&gt;
8185 Copyright 2008 Uwe Klein &lt;uklein@klein-messgeraete.de&gt;
8186 Copyright 2009 Steve Bennett &lt;steveb@workware.net.au&gt;</code></pre>
8187 </div></div>
8188 <div class="literalblock">
8189 <div class="content">
8190 <pre><code>Redistribution and use in source and binary forms, with or without
8191 modification, are permitted provided that the following conditions
8192 are met:
8193 1. Redistributions of source code must retain the above copyright
8194 notice, this list of conditions and the following disclaimer.
8195 2. Redistributions in binary form must reproduce the above
8196 copyright notice, this list of conditions and the following
8197 disclaimer in the documentation and/or other materials
8198 provided with the distribution.</code></pre>
8199 </div></div>
8200 <div class="literalblock">
8201 <div class="content">
8202 <pre><code>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
8203 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8204 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
8205 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
8206 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8207 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8208 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8209 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8210 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8211 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8212 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
8213 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</code></pre>
8214 </div></div>
8215 <div class="literalblock">
8216 <div class="content">
8217 <pre><code>The views and conclusions contained in the software and documentation
8218 are those of the authors and should not be interpreted as representing
8219 official policies, either expressed or implied, of the Jim Tcl Project.</code></pre>
8220 </div></div>
8221 </div>
8222 </div>
8223 </div>
8224 <div id="footnotes"><hr /></div>
8225 <div id="footer">
8226 <div id="footer-text">
8227 Last updated 2015-01-31 14:05:26 AEST
8228 </div>
8229 </div>
8230 </body>
8231 </html>