add support for [info source ?filename line?]
[jimtcl.git] / Tcl_shipped.html
blobd1b5829707e064553de83e4559b827eb0c94c2d5
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.75 -
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_74_and_0_75">Changes between 0.74 and 0.75</h3>
882 <div class="olist arabic"><ol class="arabic">
883 <li>
885 <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
886 </p>
887 </li>
888 <li>
890 <a href="#_file"><strong><code>file</code></strong></a> <code>copy</code> <em>-force</em> handles source and target as the same file
891 </p>
892 </li>
893 <li>
895 <a href="#_format"><strong><code>format</code></strong></a> now supports <code>%b</code> for binary conversion
896 </p>
897 </li>
898 <li>
900 <a href="#_lsort"><strong><code>lsort</code></strong></a> now supports <em>-unique</em> and <em>-real</em>
901 </p>
902 </li>
903 <li>
905 Add support for half-close with <a href="#_aio"><strong><code>aio</code></strong></a> <code>close</code> ?r|w?
906 </p>
907 </li>
908 <li>
910 Add <a href="#_socket"><strong><code>socket</code></strong></a> <code>pair</code> for a bidirectional pipe
911 </p>
912 </li>
913 <li>
915 Add <em>--random-hash</em> to randomise hash tables for greater security
916 </p>
917 </li>
918 <li>
920 <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>
921 </p>
922 </li>
923 <li>
925 <a href="#_file"><strong><code>file</code></strong></a> <code>stat</code> no longer requires the variable name
926 </p>
927 </li>
928 <li>
930 Add support for <a href="#_file"><strong><code>file</code></strong></a> <code>link</code>
931 </p>
932 </li>
933 <li>
935 <a href="#_glob"><strong><code>glob</code></strong></a> now supports the <em>--tails</em> option
936 </p>
937 </li>
938 <li>
940 Add support for <a href="#_string"><strong><code>string</code></strong></a> <code>cat</code>
941 </p>
942 </li>
943 <li>
945 Allow <a href="#_info"><strong><code>info</code></strong></a> <code>source</code> to add source info
946 </p>
947 </li>
948 </ol></div>
949 </div>
950 <div class="sect2">
951 <h3 id="_changes_between_0_73_and_0_74">Changes between 0.73 and 0.74</h3>
952 <div class="olist arabic"><ol class="arabic">
953 <li>
955 Numbers with leading zeros are treated as decimal, not octal
956 </p>
957 </li>
958 <li>
960 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>isatty</code>
961 </p>
962 </li>
963 <li>
965 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>
966 </p>
967 </li>
968 <li>
970 <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>
971 </p>
972 </li>
973 <li>
975 <a href="#_glob"><strong><code>glob</code></strong></a> now supports <em>-directory</em>
976 </p>
977 </li>
978 </ol></div>
979 </div>
980 <div class="sect2">
981 <h3 id="_changes_between_0_72_and_0_73">Changes between 0.72 and 0.73</h3>
982 <div class="olist arabic"><ol class="arabic">
983 <li>
985 Built-in regexp now support non-capturing parentheses: (?:&#8230;)
986 </p>
987 </li>
988 <li>
990 Add <a href="#_string"><strong><code>string</code></strong></a> <code>replace</code>
991 </p>
992 </li>
993 <li>
995 Add <a href="#_string"><strong><code>string</code></strong></a> <code>totitle</code>
996 </p>
997 </li>
998 <li>
1000 Add <a href="#_info"><strong><code>info</code></strong></a> <code>statics</code>
1001 </p>
1002 </li>
1003 <li>
1005 Add <code>build-jim-ext</code> for easy separate building of loadable modules (extensions)
1006 </p>
1007 </li>
1008 <li>
1010 <a href="#_local"><strong><code>local</code></strong></a> now works with any command, not just procs
1011 </p>
1012 </li>
1013 <li>
1015 Add <a href="#_info"><strong><code>info</code></strong></a> <code>alias</code> to access the target of an alias
1016 </p>
1017 </li>
1018 <li>
1020 UTF-8 encoding past the basic multilingual plane (BMP) is supported
1021 </p>
1022 </li>
1023 <li>
1025 Add <a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a>
1026 </p>
1027 </li>
1028 <li>
1030 Add <a href="#_history"><strong><code>history</code></strong></a>
1031 </p>
1032 </li>
1033 <li>
1035 Most extensions are now enabled by default
1036 </p>
1037 </li>
1038 <li>
1040 Add support for namespaces and the <a href="#_namespace"><strong><code>namespace</code></strong></a> command
1041 </p>
1042 </li>
1043 <li>
1045 Add <a href="#_apply"><strong><code>apply</code></strong></a>
1046 </p>
1047 </li>
1048 </ol></div>
1049 </div>
1050 <div class="sect2">
1051 <h3 id="_changes_between_0_71_and_0_72">Changes between 0.71 and 0.72</h3>
1052 <div class="olist arabic"><ol class="arabic">
1053 <li>
1055 procs now allow <em>args</em> and optional parameters in any position
1056 </p>
1057 </li>
1058 <li>
1060 Add Tcl-compatible expr functions, <code>rand()</code>, <code>srand()</code> and <code>pow()</code>
1061 </p>
1062 </li>
1063 <li>
1065 Add support for the <em>-force</em> option to <a href="#_file"><strong><code>file</code></strong></a> <code>delete</code>
1066 </p>
1067 </li>
1068 <li>
1070 Better diagnostics when <a href="#_source"><strong><code>source</code></strong></a> fails to load a script with a missing quote or bracket
1071 </p>
1072 </li>
1073 <li>
1075 New <code>tcl_platform(pathSeparator)</code>
1076 </p>
1077 </li>
1078 <li>
1080 Add support settings the modification time with <a href="#_file"><strong><code>file</code></strong></a> <code>mtime</code>
1081 </p>
1082 </li>
1083 <li>
1085 <a href="#_exec"><strong><code>exec</code></strong></a> is now fully supported on win32 (mingw32)
1086 </p>
1087 </li>
1088 <li>
1090 <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
1091 </p>
1092 </li>
1093 <li>
1095 Line editing is now supported for the win32 console (mingw32)
1096 </p>
1097 </li>
1098 <li>
1100 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>listen</code> command
1101 </p>
1102 </li>
1103 </ol></div>
1104 </div>
1105 <div class="sect2">
1106 <h3 id="_changes_between_0_70_and_0_71">Changes between 0.70 and 0.71</h3>
1107 <div class="olist arabic"><ol class="arabic">
1108 <li>
1110 Allow <em>args</em> to be renamed in procs
1111 </p>
1112 </li>
1113 <li>
1115 Add <code>$(&#8230;)</code> shorthand syntax for expressions
1116 </p>
1117 </li>
1118 <li>
1120 Add automatic reference variables in procs with <code>&amp;var</code> syntax
1121 </p>
1122 </li>
1123 <li>
1125 Support <code>jimsh --version</code>
1126 </p>
1127 </li>
1128 <li>
1130 Additional variables in <code>tcl_platform()</code>
1131 </p>
1132 </li>
1133 <li>
1135 <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
1136 </p>
1137 </li>
1138 <li>
1140 Add <a href="#_loop"><strong><code>loop</code></strong></a> command (TclX compatible)
1141 </p>
1142 </li>
1143 <li>
1145 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>buffering</code> command
1146 </p>
1147 </li>
1148 <li>
1150 <a href="#_info"><strong><code>info</code></strong></a> <code>complete</code> can now return the missing character
1151 </p>
1152 </li>
1153 <li>
1155 <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
1156 </p>
1157 </li>
1158 <li>
1160 Add <a href="#_string"><strong><code>string</code></strong></a> <code>byterange</code>
1161 </p>
1162 </li>
1163 <li>
1165 Built-in regexp now support non-greedy repetition (*?, +?, ??)
1166 </p>
1167 </li>
1168 </ol></div>
1169 </div>
1170 </div>
1171 </div>
1172 <div class="sect1">
1173 <h2 id="_tcl_introduction">TCL INTRODUCTION</h2>
1174 <div class="sectionbody">
1175 <div class="paragraph"><p>Tcl stands for <em>tool command language</em> and is pronounced <em>tickle.</em>
1176 It is actually two things: a language and a library.</p></div>
1177 <div class="paragraph"><p>First, Tcl is a simple textual language, intended primarily for
1178 issuing commands to interactive programs such as text editors,
1179 debuggers, illustrators, and shells. It has a simple syntax and is also
1180 programmable, so Tcl users can write command procedures to provide more
1181 powerful commands than those in the built-in set.</p></div>
1182 <div class="paragraph"><p>Second, Tcl is a library package that can be embedded in application
1183 programs. The Tcl library consists of a parser for the Tcl language,
1184 routines to implement the Tcl built-in commands, and procedures that
1185 allow each application to extend Tcl with additional commands specific
1186 to that application. The application program generates Tcl commands and
1187 passes them to the Tcl parser for execution. Commands may be generated
1188 by reading characters from an input source, or by associating command
1189 strings with elements of the application&#8217;s user interface, such as menu
1190 entries, buttons, or keystrokes.</p></div>
1191 <div class="paragraph"><p>When the Tcl library receives commands it parses them into component
1192 fields and executes built-in commands directly. For commands implemented
1193 by the application, Tcl calls back to the application to execute the
1194 commands. In many cases commands will invoke recursive invocations of the
1195 Tcl interpreter by passing in additional strings to execute (procedures,
1196 looping commands, and conditional commands all work in this way).</p></div>
1197 <div class="paragraph"><p>An application program gains three advantages by using Tcl for its command
1198 language. First, Tcl provides a standard syntax: once users know Tcl,
1199 they will be able to issue commands easily to any Tcl-based application.
1200 Second, Tcl provides programmability. All a Tcl application needs
1201 to do is to implement a few application-specific low-level commands.
1202 Tcl provides many utility commands plus a general programming interface
1203 for building up complex command procedures. By using Tcl, applications
1204 need not re-implement these features.</p></div>
1205 <div class="paragraph"><p>Third, Tcl can be used as a common language for communicating between
1206 applications. Inter-application communication is not built into the
1207 Tcl core described here, but various add-on libraries, such as the Tk
1208 toolkit, allow applications to issue commands to each other. This makes
1209 it possible for applications to work together in much more powerful ways
1210 than was previously possible.</p></div>
1211 <div class="paragraph"><p>Fourth, Jim Tcl includes a command processor, <code>jimsh</code>, which can be
1212 used to run standalone Tcl scripts, or to run Tcl commands interactively.</p></div>
1213 <div class="paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
1214 the language syntax and the built-in commands that will be available
1215 in any application based on Tcl. The individual library procedures are
1216 described in more detail in separate manual pages, one per procedure.</p></div>
1217 </div>
1218 </div>
1219 <div class="sect1">
1220 <h2 id="_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER</h2>
1221 <div class="sectionbody">
1222 <div class="paragraph"><p>A simple, but powerful command processor, <code>jimsh</code>, is part of Jim Tcl.
1223 It may be invoked in interactive mode as:</p></div>
1224 <div class="literalblock">
1225 <div class="content">
1226 <pre><code>jimsh</code></pre>
1227 </div></div>
1228 <div class="paragraph"><p>or to process the Tcl script in a file with:</p></div>
1229 <div class="literalblock">
1230 <div class="content">
1231 <pre><code>jimsh filename</code></pre>
1232 </div></div>
1233 <div class="paragraph"><p>It may also be invoked to execute an immediate script with:</p></div>
1234 <div class="literalblock">
1235 <div class="content">
1236 <pre><code>jimsh -e "script"</code></pre>
1237 </div></div>
1238 <div class="sect2">
1239 <h3 id="_interactive_mode">Interactive Mode</h3>
1240 <div class="paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
1241 those commands and prints the results.</p></div>
1242 <div class="literalblock">
1243 <div class="content">
1244 <pre><code>$ jimsh
1245 Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
1246 . info version
1247 0.73
1248 . lsort [info commands p*]
1249 package parray pid popen proc puts pwd
1250 . foreach i {a b c} {
1251 {&gt; puts $i
1252 {&gt; }
1256 . bad
1257 invalid command name "bad"
1258 [error] . exit
1259 $</code></pre>
1260 </div></div>
1261 <div class="paragraph"><p>If <code>jimsh</code> is configured with line editing (it is by default) and a VT-100-compatible
1262 terminal is detected, Emacs-style line editing commands are available, including:
1263 arrow keys, <code>^W</code> to erase a word, <code>^U</code> to erase the line, <code>^R</code> for reverse incremental search
1264 in history. Additionally, the <code>h</code> command may be used to display the command history.</p></div>
1265 <div class="paragraph"><p>Command line history is automatically saved and loaded from <code>~/.jim_history</code></p></div>
1266 <div class="paragraph"><p>In interactive mode, <code>jimsh</code> automatically runs the script <code>~/.jimrc</code> at startup
1267 if it exists.</p></div>
1268 </div>
1269 </div>
1270 </div>
1271 <div class="sect1">
1272 <h2 id="_interpreters">INTERPRETERS</h2>
1273 <div class="sectionbody">
1274 <div class="paragraph"><p>The central data structure in Tcl is an interpreter (C type <em>Jim_Interp</em>).
1275 An interpreter consists of a set of command bindings, a set of variable
1276 values, and a few other miscellaneous pieces of state. Each Tcl command
1277 is interpreted in the context of a particular interpreter.</p></div>
1278 <div class="paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
1279 simultaneously, each associated with a different widget or portion of
1280 the application. Interpreters are relatively lightweight structures.
1281 They can be created and deleted quickly, so application programmers should
1282 feel free to use multiple interpreters if that simplifies the application.</p></div>
1283 </div>
1284 </div>
1285 <div class="sect1">
1286 <h2 id="_data_types">DATA TYPES</h2>
1287 <div class="sectionbody">
1288 <div class="paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
1289 to commands, all command results, and all variable values are strings.</p></div>
1290 <div class="paragraph"><p>Where commands require numeric arguments or return numeric results,
1291 the arguments and results are passed as strings. Many commands expect
1292 their string arguments to have certain formats, but this interpretation
1293 is up to the individual commands. For example, arguments often contain
1294 Tcl command strings, which may get executed as part of the commands.
1295 The easiest way to understand the Tcl interpreter is to remember that
1296 everything is just an operation on a string. In many cases Tcl constructs
1297 will look similar to more structured constructs from other languages.
1298 However, the Tcl constructs are not structured at all; they are just
1299 strings of characters, and this gives them a different behaviour than
1300 the structures they may look like.</p></div>
1301 <div class="paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
1302 the interpretation, there are three common forms that strings take:
1303 commands, expressions, and lists. The major sections below discuss
1304 these three forms in more detail.</p></div>
1305 </div>
1306 </div>
1307 <div class="sect1">
1308 <h2 id="_basic_command_syntax">BASIC COMMAND SYNTAX</h2>
1309 <div class="sectionbody">
1310 <div class="paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
1311 and Lisp. However, the interpretation of commands is different
1312 in Tcl than in either of those other two systems.
1313 A Tcl command string consists of one or more commands separated
1314 by newline characters or semi-colons.
1315 Each command consists of a collection of fields separated by
1316 white space (spaces or tabs).
1317 The first field must be the name of a command, and the
1318 additional fields, if any, are arguments that will be passed to
1319 that command. For example, the command:</p></div>
1320 <div class="literalblock">
1321 <div class="content">
1322 <pre><code>set a 22</code></pre>
1323 </div></div>
1324 <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
1325 the last two, <em>a</em> and <em>22</em>, will be passed as arguments to
1326 the <a href="#_set"><strong><code>set</code></strong></a> command. The command name may refer either to a built-in
1327 Tcl command, an application-specific command bound in with the library
1328 procedure <em>Jim_CreateCommand</em>, or a command procedure defined with the
1329 <a href="#_proc"><strong><code>proc</code></strong></a> built-in command.</p></div>
1330 <div class="paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1331 interpret those strings in any fashion they wish. The <a href="#_set"><strong><code>set</code></strong></a> command,
1332 for example, will treat its first argument as the name of a variable
1333 and its second argument as a string value to assign to that variable.
1334 For other commands arguments may be interpreted as integers, lists,
1335 file names, or Tcl commands.</p></div>
1336 <div class="paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1337 However, if the Tcl interpreter cannot locate a command it invokes a
1338 special command named <a href="#_unknown"><strong><code>unknown</code></strong></a> which attempts to find or create the
1339 command.</p></div>
1340 <div class="paragraph"><p>For example, at many sites <a href="#_unknown"><strong><code>unknown</code></strong></a> will search through library
1341 directories for the desired command and create it as a Tcl procedure if
1342 it is found. The <a href="#_unknown"><strong><code>unknown</code></strong></a> command often provides automatic completion
1343 of abbreviated commands, but usually only for commands that were typed
1344 interactively.</p></div>
1345 <div class="paragraph"><p>It&#8217;s probably a bad idea to use abbreviations in command scripts and
1346 other forms that will be re-used over time: changes to the command set
1347 may cause abbreviations to become ambiguous, resulting in scripts that
1348 no longer work.</p></div>
1349 </div>
1350 </div>
1351 <div class="sect1">
1352 <h2 id="_comments">COMMENTS</h2>
1353 <div class="sectionbody">
1354 <div class="paragraph"><p>If the first non-blank character in a command is <code>#</code>, then everything
1355 from the <code>#</code> up through the next newline character is treated as
1356 a comment and ignored. When comments are embedded inside nested
1357 commands (e.g. fields enclosed in braces) they must have properly-matched
1358 braces (this is necessary because when Tcl parses the top-level command
1359 it doesn&#8217;t yet know that the nested field will be used as a command so
1360 it cannot process the nested comment character as a comment).</p></div>
1361 </div>
1362 </div>
1363 <div class="sect1">
1364 <h2 id="_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES</h2>
1365 <div class="sectionbody">
1366 <div class="paragraph"><p>Normally each argument field ends at the next white space, but
1367 double-quotes may be used to create arguments with embedded space.</p></div>
1368 <div class="paragraph"><p>If an argument field begins with a double-quote, then the argument isn&#8217;t
1369 terminated by white space (including newlines) or a semi-colon (see below
1370 for information on semi-colons); instead it ends at the next double-quote
1371 character. The double-quotes are not included in the resulting argument.
1372 For example, the command</p></div>
1373 <div class="literalblock">
1374 <div class="content">
1375 <pre><code>set a "This is a single argument"</code></pre>
1376 </div></div>
1377 <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>
1378 <div class="paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1379 and backslash substitutions still occur, as described below. If the
1380 first character of a command field is not a quote, then quotes receive
1381 no special interpretation in the parsing of that field.</p></div>
1382 </div>
1383 </div>
1384 <div class="sect1">
1385 <h2 id="_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES</h2>
1386 <div class="sectionbody">
1387 <div class="paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1388 to quotes except for two differences. First, they nest; this makes them
1389 easier to use for complicated arguments like nested Tcl command strings.
1390 Second, the substitutions described below for commands, variables, and
1391 backslashes do <strong>not</strong> occur in arguments enclosed in braces, so braces
1392 can be used to prevent substitutions where they are undesirable.</p></div>
1393 <div class="paragraph"><p>If an argument field begins with a left brace, then the argument ends
1394 at the matching right brace. Tcl will strip off the outermost layer
1395 of braces and pass the information between the braces to the command
1396 without any further modification. For example, in the command</p></div>
1397 <div class="literalblock">
1398 <div class="content">
1399 <pre><code>set a {xyz a {b c d}}</code></pre>
1400 </div></div>
1401 <div class="paragraph"><p>the <a href="#_set"><strong><code>set</code></strong></a> command will receive two arguments: <em>a</em>
1402 and <em>xyz a {b c d}</em>.</p></div>
1403 <div class="paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1404 not be on the same line as the starting quote or brace; in this case
1405 the newline will be included in the argument field along with any other
1406 characters up to the matching brace or quote. For example, the <a href="#_eval"><strong><code>eval</code></strong></a>
1407 command takes one argument, which is a command string; <a href="#_eval"><strong><code>eval</code></strong></a> invokes
1408 the Tcl interpreter to execute the command string. The command</p></div>
1409 <div class="literalblock">
1410 <div class="content">
1411 <pre><code>eval {
1412 set a 22
1413 set b 33
1414 }</code></pre>
1415 </div></div>
1416 <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>
1417 <div class="paragraph"><p>If the first character of a command field is not a left
1418 brace, then neither left nor right
1419 braces in the field will be treated specially (except as part of
1420 variable substitution; see below).</p></div>
1421 </div>
1422 </div>
1423 <div class="sect1">
1424 <h2 id="_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS</h2>
1425 <div class="sectionbody">
1426 <div class="paragraph"><p>If an open bracket occurs in a field of a command, then command
1427 substitution occurs (except for fields enclosed in braces). All of the
1428 text up to the matching close bracket is treated as a Tcl command and
1429 executed immediately. Then the result of that command is substituted
1430 for the bracketed text. For example, consider the command</p></div>
1431 <div class="literalblock">
1432 <div class="content">
1433 <pre><code>set a [set b]</code></pre>
1434 </div></div>
1435 <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
1436 variable and <a href="#_set"><strong><code>set</code></strong></a> returns the contents of that variable. In this case,
1437 if variable <em>b</em> has the value <em>foo</em>, then the command above is equivalent
1438 to the command</p></div>
1439 <div class="literalblock">
1440 <div class="content">
1441 <pre><code>set a foo</code></pre>
1442 </div></div>
1443 <div class="paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1444 <em>b</em> has the value <em>foo</em> and the variable <em>c</em> has the value <em>gorp</em>,
1445 then the command</p></div>
1446 <div class="literalblock">
1447 <div class="content">
1448 <pre><code>set a xyz[set b].[set c]</code></pre>
1449 </div></div>
1450 <div class="paragraph"><p>is equivalent to the command</p></div>
1451 <div class="literalblock">
1452 <div class="content">
1453 <pre><code>set a xyzfoo.gorp</code></pre>
1454 </div></div>
1455 <div class="paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1456 or semi-colons in the usual fashion. In this case the value of the last
1457 command is used for substitution. For example, the command</p></div>
1458 <div class="literalblock">
1459 <div class="content">
1460 <pre><code>set a x[set b 22
1461 expr $b+2]x</code></pre>
1462 </div></div>
1463 <div class="paragraph"><p>is equivalent to the command</p></div>
1464 <div class="literalblock">
1465 <div class="content">
1466 <pre><code>set a x24x</code></pre>
1467 </div></div>
1468 <div class="paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1469 between them are not interpreted specially; they are passed through to
1470 the argument verbatim.</p></div>
1471 </div>
1472 </div>
1473 <div class="sect1">
1474 <h2 id="_variable_substitution_with">VARIABLE SUBSTITUTION WITH $</h2>
1475 <div class="sectionbody">
1476 <div class="paragraph"><p>The dollar sign (<code>$</code>) may be used as a special shorthand form for
1477 substituting variable values. If <code>$</code> appears in an argument that isn&#8217;t
1478 enclosed in braces then variable substitution will occur. The characters
1479 after the <code>$</code>, up to the first character that isn&#8217;t a number, letter,
1480 or underscore, are taken as a variable name and the string value of that
1481 variable is substituted for the name.</p></div>
1482 <div class="paragraph"><p>For example, if variable <em>foo</em> has the value <em>test</em>, then the command</p></div>
1483 <div class="literalblock">
1484 <div class="content">
1485 <pre><code>set a $foo.c</code></pre>
1486 </div></div>
1487 <div class="paragraph"><p>is equivalent to the command</p></div>
1488 <div class="literalblock">
1489 <div class="content">
1490 <pre><code>set a test.c</code></pre>
1491 </div></div>
1492 <div class="paragraph"><p>There are two special forms for variable substitution. If the next
1493 character after the name of the variable is an open parenthesis, then
1494 the variable is assumed to be an array name, and all of the characters
1495 between the open parenthesis and the next close parenthesis are taken as
1496 an index into the array. Command substitutions and variable substitutions
1497 are performed on the information between the parentheses before it is
1498 used as an index.</p></div>
1499 <div class="paragraph"><p>For example, if the variable <em>x</em> is an array with one element named
1500 <em>first</em> and value <em>87</em> and another element named <em>14</em> and value <em>more</em>,
1501 then the command</p></div>
1502 <div class="literalblock">
1503 <div class="content">
1504 <pre><code>set a xyz$x(first)zyx</code></pre>
1505 </div></div>
1506 <div class="paragraph"><p>is equivalent to the command</p></div>
1507 <div class="literalblock">
1508 <div class="content">
1509 <pre><code>set a xyz87zyx</code></pre>
1510 </div></div>
1511 <div class="paragraph"><p>If the variable <em>index</em> has the value <em>14</em>, then the command</p></div>
1512 <div class="literalblock">
1513 <div class="content">
1514 <pre><code>set a xyz$x($index)zyx</code></pre>
1515 </div></div>
1516 <div class="paragraph"><p>is equivalent to the command</p></div>
1517 <div class="literalblock">
1518 <div class="content">
1519 <pre><code>set a xyzmorezyx</code></pre>
1520 </div></div>
1521 <div class="paragraph"><p>For more information on arrays, see VARIABLES AND ARRAYS below.</p></div>
1522 <div class="paragraph"><p>The second special form for variables occurs when the dollar sign is
1523 followed by an open curly brace. In this case the variable name consists
1524 of all the characters up to the next curly brace.</p></div>
1525 <div class="paragraph"><p>Array references are not possible in this form: the name between braces
1526 is assumed to refer to a scalar variable. For example, if variable
1527 <em>foo</em> has the value <em>test</em>, then the command</p></div>
1528 <div class="literalblock">
1529 <div class="content">
1530 <pre><code>set a abc${foo}bar</code></pre>
1531 </div></div>
1532 <div class="paragraph"><p>is equivalent to the command</p></div>
1533 <div class="literalblock">
1534 <div class="content">
1535 <pre><code>set a abctestbar</code></pre>
1536 </div></div>
1537 <div class="paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1538 braces: the dollar sign and variable name are passed through to the
1539 argument verbatim.</p></div>
1540 <div class="paragraph"><p>The dollar sign abbreviation is simply a shorthand form. <code>$a</code> is
1541 completely equivalent to <code>[set a]</code>; it is provided as a convenience
1542 to reduce typing.</p></div>
1543 </div>
1544 </div>
1545 <div class="sect1">
1546 <h2 id="_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS</h2>
1547 <div class="sectionbody">
1548 <div class="paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1549 newline character). However, semi-colon (<code>;</code>) is treated as a command
1550 separator character; multiple commands may be placed on one line by
1551 separating them with a semi-colon. Semi-colons are not treated as
1552 command separators if they appear within curly braces or double-quotes.</p></div>
1553 </div>
1554 </div>
1555 <div class="sect1">
1556 <h2 id="_backslash_substitution">BACKSLASH SUBSTITUTION</h2>
1557 <div class="sectionbody">
1558 <div class="paragraph"><p>Backslashes may be used to insert non-printing characters into command
1559 fields and also to insert special characters like braces and brackets
1560 into fields without them being interpreted specially as described above.</p></div>
1561 <div class="paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1562 listed below. In each case, the backslash
1563 sequence is replaced by the given character:</p></div>
1564 <div class="dlist" id="BackslashSequences"><dl>
1565 <dt class="hdlist1">
1566 <code>\b</code>
1567 </dt>
1568 <dd>
1570 Backspace (0x8)
1571 </p>
1572 </dd>
1573 <dt class="hdlist1">
1574 <code>\f</code>
1575 </dt>
1576 <dd>
1578 Form feed (0xc)
1579 </p>
1580 </dd>
1581 <dt class="hdlist1">
1582 <code>\n</code>
1583 </dt>
1584 <dd>
1586 Newline (0xa)
1587 </p>
1588 </dd>
1589 <dt class="hdlist1">
1590 <code>\r</code>
1591 </dt>
1592 <dd>
1594 Carriage-return (0xd).
1595 </p>
1596 </dd>
1597 <dt class="hdlist1">
1598 <code>\t</code>
1599 </dt>
1600 <dd>
1602 Tab (0x9).
1603 </p>
1604 </dd>
1605 <dt class="hdlist1">
1606 <code>\v</code>
1607 </dt>
1608 <dd>
1610 Vertical tab (0xb).
1611 </p>
1612 </dd>
1613 <dt class="hdlist1">
1614 <code>\{</code>
1615 </dt>
1616 <dd>
1618 Left brace ({).
1619 </p>
1620 </dd>
1621 <dt class="hdlist1">
1622 <code>\}</code>
1623 </dt>
1624 <dd>
1626 Right brace (}).
1627 </p>
1628 </dd>
1629 <dt class="hdlist1">
1630 <code>\[</code>
1631 </dt>
1632 <dd>
1634 Open bracket ([).
1635 </p>
1636 </dd>
1637 <dt class="hdlist1">
1638 <code>\]</code>
1639 </dt>
1640 <dd>
1642 Close bracket (]).
1643 </p>
1644 </dd>
1645 <dt class="hdlist1">
1646 <code>\$</code>
1647 </dt>
1648 <dd>
1650 Dollar sign ($).
1651 </p>
1652 </dd>
1653 <dt class="hdlist1">
1654 <code>\&lt;space&gt;</code>
1655 </dt>
1656 <dd>
1658 Space ( ): doesn&#8217;t terminate argument.
1659 </p>
1660 </dd>
1661 <dt class="hdlist1">
1662 <code>\;</code>
1663 </dt>
1664 <dd>
1666 Semi-colon: doesn&#8217;t terminate command.
1667 </p>
1668 </dd>
1669 <dt class="hdlist1">
1670 <code>\"</code>
1671 </dt>
1672 <dd>
1674 Double-quote.
1675 </p>
1676 </dd>
1677 <dt class="hdlist1">
1678 <code>\&lt;newline&gt;</code>
1679 </dt>
1680 <dd>
1682 Nothing: this joins two lines together
1683 into a single line. This backslash feature is unique in that
1684 it will be applied even when the sequence occurs within braces.
1685 </p>
1686 </dd>
1687 <dt class="hdlist1">
1688 <code>\\</code>
1689 </dt>
1690 <dd>
1692 Backslash (<em>\</em>).
1693 </p>
1694 </dd>
1695 <dt class="hdlist1">
1696 <code>\ddd</code>
1697 </dt>
1698 <dd>
1700 The digits <code><em>ddd</em></code> (one, two, or three of them) give the octal value of
1701 the character. Note that Jim supports null characters in strings.
1702 </p>
1703 </dd>
1704 <dt class="hdlist1">
1705 <code>\unnnn</code>
1706 </dt>
1707 <dt class="hdlist1">
1708 <code>\u{nnn}</code>
1709 </dt>
1710 <dt class="hdlist1">
1711 <code>\Unnnnnnnn</code>
1712 </dt>
1713 <dd>
1715 The UTF-8 encoding of the unicode codepoint represented by the hex digits, <code><em>nnnn</em></code>, is inserted.
1716 The <em>u</em> form allows for one to four hex digits.
1717 The <em>U</em> form allows for one to eight hex digits.
1718 The <em>u{nnn}</em> form allows for one to eight hex digits, but makes it easier to insert
1719 characters UTF-8 characters which are followed by a hex digit.
1720 </p>
1721 </dd>
1722 </dl></div>
1723 <div class="paragraph"><p>For example, in the command</p></div>
1724 <div class="literalblock">
1725 <div class="content">
1726 <pre><code>set a \{x\[\ yz\141</code></pre>
1727 </div></div>
1728 <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>
1729 <div class="paragraph"><p>If a backslash is followed by something other than one of the options
1730 described above, then the backslash is transmitted to the argument
1731 field without any special processing, and the Tcl scanner continues
1732 normal processing with the next character. For example, in the
1733 command</p></div>
1734 <div class="literalblock">
1735 <div class="content">
1736 <pre><code>set \*a \\\{foo</code></pre>
1737 </div></div>
1738 <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
1739 argument will be <code>\{foo</code>.</p></div>
1740 <div class="paragraph"><p>If an argument is enclosed in braces, then backslash sequences inside
1741 the argument are parsed but no substitution occurs (except for
1742 backslash-newline): the backslash
1743 sequence is passed through to the argument as is, without making
1744 any special interpretation of the characters in the backslash sequence.
1745 In particular, backslashed braces are not counted in locating the
1746 matching right brace that terminates the argument.
1747 For example, in the
1748 command</p></div>
1749 <div class="literalblock">
1750 <div class="content">
1751 <pre><code>set a {\{abc}</code></pre>
1752 </div></div>
1753 <div class="paragraph"><p>the second argument to <a href="#_set"><strong><code>set</code></strong></a> will be <code>\{abc</code>.</p></div>
1754 <div class="paragraph"><p>This backslash mechanism is not sufficient to generate absolutely
1755 any argument structure; it only covers the
1756 most common cases. To produce particularly complicated arguments
1757 it is probably easiest to use the <a href="#_format"><strong><code>format</code></strong></a> command along with
1758 command substitution.</p></div>
1759 </div>
1760 </div>
1761 <div class="sect1">
1762 <h2 id="_string_and_list_index_specifications">STRING AND LIST INDEX SPECIFICATIONS</h2>
1763 <div class="sectionbody">
1764 <div class="paragraph"><p>Many string and list commands take one or more <em>index</em> parameters which
1765 specify a position in the string relative to the start or end of the string/list.</p></div>
1766 <div class="paragraph"><p>The index may be one of the following forms:</p></div>
1767 <div class="dlist"><dl>
1768 <dt class="hdlist1">
1769 <code>integer</code>
1770 </dt>
1771 <dd>
1773 A simple integer, where <em>0</em> refers to the first element of the string
1774 or list.
1775 </p>
1776 </dd>
1777 <dt class="hdlist1">
1778 <code>integer+integer</code> or
1779 </dt>
1780 <dt class="hdlist1">
1781 <code>integer-integer</code>
1782 </dt>
1783 <dd>
1785 The sum or difference of the two integers. e.g. <code>2+3</code> refers to the 5th element.
1786 This is useful when used with (e.g.) <code>$i+1</code> rather than the more verbose
1787 <code>[expr {$i+1}]</code>
1788 </p>
1789 </dd>
1790 <dt class="hdlist1">
1791 <code>end</code>
1792 </dt>
1793 <dd>
1795 The last element of the string or list.
1796 </p>
1797 </dd>
1798 <dt class="hdlist1">
1799 <code>end-integer</code>
1800 </dt>
1801 <dd>
1803 The <em>nth-from-last</em> element of the string or list.
1804 </p>
1805 </dd>
1806 </dl></div>
1807 </div>
1808 </div>
1809 <div class="sect1">
1810 <h2 id="_command_summary">COMMAND SUMMARY</h2>
1811 <div class="sectionbody">
1812 <div class="olist arabic"><ol class="arabic">
1813 <li>
1815 A command is just a string.
1816 </p>
1817 </li>
1818 <li>
1820 Within a string commands are separated by newlines or semi-colons
1821 (unless the newline or semi-colon is within braces or brackets
1822 or is backslashed).
1823 </p>
1824 </li>
1825 <li>
1827 A command consists of fields. The first field is the name of the command.
1828 The other fields are strings that are passed to that command as arguments.
1829 </p>
1830 </li>
1831 <li>
1833 Fields are normally separated by white space.
1834 </p>
1835 </li>
1836 <li>
1838 Double-quotes allow white space and semi-colons to appear within
1839 a single argument.
1840 Command substitution, variable substitution, and backslash substitution
1841 still occur inside quotes.
1842 </p>
1843 </li>
1844 <li>
1846 Braces defer interpretation of special characters.
1847 If a field begins with a left brace, then it consists of everything
1848 between the left brace and the matching right brace. The
1849 braces themselves are not included in the argument.
1850 No further processing is done on the information between the braces
1851 except that backslash-newline sequences are eliminated.
1852 </p>
1853 </li>
1854 <li>
1856 If a field doesn&#8217;t begin with a brace then backslash,
1857 variable, and command substitution are done on the field. Only a
1858 single level of processing is done: the results of one substitution
1859 are not scanned again for further substitutions or any other
1860 special treatment. Substitution can
1861 occur on any field of a command, including the command name
1862 as well as the arguments.
1863 </p>
1864 </li>
1865 <li>
1867 If the first non-blank character of a command is a <code>#</code>, everything
1868 from the <code>#</code> up through the next newline is treated as a comment
1869 and ignored.
1870 </p>
1871 </li>
1872 </ol></div>
1873 </div>
1874 </div>
1875 <div class="sect1">
1876 <h2 id="_expressions">EXPRESSIONS</h2>
1877 <div class="sectionbody">
1878 <div class="paragraph"><p>The second major interpretation applied to strings in Tcl is
1879 as expressions. Several commands, such as <a href="#_expr"><strong><code>expr</code></strong></a>, <a href="#_for"><strong><code>for</code></strong></a>,
1880 and <a href="#_if"><strong><code>if</code></strong></a>, treat one or more of their arguments as expressions
1881 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
1882 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
1883 <div class="paragraph"><p>The operators permitted in Tcl expressions are a subset of
1884 the operators permitted in C expressions, and they have the
1885 same meaning and precedence as the corresponding C operators.
1886 Expressions almost always yield numeric results
1887 (integer or floating-point values).
1888 For example, the expression</p></div>
1889 <div class="literalblock">
1890 <div class="content">
1891 <pre><code>8.2 + 6</code></pre>
1892 </div></div>
1893 <div class="paragraph"><p>evaluates to 14.2.</p></div>
1894 <div class="paragraph"><p>Tcl expressions differ from C expressions in the way that
1895 operands are specified, and in that Tcl expressions support
1896 non-numeric operands and string comparisons.</p></div>
1897 <div class="paragraph"><p>A Tcl expression consists of a combination of operands, operators,
1898 and parentheses.</p></div>
1899 <div class="paragraph"><p>White space may be used between the operands and operators and
1900 parentheses; it is ignored by the expression processor.
1901 Where possible, operands are interpreted as integer values.</p></div>
1902 <div class="paragraph"><p>Integer values may be specified in decimal (the normal case) or in
1903 hexadecimal (if the first two characters of the operand are <em>0x</em>).
1904 Note that Jim Tcl does <strong>not</strong> treat numbers with leading zeros as octal.</p></div>
1905 <div class="paragraph"><p>If an operand does not have one of the integer formats given
1906 above, then it is treated as a floating-point number if that is
1907 possible. Floating-point numbers may be specified in any of the
1908 ways accepted by an ANSI-compliant C compiler (except that the
1909 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
1910 most installations). For example, all of the
1911 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
1912 <div class="paragraph"><p>If no numeric interpretation is possible, then an operand is left
1913 as a string (and only a limited set of operators may be applied to
1914 it).</p></div>
1915 <div class="olist arabic"><ol class="arabic">
1916 <li>
1918 Operands may be specified in any of the following ways:
1919 </p>
1920 </li>
1921 <li>
1923 As a numeric value, either integer or floating-point.
1924 </p>
1925 </li>
1926 <li>
1928 As a Tcl variable, using standard <em>$</em> notation.
1929 The variable&#8217;s value will be used as the operand.
1930 </p>
1931 </li>
1932 <li>
1934 As a string enclosed in double-quotes.
1935 The expression parser will perform backslash, variable, and
1936 command substitutions on the information between the quotes,
1937 and use the resulting value as the operand
1938 </p>
1939 </li>
1940 <li>
1942 As a string enclosed in braces.
1943 The characters between the open brace and matching close brace
1944 will be used as the operand without any substitutions.
1945 </p>
1946 </li>
1947 <li>
1949 As a Tcl command enclosed in brackets.
1950 The command will be executed and its result will be used as
1951 the operand.
1952 </p>
1953 </li>
1954 </ol></div>
1955 <div class="paragraph"><p>Where substitutions occur above (e.g. inside quoted strings), they
1956 are performed by the expression processor.
1957 However, an additional layer of substitution may already have
1958 been performed by the command parser before the expression
1959 processor was called.</p></div>
1960 <div class="paragraph"><p>As discussed below, it is usually best to enclose expressions
1961 in braces to prevent the command parser from performing substitutions
1962 on the contents.</p></div>
1963 <div class="paragraph"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
1964 the value 3 and the variable <em>b</em> has the value 6. Then the expression
1965 on the left side of each of the lines below will evaluate to the value
1966 on the right side of the line:</p></div>
1967 <div class="literalblock">
1968 <div class="content">
1969 <pre><code>$a + 3.1 6.1
1970 2 + "$a.$b" 5.6
1971 4*[llength "6 2"] 8
1972 {word one} &lt; "word $a" 0</code></pre>
1973 </div></div>
1974 <div class="paragraph"><p>The valid operators are listed below, grouped in decreasing order
1975 of precedence:</p></div>
1976 <div class="dlist" id="OperatorPrecedence"><dl>
1977 <dt class="hdlist1">
1978 <code>int() double() round() abs(), rand(), srand()</code>
1979 </dt>
1980 <dd>
1982 Unary functions (except rand() which takes no arguments)
1983 </p>
1984 <div class="ulist"><ul>
1985 <li>
1987 <code><em>int()</em></code> converts the numeric argument to an integer by truncating down.
1988 </p>
1989 </li>
1990 <li>
1992 <code><em>double()</em></code> converts the numeric argument to floating point.
1993 </p>
1994 </li>
1995 <li>
1997 <code><em>round()</em></code> converts the numeric argument to the closest integer value.
1998 </p>
1999 </li>
2000 <li>
2002 <code><em>abs()</em></code> takes the absolute value of the numeric argument.
2003 </p>
2004 </li>
2005 <li>
2007 <code><em>rand()</em></code> takes the absolute value of the numeric argument.
2008 </p>
2009 </li>
2010 <li>
2012 <code><em>rand()</em></code> returns a pseudo-random floating-point value in the range (0,1).
2013 </p>
2014 </li>
2015 <li>
2017 <code><em>srand()</em></code> takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
2018 </p>
2019 </li>
2020 </ul></div>
2021 </dd>
2022 <dt class="hdlist1">
2023 <code>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</code>
2024 </dt>
2025 <dd>
2027 Unary math functions.
2028 If Jim is compiled with math support, these functions are available.
2029 </p>
2030 </dd>
2031 <dt class="hdlist1">
2032 <code>- + ~ !</code>
2033 </dt>
2034 <dd>
2036 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
2037 may be applied to string operands, and bit-wise NOT may be
2038 applied only to integers.
2039 </p>
2040 </dd>
2041 <dt class="hdlist1">
2042 <code>** pow(x,y)</code>
2043 </dt>
2044 <dd>
2046 Power. e.g. <em>x<sup>y</sup></em>. If Jim is compiled with math support, supports doubles and
2047 integers. Otherwise supports integers only. (Note that the math-function form
2048 has the same highest precedence)
2049 </p>
2050 </dd>
2051 <dt class="hdlist1">
2052 <code>* / %</code>
2053 </dt>
2054 <dd>
2056 Multiply, divide, remainder. None of these operands may be
2057 applied to string operands, and remainder may be applied only
2058 to integers.
2059 </p>
2060 </dd>
2061 <dt class="hdlist1">
2062 <code>+ -</code>
2063 </dt>
2064 <dd>
2066 Add and subtract. Valid for any numeric operands.
2067 </p>
2068 </dd>
2069 <dt class="hdlist1">
2070 <code>&lt;&lt; &gt;&gt; &lt;&lt;&lt; &gt;&gt;&gt;</code>
2071 </dt>
2072 <dd>
2074 Left and right shift, left and right rotate. Valid for integer operands only.
2075 </p>
2076 </dd>
2077 <dt class="hdlist1">
2078 <code>&lt; &gt; &lt;= &gt;=</code>
2079 </dt>
2080 <dd>
2082 Boolean less, greater, less than or equal, and greater than or equal.
2083 Each operator produces 1 if the condition is true, 0 otherwise.
2084 These operators may be applied to strings as well as numeric operands,
2085 in which case string comparison is used.
2086 </p>
2087 </dd>
2088 <dt class="hdlist1">
2089 <code>== !=</code>
2090 </dt>
2091 <dd>
2093 Boolean equal and not equal. Each operator produces a zero/one result.
2094 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
2095 if possible, then floating point types, and finally strings will be compared.
2096 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
2097 </p>
2098 </dd>
2099 <dt class="hdlist1">
2100 <code>eq ne</code>
2101 </dt>
2102 <dd>
2104 String equal and not equal. Uses the string value directly without
2105 attempting to convert to a number first.
2106 </p>
2107 </dd>
2108 <dt class="hdlist1">
2109 <code>in ni</code>
2110 </dt>
2111 <dd>
2113 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
2114 is contained in the right operand (as a list), or 0 otherwise. The result for
2115 <code>{$a ni $list}</code> is equivalent to <code>{!($a in $list)}</code>.
2116 </p>
2117 </dd>
2118 <dt class="hdlist1">
2119 <code>&amp;</code>
2120 </dt>
2121 <dd>
2123 Bit-wise AND. Valid for integer operands only.
2124 </p>
2125 </dd>
2126 <dt class="hdlist1">
2127 <code>|</code>
2128 </dt>
2129 <dd>
2131 Bit-wise OR. Valid for integer operands only.
2132 </p>
2133 </dd>
2134 <dt class="hdlist1">
2135 <code>^</code>
2136 </dt>
2137 <dd>
2139 Bit-wise exclusive OR. Valid for integer operands only.
2140 </p>
2141 </dd>
2142 <dt class="hdlist1">
2143 <code>&amp;&amp;</code>
2144 </dt>
2145 <dd>
2147 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
2148 Valid for numeric operands only (integers or floating-point).
2149 </p>
2150 </dd>
2151 <dt class="hdlist1">
2152 <code>||</code>
2153 </dt>
2154 <dd>
2156 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
2157 Valid for numeric operands only (integers or floating-point).
2158 </p>
2159 </dd>
2160 <dt class="hdlist1">
2161 <code>x ? y : z</code>
2162 </dt>
2163 <dd>
2165 If-then-else, as in C. If <code><em>x</em></code>
2166 evaluates to non-zero, then the result is the value of <code><em>y</em></code>.
2167 Otherwise the result is the value of <code><em>z</em></code>.
2168 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
2169 be of any type.
2170 </p>
2171 </dd>
2172 </dl></div>
2173 <div class="paragraph"><p>See the C manual for more details on the results
2174 produced by each operator.
2175 All of the binary operators group left-to-right within the same
2176 precedence level. For example, the expression</p></div>
2177 <div class="literalblock">
2178 <div class="content">
2179 <pre><code>4*2 &lt; 7</code></pre>
2180 </div></div>
2181 <div class="paragraph"><p>evaluates to 0.</p></div>
2182 <div class="paragraph"><p>The <code>&amp;&amp;</code>, <code>||</code>, and <code>?:</code> operators have <em>lazy evaluation</em>, just as
2183 in C, which means that operands are not evaluated if they are not
2184 needed to determine the outcome. For example, in</p></div>
2185 <div class="literalblock">
2186 <div class="content">
2187 <pre><code>$v ? [a] : [b]</code></pre>
2188 </div></div>
2189 <div class="paragraph"><p>only one of <code>[a]</code> or <code>[b]</code> will actually be evaluated,
2190 depending on the value of <code>$v</code>.</p></div>
2191 <div class="paragraph"><p>All internal computations involving integers are done with the C
2192 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
2193 computations involving floating-point are done with the C type
2194 <em>double</em>.</p></div>
2195 <div class="paragraph"><p>When converting a string to floating-point, exponent overflow is
2196 detected and results in a Tcl error.
2197 For conversion to integer from string, detection of overflow depends
2198 on the behaviour of some routines in the local C library, so it should
2199 be regarded as unreliable.
2200 In any case, overflow and underflow are generally not detected
2201 reliably for intermediate results.</p></div>
2202 <div class="paragraph"><p>Conversion among internal representations for integer, floating-point,
2203 and string operands is done automatically as needed.
2204 For arithmetic computations, integers are used until some
2205 floating-point number is introduced, after which floating-point is used.
2206 For example,</p></div>
2207 <div class="literalblock">
2208 <div class="content">
2209 <pre><code>5 / 4</code></pre>
2210 </div></div>
2211 <div class="paragraph"><p>yields the result 1, while</p></div>
2212 <div class="literalblock">
2213 <div class="content">
2214 <pre><code>5 / 4.0
2215 5 / ( [string length "abcd"] + 0.0 )</code></pre>
2216 </div></div>
2217 <div class="paragraph"><p>both yield the result 1.25.</p></div>
2218 <div class="paragraph"><p>String values may be used as operands of the comparison operators,
2219 although the expression evaluator tries to do comparisons as integer
2220 or floating-point when it can.
2221 If one of the operands of a comparison is a string and the other
2222 has a numeric value, the numeric operand is converted back to
2223 a string using the C <em>sprintf</em> format specifier
2224 <em>%d</em> for integers and <em>%g</em> for floating-point values.
2225 For example, the expressions</p></div>
2226 <div class="literalblock">
2227 <div class="content">
2228 <pre><code>"0x03" &gt; "2"
2229 "0y" &lt; "0x12"</code></pre>
2230 </div></div>
2231 <div class="paragraph"><p>both evaluate to 1. The first comparison is done using integer
2232 comparison, and the second is done using string comparison after
2233 the second operand is converted to the string <em>18</em>.</p></div>
2234 <div class="paragraph"><p>In general it is safest to enclose an expression in braces when
2235 entering it in a command: otherwise, if the expression contains
2236 any white space then the Tcl interpreter will split it
2237 among several arguments. For example, the command</p></div>
2238 <div class="literalblock">
2239 <div class="content">
2240 <pre><code>expr $a + $b</code></pre>
2241 </div></div>
2242 <div class="paragraph"><p>results in three arguments being passed to <a href="#_expr"><strong><code>expr</code></strong></a>: <code>$a</code>,
2243 +, and <code>$b</code>. In addition, if the expression isn&#8217;t in braces
2244 then the Tcl interpreter will perform variable and command substitution
2245 immediately (it will happen in the command parser rather than in
2246 the expression parser). In many cases the expression is being
2247 passed to a command that will evaluate the expression later (or
2248 even many times if, for example, the expression is to be used to
2249 decide when to exit a loop). Usually the desired goal is to re-do
2250 the variable or command substitutions each time the expression is
2251 evaluated, rather than once and for all at the beginning. For example,
2252 the command</p></div>
2253 <div class="literalblock">
2254 <div class="content">
2255 <pre><code>for {set i 1} $i&lt;=10 {incr i} {...} ** WRONG **</code></pre>
2256 </div></div>
2257 <div class="paragraph"><p>is probably intended to iterate over all values of <code>i</code> from 1 to 10.
2258 After each iteration of the body of the loop, <a href="#_for"><strong><code>for</code></strong></a> will pass
2259 its second argument to the expression evaluator to see whether or not
2260 to continue processing. Unfortunately, in this case the value of <code>i</code>
2261 in the second argument will be substituted once and for all when the
2262 <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>
2263 command was invoked then the second argument of <a href="#_for"><strong><code>for</code></strong></a> will be <code>0&lt;=10</code>
2264 which will always evaluate to 1, even though <code>i</code> eventually
2265 becomes greater than 10. In the above case the loop will never
2266 terminate. Instead, the expression should be placed in braces:</p></div>
2267 <div class="literalblock">
2268 <div class="content">
2269 <pre><code>for {set i 1} {$i&lt;=10} {incr i} {...} ** RIGHT **</code></pre>
2270 </div></div>
2271 <div class="paragraph"><p>This causes the substitution of <em>i</em>
2272 to be delayed; it will be re-done each time the expression is
2273 evaluated, which is the desired result.</p></div>
2274 </div>
2275 </div>
2276 <div class="sect1">
2277 <h2 id="_lists">LISTS</h2>
2278 <div class="sectionbody">
2279 <div class="paragraph"><p>The third major way that strings are interpreted in Tcl is as lists.
2280 A list is just a string with a list-like structure
2281 consisting of fields separated by white space. For example, the
2282 string</p></div>
2283 <div class="literalblock">
2284 <div class="content">
2285 <pre><code>Al Sue Anne John</code></pre>
2286 </div></div>
2287 <div class="paragraph"><p>is a list with four elements or fields.
2288 Lists have the same basic structure as command strings, except
2289 that a newline character in a list is treated as a field separator
2290 just like space or tab. Conventions for braces and quotes
2291 and backslashes are the same for lists as for commands. For example,
2292 the string</p></div>
2293 <div class="literalblock">
2294 <div class="content">
2295 <pre><code>a b\ c {d e {f g h}}</code></pre>
2296 </div></div>
2297 <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>
2298 <div class="paragraph"><p>Whenever an element is extracted from a list, the same rules about
2299 braces and quotes and backslashes are applied as for commands. Thus in
2300 the example above when the third element is extracted from the list,
2301 the result is</p></div>
2302 <div class="literalblock">
2303 <div class="content">
2304 <pre><code>d e {f g h}</code></pre>
2305 </div></div>
2306 <div class="paragraph"><p>(when the field was extracted, all that happened was to strip off
2307 the outermost layer of braces). Command substitution and
2308 variable substitution are never
2309 made on a list (at least, not by the list-processing commands; the
2310 list can always be passed to the Tcl interpreter for evaluation).</p></div>
2311 <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>,
2312 <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
2313 you to build lists, extract elements from them, search them, and perform
2314 other list-related functions.</p></div>
2315 <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>
2316 </div>
2317 </div>
2318 <div class="sect1">
2319 <h2 id="_list_expansion">LIST EXPANSION</h2>
2320 <div class="sectionbody">
2321 <div class="paragraph"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
2322 arguments. Support for this feature is also available in Jim.</p></div>
2323 <div class="paragraph"><p>Consider the following attempt to exec a list:</p></div>
2324 <div class="literalblock">
2325 <div class="content">
2326 <pre><code>set cmd {ls -l}
2327 exec $cmd</code></pre>
2328 </div></div>
2329 <div class="paragraph"><p>This will attempt to exec the a command named "ls -l", which will clearly not
2330 work. Typically eval and concat are required to solve this problem, however
2331 it can be solved much more easily with <code>{*}</code>.</p></div>
2332 <div class="literalblock">
2333 <div class="content">
2334 <pre><code>exec {*}$cmd</code></pre>
2335 </div></div>
2336 <div class="paragraph"><p>This will expand the following argument into individual elements and then evaluate
2337 the resulting command.</p></div>
2338 <div class="paragraph"><p>Note that the official Tcl syntax is <code>{*}</code>, however <code>{expand}</code> is retained
2339 for backward compatibility with experimental versions of this feature.</p></div>
2340 </div>
2341 </div>
2342 <div class="sect1">
2343 <h2 id="_regular_expressions">REGULAR EXPRESSIONS</h2>
2344 <div class="sectionbody">
2345 <div class="paragraph"><p>Tcl provides two commands that support string matching using regular
2346 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
2347 <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-regexp</code>.</p></div>
2348 <div class="paragraph"><p>Regular expressions may be implemented one of two ways. Either using the system&#8217;s C library
2349 POSIX regular expression support, or using the built-in regular expression engine.
2350 The differences between these are described below.</p></div>
2351 <div class="paragraph"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<code>ARE</code>).</p></div>
2352 <div class="sect2">
2353 <h3 id="_posix_regular_expressions">POSIX Regular Expressions</h3>
2354 <div class="paragraph"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
2355 this support will be used by default. The type of regular expressions supported are
2356 Extended Regular Expressions (<code>ERE</code>) rather than Basic Regular Expressions (<code>BRE</code>).
2357 See REG_EXTENDED in the documentation.</p></div>
2358 <div class="paragraph"><p>Using the system-supported POSIX regular expressions will typically
2359 make for the smallest code size, but some features such as UTF-8
2360 and <code>\w</code>, <code>\d</code>, <code>\s</code> are not supported.</p></div>
2361 <div class="paragraph"><p>See regex(3) and regex(7) for full details.</p></div>
2362 </div>
2363 <div class="sect2">
2364 <h3 id="_jim_built_in_regular_expressions">Jim built-in Regular Expressions</h3>
2365 <div class="paragraph"><p>The Jim built-in regulare expression engine may be selected with <code>./configure --with-jim-regexp</code>
2366 or it will be selected automatically if UTF-8 support is enabled.</p></div>
2367 <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
2368 and POSIX are highlighted below.</p></div>
2369 <div class="olist arabic"><ol class="arabic">
2370 <li>
2372 UTF-8 strings and patterns are both supported
2373 </p>
2374 </li>
2375 <li>
2377 Supported character classes: <code>[:alnum:]</code>, <code>[:digit:]</code> and <code>[:space:]</code>
2378 </p>
2379 </li>
2380 <li>
2382 Supported shorthand character classes: <code>\w</code> = <code>[:alnum:]</code>, <code>\d</code> = <code>[:digit:],</code> <code>\s</code> = <code>[:space:]</code>
2383 </p>
2384 </li>
2385 <li>
2387 Character classes apply to ASCII characters only
2388 </p>
2389 </li>
2390 <li>
2392 Supported constraint escapes: <code>\m</code> = <code>\&lt;</code> = start of word, <code>\M</code> = <code>\&gt;</code> = end of word
2393 </p>
2394 </li>
2395 <li>
2397 Backslash escapes may be used within regular expressions, such as <code>\n</code> = newline, <code>\uNNNN</code> = unicode
2398 </p>
2399 </li>
2400 <li>
2402 Support for the <code>?</code> non-greedy quantifier. e.g. <code>*?</code>
2403 </p>
2404 </li>
2405 <li>
2407 Support for non-capuring parentheses <code>(?:&#8230;)</code>
2408 </p>
2409 </li>
2410 </ol></div>
2411 </div>
2412 </div>
2413 </div>
2414 <div class="sect1">
2415 <h2 id="_command_results">COMMAND RESULTS</h2>
2416 <div class="sectionbody">
2417 <div class="paragraph"><p>Each command produces two results: a code and a string. The
2418 code indicates whether the command completed successfully or not,
2419 and the string gives additional information. The valid codes are
2420 defined in jim.h, and are:</p></div>
2421 <div class="dlist"><dl>
2422 <dt class="hdlist1">
2423 <code>JIM_OK(0)</code>
2424 </dt>
2425 <dd>
2427 This is the normal return code, and indicates that the command completed
2428 successfully. The string gives the command&#8217;s return value.
2429 </p>
2430 </dd>
2431 <dt class="hdlist1">
2432 <code>JIM_ERR(1)</code>
2433 </dt>
2434 <dd>
2436 Indicates that an error occurred; the string gives a message describing
2437 the error.
2438 </p>
2439 </dd>
2440 <dt class="hdlist1">
2441 <code>JIM_RETURN(2)</code>
2442 </dt>
2443 <dd>
2445 Indicates that the <a href="#_return"><strong><code>return</code></strong></a> command has been invoked, and that the
2446 current procedure (or top-level command or <a href="#_source"><strong><code>source</code></strong></a> command)
2447 should return immediately. The
2448 string gives the return value for the procedure or command.
2449 </p>
2450 </dd>
2451 <dt class="hdlist1">
2452 <code>JIM_BREAK(3)</code>
2453 </dt>
2454 <dd>
2456 Indicates that the <a href="#_break"><strong><code>break</code></strong></a> command has been invoked, so the
2457 innermost loop should abort immediately. The string should always
2458 be empty.
2459 </p>
2460 </dd>
2461 <dt class="hdlist1">
2462 <code>JIM_CONTINUE(4)</code>
2463 </dt>
2464 <dd>
2466 Indicates that the <a href="#_continue"><strong><code>continue</code></strong></a> command has been invoked, so the
2467 innermost loop should go on to the next iteration. The string
2468 should always be empty.
2469 </p>
2470 </dd>
2471 <dt class="hdlist1">
2472 <code>JIM_SIGNAL(5)</code>
2473 </dt>
2474 <dd>
2476 Indicates that a signal was caught while executing a commands.
2477 The string contains the name of the signal caught.
2478 See the <a href="#_signal"><strong><code>signal</code></strong></a> and <a href="#_catch"><strong><code>catch</code></strong></a> commands.
2479 </p>
2480 </dd>
2481 <dt class="hdlist1">
2482 <code>JIM_EXIT(6)</code>
2483 </dt>
2484 <dd>
2486 Indicates that the command called the <a href="#_exit"><strong><code>exit</code></strong></a> command.
2487 The string contains the exit code.
2488 </p>
2489 </dd>
2490 </dl></div>
2491 <div class="paragraph"><p>Tcl programmers do not normally need to think about return codes,
2492 since <code>JIM_OK</code> is almost always returned. If anything else is returned
2493 by a command, then the Tcl interpreter immediately stops processing
2494 commands and returns to its caller. If there are several nested
2495 invocations of the Tcl interpreter in progress, then each nested
2496 command will usually return the error to its caller, until eventually
2497 the error is reported to the top-level application code. The
2498 application will then display the error message for the user.</p></div>
2499 <div class="paragraph"><p>In a few cases, some commands will handle certain <a href="#_error"><strong><code>error</code></strong></a> conditions
2500 themselves and not return them upwards. For example, the <a href="#_for"><strong><code>for</code></strong></a>
2501 command checks for the <code>JIM_BREAK</code> code; if it occurs, then <a href="#_for"><strong><code>for</code></strong></a>
2502 stops executing the body of the loop and returns <code>JIM_OK</code> to its
2503 caller. The <a href="#_for"><strong><code>for</code></strong></a> command also handles <code>JIM_CONTINUE</code> codes and the
2504 procedure interpreter handles <code>JIM_RETURN</code> codes. The <a href="#_catch"><strong><code>catch</code></strong></a>
2505 command allows Tcl programs to catch errors and handle them without
2506 aborting command interpretation any further.</p></div>
2507 <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
2508 return codes and names.</p></div>
2509 </div>
2510 </div>
2511 <div class="sect1">
2512 <h2 id="_procedures">PROCEDURES</h2>
2513 <div class="sectionbody">
2514 <div class="paragraph"><p>Tcl allows you to extend the command interface by defining
2515 procedures. A Tcl procedure can be invoked just like any other Tcl
2516 command (it has a name and it receives one or more arguments).
2517 The only difference is that its body isn&#8217;t a piece of C code linked
2518 into the program; it is a string containing one or more other
2519 Tcl commands.</p></div>
2520 <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>
2521 <div class="paragraph"><p><code><strong>proc</strong> <em>name arglist ?statics? body</em></code></p></div>
2522 <div class="paragraph"><p>The new command is named <code><em>name</em></code>, and it replaces any existing command
2523 there may have been by that name. Whenever the new command is
2524 invoked, the contents of <code><em>body</em></code> will be executed by the Tcl
2525 interpreter.</p></div>
2526 <div class="paragraph"><p><code><em>arglist</em></code> specifies the formal arguments to the procedure.
2527 It consists of a list, possibly empty, of the following
2528 argument specifiers:</p></div>
2529 <div class="dlist"><dl>
2530 <dt class="hdlist1">
2531 <code>name</code>
2532 </dt>
2533 <dd>
2535 Required Argument - A simple argument name.
2536 </p>
2537 </dd>
2538 <dt class="hdlist1">
2539 <code>name default</code>
2540 </dt>
2541 <dd>
2543 Optional Argument - A two-element list consisting of the
2544 argument name, followed by the default value, which will
2545 be used if the corresponding argument is not supplied.
2546 </p>
2547 </dd>
2548 <dt class="hdlist1">
2549 <code>&amp;name</code>
2550 </dt>
2551 <dd>
2553 Reference Argument - The caller is expected to pass the name of
2554 an existing variable. An implicit <a href="#_upvar"><strong><code>upvar</code></strong></a> <code>1 'origname' 'name'</code> is done
2555 to make the variable available in the proc scope.
2556 </p>
2557 </dd>
2558 <dt class="hdlist1">
2559 <code><strong>args</strong></code>
2560 </dt>
2561 <dd>
2563 Variable Argument - The special name <code><em>args</em></code>, which is
2564 assigned all remaining arguments (including none) as a list. The
2565 variable argument may only be specified once. Note that
2566 the syntax <code>args newname</code> may be used to retain the special
2567 behaviour of <code><em>args</em></code> with a different local name. In this case,
2568 the variable is named <code><em>newname</em></code> rather than <code><em>args</em></code>.
2569 </p>
2570 </dd>
2571 </dl></div>
2572 <div class="paragraph"><p>When the command is invoked, a local variable will be created for each of
2573 the formal arguments to the procedure; its value will be the value
2574 of corresponding argument in the invoking command or the argument&#8217;s
2575 default value.</p></div>
2576 <div class="paragraph"><p>Arguments with default values need not be specified in a procedure
2577 invocation. However, there must be enough actual arguments for all
2578 required arguments, and there must not be any extra actual arguments
2579 (unless the Variable Argument is specified).</p></div>
2580 <div class="paragraph"><p>Actual arguments are assigned to formal arguments as in left-to-right
2581 order with the following precedence.</p></div>
2582 <div class="olist arabic"><ol class="arabic">
2583 <li>
2585 Required Arguments (including Reference Arguments)
2586 </p>
2587 </li>
2588 <li>
2590 Optional Arguments
2591 </p>
2592 </li>
2593 <li>
2595 Variable Argument
2596 </p>
2597 </li>
2598 </ol></div>
2599 <div class="paragraph"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2600 <div class="literalblock">
2601 <div class="content">
2602 <pre><code>proc p {{a A} args b {c C} d} {...}</code></pre>
2603 </div></div>
2604 <div class="paragraph"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2605 The following table shows how various numbers of arguments are assigned.
2606 Values marked as <code>-</code> are assigned the default value.</p></div>
2607 <div class="tableblock">
2608 <table rules="all"
2609 width="40%"
2610 frame="hsides"
2611 cellspacing="0" cellpadding="4">
2612 <col width="16%" />
2613 <col width="16%" />
2614 <col width="16%" />
2615 <col width="16%" />
2616 <col width="16%" />
2617 <col width="16%" />
2618 <thead>
2619 <tr>
2620 <th align="left" valign="top">Number of arguments</th>
2621 <th align="left" valign="top">a</th>
2622 <th align="left" valign="top">args</th>
2623 <th align="left" valign="top">b</th>
2624 <th align="left" valign="top">c</th>
2625 <th align="left" valign="top">d</th>
2626 </tr>
2627 </thead>
2628 <tbody>
2629 <tr>
2630 <td align="left" valign="top"><p class="table">2</p></td>
2631 <td align="left" valign="top"><p class="table">-</p></td>
2632 <td align="left" valign="top"><p class="table">-</p></td>
2633 <td align="left" valign="top"><p class="table">1</p></td>
2634 <td align="left" valign="top"><p class="table">-</p></td>
2635 <td align="left" valign="top"><p class="table">2</p></td>
2636 </tr>
2637 <tr>
2638 <td align="left" valign="top"><p class="table">3</p></td>
2639 <td align="left" valign="top"><p class="table">1</p></td>
2640 <td align="left" valign="top"><p class="table">-</p></td>
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">3</p></td>
2644 </tr>
2645 <tr>
2646 <td align="left" valign="top"><p class="table">4</p></td>
2647 <td align="left" valign="top"><p class="table">1</p></td>
2648 <td align="left" valign="top"><p class="table">-</p></td>
2649 <td align="left" valign="top"><p class="table">2</p></td>
2650 <td align="left" valign="top"><p class="table">3</p></td>
2651 <td align="left" valign="top"><p class="table">4</p></td>
2652 </tr>
2653 <tr>
2654 <td align="left" valign="top"><p class="table">5</p></td>
2655 <td align="left" valign="top"><p class="table">1</p></td>
2656 <td align="left" valign="top"><p class="table">2</p></td>
2657 <td align="left" valign="top"><p class="table">3</p></td>
2658 <td align="left" valign="top"><p class="table">4</p></td>
2659 <td align="left" valign="top"><p class="table">5</p></td>
2660 </tr>
2661 <tr>
2662 <td align="left" valign="top"><p class="table">6</p></td>
2663 <td align="left" valign="top"><p class="table">1</p></td>
2664 <td align="left" valign="top"><p class="table">2,3</p></td>
2665 <td align="left" valign="top"><p class="table">4</p></td>
2666 <td align="left" valign="top"><p class="table">5</p></td>
2667 <td align="left" valign="top"><p class="table">6</p></td>
2668 </tr>
2669 </tbody>
2670 </table>
2671 </div>
2672 <div class="paragraph"><p>When <code><em>body</em></code> is being executed, variable names normally refer to local
2673 variables, which are created automatically when referenced and deleted
2674 when the procedure returns. One local variable is automatically created
2675 for each of the procedure&#8217;s arguments. Global variables can be
2676 accessed by invoking the <a href="#_global"><strong><code>global</code></strong></a> command or via the <code>::</code> prefix.</p></div>
2677 <div class="sect2">
2678 <h3 id="_new_in_jim">New in Jim</h3>
2679 <div class="paragraph"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2680 These variables scoped to the procedure and initialised at procedure definition.
2681 Either from the static variable definition, or from the enclosing scope.</p></div>
2682 <div class="paragraph"><p>Consider the following example:</p></div>
2683 <div class="literalblock">
2684 <div class="content">
2685 <pre><code>jim&gt; set a 1
2686 jim&gt; proc a {} {a {b 2}} {
2687 set c 1
2688 puts "$a $b $c"
2689 incr a
2690 incr b
2691 incr c
2693 jim&gt; a
2694 1 2 1
2695 jim&gt; a
2696 2 3 1</code></pre>
2697 </div></div>
2698 <div class="paragraph"><p>The static variable <code><em>a</em></code> has no initialiser, so it is initialised from
2699 the enclosing scope with the value 1. (Note that it is an error if there
2700 is no variable with the same name in the enclosing scope). However <code><em>b</em></code>
2701 has an initialiser, so it is initialised to 2.</p></div>
2702 <div class="paragraph"><p>Unlike a local variable, the value of a static variable is retained across
2703 invocations of the procedure.</p></div>
2704 <div class="paragraph"><p>See the <a href="#_proc"><strong><code>proc</code></strong></a> command for information on how to define procedures
2705 and what happens when they are invoked. See also NAMESPACES.</p></div>
2706 </div>
2707 </div>
2708 </div>
2709 <div class="sect1">
2710 <h2 id="_variables_scalars_and_arrays">VARIABLES - SCALARS AND ARRAYS</h2>
2711 <div class="sectionbody">
2712 <div class="paragraph"><p>Tcl allows the definition of variables and the use of their values
2713 either through <em>$</em>-style variable substitution, the <a href="#_set"><strong><code>set</code></strong></a>
2714 command, or a few other mechanisms.</p></div>
2715 <div class="paragraph"><p>Variables need not be declared: a new variable will automatically
2716 be created each time a new variable name is used.</p></div>
2717 <div class="paragraph"><p>Tcl supports two types of variables: scalars and arrays.
2718 A scalar variable has a single value, whereas an array variable
2719 can have any number of elements, each with a name (called
2720 its <em>index</em>) and a value.</p></div>
2721 <div class="paragraph"><p>Array indexes may be arbitrary strings; they need not be numeric.
2722 Parentheses are used refer to array elements in Tcl commands.
2723 For example, the command</p></div>
2724 <div class="literalblock">
2725 <div class="content">
2726 <pre><code>set x(first) 44</code></pre>
2727 </div></div>
2728 <div class="paragraph"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2729 so that its new value is <em>44</em>.</p></div>
2730 <div class="paragraph"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2731 that contain multiple concatenated values.
2732 For example, the commands</p></div>
2733 <div class="literalblock">
2734 <div class="content">
2735 <pre><code>set a(2,3) 1
2736 set a(3,6) 2</code></pre>
2737 </div></div>
2738 <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>
2739 <div class="paragraph"><p>In general, array elements may be used anywhere in Tcl that scalar
2740 variables may be used.</p></div>
2741 <div class="paragraph"><p>If an array is defined with a particular name, then there may
2742 not be a scalar variable with the same name.</p></div>
2743 <div class="paragraph"><p>Similarly, if there is a scalar variable with a particular
2744 name then it is not possible to make array references to the
2745 variable.</p></div>
2746 <div class="paragraph"><p>To convert a scalar variable to an array or vice versa, remove
2747 the existing variable with the <a href="#_unset"><strong><code>unset</code></strong></a> command.</p></div>
2748 <div class="paragraph"><p>The <a href="#_array"><strong><code>array</code></strong></a> command provides several features for dealing
2749 with arrays, such as querying the names of all the elements of
2750 the array and converting between an array and a list.</p></div>
2751 <div class="paragraph"><p>Variables may be either global or local. If a variable
2752 name is used when a procedure isn&#8217;t being executed, then it
2753 automatically refers to a global variable. Variable names used
2754 within a procedure normally refer to local variables associated with that
2755 invocation of the procedure. Local variables are deleted whenever
2756 a procedure exits. Either <a href="#_global"><strong><code>global</code></strong></a> command may be used to request
2757 that a name refer to a global variable for the duration of the current
2758 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2759 may be explicitly scoped with the <code>::</code> prefix. For example</p></div>
2760 <div class="literalblock">
2761 <div class="content">
2762 <pre><code>set a 1
2763 set b 2
2764 proc p {} {
2765 set c 3
2766 global a</code></pre>
2767 </div></div>
2768 <div class="literalblock">
2769 <div class="content">
2770 <pre><code> puts "$a $::b $c"
2772 p</code></pre>
2773 </div></div>
2774 <div class="paragraph"><p>will output:</p></div>
2775 <div class="literalblock">
2776 <div class="content">
2777 <pre><code>1 2 3</code></pre>
2778 </div></div>
2779 </div>
2780 </div>
2781 <div class="sect1">
2782 <h2 id="_arrays_as_lists_in_jim">ARRAYS AS LISTS IN JIM</h2>
2783 <div class="sectionbody">
2784 <div class="paragraph"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2785 number of elements) and an array value. This is similar to the way Tcl
2786 can convert between a string and a list.</p></div>
2787 <div class="paragraph"><p>For example:</p></div>
2788 <div class="literalblock">
2789 <div class="content">
2790 <pre><code>set a {1 one 2 two}
2791 puts $a(2)</code></pre>
2792 </div></div>
2793 <div class="paragraph"><p>will output:</p></div>
2794 <div class="literalblock">
2795 <div class="content">
2796 <pre><code>two</code></pre>
2797 </div></div>
2798 <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
2799 exist or is empty.</p></div>
2800 <div class="paragraph"><p>The reverse is also true where an array will be converted into
2801 a list.</p></div>
2802 <div class="literalblock">
2803 <div class="content">
2804 <pre><code>set a(1) one; set a(2) two
2805 puts $a</code></pre>
2806 </div></div>
2807 <div class="paragraph"><p>will output:</p></div>
2808 <div class="literalblock">
2809 <div class="content">
2810 <pre><code>1 one 2 two</code></pre>
2811 </div></div>
2812 </div>
2813 </div>
2814 <div class="sect1">
2815 <h2 id="_dictionary_values">DICTIONARY VALUES</h2>
2816 <div class="sectionbody">
2817 <div class="paragraph"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2818 of this command. Dictionaries provide efficient access to key-value
2819 pairs, just like arrays, but dictionaries are pure values. This
2820 means that you can pass them to a procedure just as a list or a
2821 string. Tcl dictionaries are therefore much more like Tcl lists,
2822 except that they represent a mapping from keys to values, rather
2823 than an ordered sequence.</p></div>
2824 <div class="paragraph"><p>You can nest dictionaries, so that the value for a particular key
2825 consists of another dictionary. That way you can elegantly build
2826 complicated data structures, such as hierarchical databases. You
2827 can also combine dictionaries with other Tcl data structures. For
2828 instance, you can build a list of dictionaries that themselves
2829 contain lists.</p></div>
2830 <div class="paragraph"><p>Dictionaries are values that contain an efficient, order-preserving
2831 mapping from arbitrary keys to arbitrary values. Each key in the
2832 dictionary maps to a single value. They have a textual format that
2833 is exactly that of any list with an even number of elements, with
2834 each mapping in the dictionary being represented as two items in
2835 the list. When a command takes a dictionary and produces a new
2836 dictionary based on it (either returning it or writing it back into
2837 the variable that the starting dictionary was read from) the new
2838 dictionary will have the same order of keys, modulo any deleted
2839 keys and with new keys added on to the end. When a string is
2840 interpreted as a dictionary and it would otherwise have duplicate
2841 keys, only the last value for a particular key is used; the others
2842 are ignored, meaning that, "apple banana" and "apple carrot apple
2843 banana" are equivalent dictionaries (with different string
2844 representations).</p></div>
2845 <div class="paragraph"><p>Note that in Jim, arrays are implemented as dictionaries.
2846 Thus automatic conversion between lists and dictionaries applies
2847 as it does for arrays.</p></div>
2848 <div class="literalblock">
2849 <div class="content">
2850 <pre><code>jim&gt; dict set a 1 one
2851 1 one
2852 jim&gt; dict set a 2 two
2853 1 one 2 two
2854 jim&gt; puts $a
2855 1 one 2 two
2856 jim&gt; puts $a(2)
2858 jim&gt; dict set a 3 T three
2859 1 one 2 two 3 {T three}</code></pre>
2860 </div></div>
2861 <div class="paragraph"><p>See the <a href="#_dict"><strong><code>dict</code></strong></a> command for more details.</p></div>
2862 </div>
2863 </div>
2864 <div class="sect1">
2865 <h2 id="_namespaces">NAMESPACES</h2>
2866 <div class="sectionbody">
2867 <div class="paragraph"><p>Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
2868 including a number of 3rd party components. While there is less need for namespaces
2869 in Jim Tcl (which does not strive to support large applications), it is convenient to
2870 provide a subset of the support for namespaces to easy porting code from Tcl.</p></div>
2871 <div class="paragraph"><p>Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
2872 purposes. This feature is currently experimental. See README.namespaces for more information
2873 and the documentation of the <a href="#_namespace"><strong><code>namespace</code></strong></a> command.</p></div>
2874 </div>
2875 </div>
2876 <div class="sect1">
2877 <h2 id="_garbage_collection_references_lambda">GARBAGE COLLECTION, REFERENCES, LAMBDA</h2>
2878 <div class="sectionbody">
2879 <div class="paragraph"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
2880 These are described briefly below.</p></div>
2881 <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>
2882 <div class="sect2">
2883 <h3 id="_references">References</h3>
2884 <div class="paragraph"><p>A reference can be thought of as holding a value with one level of indirection,
2885 where the value may be garbage collected when unreferenced.
2886 Consider the following example:</p></div>
2887 <div class="literalblock">
2888 <div class="content">
2889 <pre><code>jim&gt; set r [ref "One String" test]
2890 &lt;reference.&lt;test___&gt;.00000000000000000000&gt;
2891 jim&gt; getref $r
2892 One String</code></pre>
2893 </div></div>
2894 <div class="paragraph"><p>The operation <a href="#_ref"><strong><code>ref</code></strong></a> creates a references to the value specified by the
2895 first argument. (The second argument is a "type" used for documentation purposes).</p></div>
2896 <div class="paragraph"><p>The operation <a href="#_getref"><strong><code>getref</code></strong></a> is the dereferencing operation which retrieves the value
2897 stored in the reference.</p></div>
2898 <div class="literalblock">
2899 <div class="content">
2900 <pre><code>jim&gt; setref $r "New String"
2901 New String
2902 jim&gt; getref $r
2903 New String</code></pre>
2904 </div></div>
2905 <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
2906 is no longer accessible by any reference, it will eventually be automatically be garbage
2907 collected.</p></div>
2908 </div>
2909 <div class="sect2">
2910 <h3 id="_garbage_collection">Garbage Collection</h3>
2911 <div class="paragraph"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
2912 automatically as necessary.</p></div>
2913 <div class="paragraph"><p>With the introduction of references, it is possible to create values whose lifetime
2914 transcend their scope. To support this, case, the Jim system will periodically identify
2915 and discard objects which are no longer accessible by any reference.</p></div>
2916 <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
2917 with a finalizer:</p></div>
2918 <div class="literalblock">
2919 <div class="content">
2920 <pre><code>jim&gt; proc f {ref value} { puts "Finaliser called for $ref,$value" }
2921 jim&gt; set r [ref "One String" test f]
2922 &lt;reference.&lt;test___&gt;.00000000000
2923 jim&gt; collect
2925 jim&gt; set r ""
2926 jim&gt; collect
2927 Finaliser called for &lt;reference.&lt;test___&gt;.00000000000,One String
2928 1</code></pre>
2929 </div></div>
2930 <div class="paragraph"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
2931 contained a reference to the value, the garbage collector discarded
2932 the value (after calling the finalizer).</p></div>
2933 <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>
2934 <div class="literalblock">
2935 <div class="content">
2936 <pre><code>jim&gt; finalize $r
2938 jim&gt; finalize $r newf
2939 newf</code></pre>
2940 </div></div>
2941 </div>
2942 <div class="sect2">
2943 <h3 id="_lambda">Lambda</h3>
2944 <div class="paragraph"><p>Jim provides a garbage collected lambda function. This is a procedure
2945 which is able to create an anonymous procedure. Consider:</p></div>
2946 <div class="literalblock">
2947 <div class="content">
2948 <pre><code>jim&gt; set f [lambda {a} {{x 0}} { incr x $a }]
2949 jim&gt; $f 1
2951 jim&gt; $f 2
2953 jim&gt; set f ""</code></pre>
2954 </div></div>
2955 <div class="paragraph"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
2956 which is incremented by the supplied value and the result returned.</p></div>
2957 <div class="paragraph"><p>Once the procedure name is no longer accessible, it will automatically be deleted
2958 when the garbage collector runs.</p></div>
2959 <div class="paragraph"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
2960 <div class="literalblock">
2961 <div class="content">
2962 <pre><code>jim&gt; rename $f ""</code></pre>
2963 </div></div>
2964 </div>
2965 </div>
2966 </div>
2967 <div class="sect1">
2968 <h2 id="_utf_8_and_unicode">UTF-8 AND UNICODE</h2>
2969 <div class="sectionbody">
2970 <div class="paragraph"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
2971 then most string-related commands become UTF-8 aware. These include,
2972 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
2973 <a href="#_format"><strong><code>format</code></strong></a>.</p></div>
2974 <div class="paragraph"><p>UTF-8 encoding has many advantages, but one of the complications is that
2975 characters can take a variable number of bytes. Thus the addition of
2976 <a href="#_string"><strong><code>string</code></strong></a> <code>bytelength</code> which returns the number of bytes in a string,
2977 while <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> returns the number of characters.</p></div>
2978 <div class="paragraph"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
2979 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>
2980 <div class="paragraph"><p>Note that even if UTF-8 support is not enabled, the <code>\uNNNN</code> and related syntax
2981 is still available to embed UTF-8 sequences.</p></div>
2982 <div class="paragraph"><p>Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +<em>U+1FFFFF</em>.</p></div>
2983 <div class="sect2">
2984 <h3 id="_string_matching">String Matching</h3>
2985 <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
2986 pattern matching rules. These commands support UTF-8. For example:</p></div>
2987 <div class="literalblock">
2988 <div class="content">
2989 <pre><code>string match a\[\ua0-\ubf\]b "a\u00a3b"</code></pre>
2990 </div></div>
2991 </div>
2992 <div class="sect2">
2993 <h3 id="_format_and_scan">format and scan</h3>
2994 <div class="paragraph"><p><code>format %c</code> allows a unicode codepoint to be be encoded. For example, the following will return
2995 a string with two bytes and one character. The same as <code>\ub5</code></p></div>
2996 <div class="literalblock">
2997 <div class="content">
2998 <pre><code>format %c 0xb5</code></pre>
2999 </div></div>
3000 <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
3001 return a string with three characters, not three bytes.</p></div>
3002 <div class="literalblock">
3003 <div class="content">
3004 <pre><code>format %.3s \ub5\ub6\ub7\ub8</code></pre>
3005 </div></div>
3006 <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
3007 <code><em>a</em></code> to 181 (0xb5) and <code><em>b</em></code> to 65 (0x41).</p></div>
3008 <div class="literalblock">
3009 <div class="content">
3010 <pre><code>scan \u00b5A %c%c a b</code></pre>
3011 </div></div>
3012 <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>
3013 </div>
3014 <div class="sect2">
3015 <h3 id="_string_classes">String Classes</h3>
3016 <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
3017 will return 0, even though the string may be considered to be alphabetic.</p></div>
3018 <div class="literalblock">
3019 <div class="content">
3020 <pre><code>string is alpha \ub5Test</code></pre>
3021 </div></div>
3022 <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>
3023 </div>
3024 <div class="sect2">
3025 <h3 id="_case_mapping_and_conversion">Case Mapping and Conversion</h3>
3026 <div class="paragraph"><p>Jim provides a simplified unicode case mapping. This means that case conversion
3027 and comparison will not increase or decrease the number of characters in a string.
3028 (Although it may change the number of bytes).</p></div>
3029 <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.
3030 Any character which is not a letter or has no uppercase equivalent is left unchanged.
3031 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>
3032 <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>
3033 and <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-nocase</code> fold both strings to uppercase before comparison.</p></div>
3034 </div>
3035 <div class="sect2">
3036 <h3 id="_invalid_utf_8_sequences">Invalid UTF-8 Sequences</h3>
3037 <div class="paragraph"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
3038 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
3039 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
3040 <div class="paragraph"><p>In these situations, the offending bytes are treated as single characters. For example,
3041 the following returns 2.</p></div>
3042 <div class="literalblock">
3043 <div class="content">
3044 <pre><code>string bytelength \xff\xff</code></pre>
3045 </div></div>
3046 </div>
3047 <div class="sect2">
3048 <h3 id="_regular_expressions_2">Regular Expressions</h3>
3049 <div class="paragraph"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
3050 selected which supports UTF-8 strings and patterns.</p></div>
3051 <div class="paragraph"><p>See REGULAR EXPRESSIONS</p></div>
3052 </div>
3053 </div>
3054 </div>
3055 <div class="sect1">
3056 <h2 id="_built_in_commands">BUILT-IN COMMANDS</h2>
3057 <div class="sectionbody">
3058 <div class="paragraph"><p>The Tcl library provides the following built-in commands, which will
3059 be available in any application using Tcl. In addition to these
3060 built-in commands, there may be additional commands defined by each
3061 application, plus commands defined as Tcl procedures.</p></div>
3062 <div class="paragraph"><p>In the command syntax descriptions below, words in <code><strong>boldface</strong></code> are
3063 literals that you type verbatim to Tcl.</p></div>
3064 <div class="paragraph"><p>Words in <code><em>italics</em></code> are meta-symbols; they serve as names for any of
3065 a range of values that you can type.</p></div>
3066 <div class="paragraph"><p>Optional arguments or groups of arguments are indicated by enclosing them
3067 in <code>?question-marks?</code>.</p></div>
3068 <div class="paragraph"><p>Ellipses (<code>...</code>) indicate that any number of additional
3069 arguments or groups of arguments may appear, in the same format
3070 as the preceding argument(s).</p></div>
3071 <div class="sect2">
3072 <h3 id="CommandIndex">Command Index</h3>
3073 <div class="tableblock">
3074 <table rules="none"
3075 width="100%"
3076 frame="void"
3077 cellspacing="0" cellpadding="4">
3078 <col width="12%" />
3079 <col width="12%" />
3080 <col width="12%" />
3081 <col width="12%" />
3082 <col width="12%" />
3083 <col width="12%" />
3084 <col width="12%" />
3085 <col width="12%" />
3086 <tbody>
3087 <tr>
3088 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>after</code></strong></a></p></td>
3089 <td align="left" valign="top"><p class="table"><a href="#_aio"><strong><code>aio</code></strong></a></p></td>
3090 <td align="left" valign="top"><p class="table"><a href="#_alarm"><strong><code>alarm</code></strong></a></p></td>
3091 <td align="left" valign="top"><p class="table"><a href="#_alias"><strong><code>alias</code></strong></a></p></td>
3092 <td align="left" valign="top"><p class="table"><a href="#_append"><strong><code>append</code></strong></a></p></td>
3093 <td align="left" valign="top"><p class="table"><a href="#_apply"><strong><code>apply</code></strong></a></p></td>
3094 <td align="left" valign="top"><p class="table"><a href="#_array"><strong><code>array</code></strong></a></p></td>
3095 <td align="left" valign="top"><p class="table"><a href="#_binary"><strong><code>binary</code></strong></a></p></td>
3096 </tr>
3097 <tr>
3098 <td align="left" valign="top"><p class="table"><a href="#_break"><strong><code>break</code></strong></a></p></td>
3099 <td align="left" valign="top"><p class="table"><a href="#_case"><strong><code>case</code></strong></a></p></td>
3100 <td align="left" valign="top"><p class="table"><a href="#_catch"><strong><code>catch</code></strong></a></p></td>
3101 <td align="left" valign="top"><p class="table"><a href="#_cd"><strong><code>cd</code></strong></a></p></td>
3102 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>class</code></strong></a></p></td>
3103 <td align="left" valign="top"><p class="table"><a href="#_clock"><strong><code>clock</code></strong></a></p></td>
3104 <td align="left" valign="top"><p class="table"><a href="#_close"><strong><code>close</code></strong></a></p></td>
3105 <td align="left" valign="top"><p class="table"><a href="#_collect"><strong><code>collect</code></strong></a></p></td>
3106 </tr>
3107 <tr>
3108 <td align="left" valign="top"><p class="table"><a href="#_concat"><strong><code>concat</code></strong></a></p></td>
3109 <td align="left" valign="top"><p class="table"><a href="#_continue"><strong><code>continue</code></strong></a></p></td>
3110 <td align="left" valign="top"><p class="table"><a href="#_curry"><strong><code>curry</code></strong></a></p></td>
3111 <td align="left" valign="top"><p class="table"><a href="#_dict"><strong><code>dict</code></strong></a></p></td>
3112 <td align="left" valign="top"><p class="table"><a href="#_env"><strong><code>env</code></strong></a></p></td>
3113 <td align="left" valign="top"><p class="table"><a href="#_eof"><strong><code>eof</code></strong></a></p></td>
3114 <td align="left" valign="top"><p class="table"><a href="#_error"><strong><code>error</code></strong></a></p></td>
3115 <td align="left" valign="top"><p class="table"><a href="#_eval"><strong><code>eval</code></strong></a></p></td>
3116 </tr>
3117 <tr>
3118 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>eventloop</code></strong></a></p></td>
3119 <td align="left" valign="top"><p class="table"><a href="#_exec"><strong><code>exec</code></strong></a></p></td>
3120 <td align="left" valign="top"><p class="table"><a href="#_exists"><strong><code>exists</code></strong></a></p></td>
3121 <td align="left" valign="top"><p class="table"><a href="#_exit"><strong><code>exit</code></strong></a></p></td>
3122 <td align="left" valign="top"><p class="table"><a href="#_expr"><strong><code>expr</code></strong></a></p></td>
3123 <td align="left" valign="top"><p class="table"><a href="#_fconfigure"><strong><code>fconfigure</code></strong></a></p></td>
3124 <td align="left" valign="top"><p class="table"><a href="#_file"><strong><code>file</code></strong></a></p></td>
3125 <td align="left" valign="top"><p class="table"><a href="#_finalize"><strong><code>finalize</code></strong></a></p></td>
3126 </tr>
3127 <tr>
3128 <td align="left" valign="top"><p class="table"><a href="#_flush"><strong><code>flush</code></strong></a></p></td>
3129 <td align="left" valign="top"><p class="table"><a href="#_for"><strong><code>for</code></strong></a></p></td>
3130 <td align="left" valign="top"><p class="table"><a href="#_foreach"><strong><code>foreach</code></strong></a></p></td>
3131 <td align="left" valign="top"><p class="table"><a href="#_format"><strong><code>format</code></strong></a></p></td>
3132 <td align="left" valign="top"><p class="table"><a href="#_getref"><strong><code>getref</code></strong></a></p></td>
3133 <td align="left" valign="top"><p class="table"><a href="#_gets"><strong><code>gets</code></strong></a></p></td>
3134 <td align="left" valign="top"><p class="table"><a href="#_glob"><strong><code>glob</code></strong></a></p></td>
3135 <td align="left" valign="top"><p class="table"><a href="#_global"><strong><code>global</code></strong></a></p></td>
3136 </tr>
3137 <tr>
3138 <td align="left" valign="top"><p class="table"><a href="#_history"><strong><code>history</code></strong></a></p></td>
3139 <td align="left" valign="top"><p class="table"><a href="#_if"><strong><code>if</code></strong></a></p></td>
3140 <td align="left" valign="top"><p class="table"><a href="#_incr"><strong><code>incr</code></strong></a></p></td>
3141 <td align="left" valign="top"><p class="table"><a href="#_info"><strong><code>info</code></strong></a></p></td>
3142 <td align="left" valign="top"><p class="table"><a href="#_join"><strong><code>join</code></strong></a></p></td>
3143 <td align="left" valign="top"><p class="table"><a href="#_kill"><strong><code>kill</code></strong></a></p></td>
3144 <td align="left" valign="top"><p class="table"><a href="#_lambda"><strong><code>lambda</code></strong></a></p></td>
3145 <td align="left" valign="top"><p class="table"><a href="#_lappend"><strong><code>lappend</code></strong></a></p></td>
3146 </tr>
3147 <tr>
3148 <td align="left" valign="top"><p class="table"><a href="#_lassign"><strong><code>lassign</code></strong></a></p></td>
3149 <td align="left" valign="top"><p class="table"><a href="#_lindex"><strong><code>lindex</code></strong></a></p></td>
3150 <td align="left" valign="top"><p class="table"><a href="#_linsert"><strong><code>linsert</code></strong></a></p></td>
3151 <td align="left" valign="top"><p class="table"><a href="#_list"><strong><code>list</code></strong></a></p></td>
3152 <td align="left" valign="top"><p class="table"><a href="#_llength"><strong><code>llength</code></strong></a></p></td>
3153 <td align="left" valign="top"><p class="table"><a href="#_lmap"><strong><code>lmap</code></strong></a></p></td>
3154 <td align="left" valign="top"><p class="table"><a href="#_load"><strong><code>load</code></strong></a></p></td>
3155 <td align="left" valign="top"><p class="table"><a href="#_local"><strong><code>local</code></strong></a></p></td>
3156 </tr>
3157 <tr>
3158 <td align="left" valign="top"><p class="table"><a href="#_loop"><strong><code>loop</code></strong></a></p></td>
3159 <td align="left" valign="top"><p class="table"><a href="#_lrange"><strong><code>lrange</code></strong></a></p></td>
3160 <td align="left" valign="top"><p class="table"><a href="#_lrepeat"><strong><code>lrepeat</code></strong></a></p></td>
3161 <td align="left" valign="top"><p class="table"><a href="#_lreplace"><strong><code>lreplace</code></strong></a></p></td>
3162 <td align="left" valign="top"><p class="table"><a href="#_lreverse"><strong><code>lreverse</code></strong></a></p></td>
3163 <td align="left" valign="top"><p class="table"><a href="#_lsearch"><strong><code>lsearch</code></strong></a></p></td>
3164 <td align="left" valign="top"><p class="table"><a href="#_lset"><strong><code>lset</code></strong></a></p></td>
3165 <td align="left" valign="top"><p class="table"><a href="#_lsort"><strong><code>lsort</code></strong></a></p></td>
3166 </tr>
3167 <tr>
3168 <td align="left" valign="top"><p class="table"><a href="#_namespace"><strong><code>namespace</code></strong></a></p></td>
3169 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>oo</code></strong></a></p></td>
3170 <td align="left" valign="top"><p class="table"><a href="#_open"><strong><code>open</code></strong></a></p></td>
3171 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.fork</code></strong></a></p></td>
3172 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.gethostname</code></strong></a></p></td>
3173 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.getids</code></strong></a></p></td>
3174 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.uptime</code></strong></a></p></td>
3175 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.wait</code></strong></a></p></td>
3176 </tr>
3177 <tr>
3178 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3179 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3180 <td align="left" valign="top"><p class="table"><a href="#_package"><strong><code>package</code></strong></a></p></td>
3181 <td align="left" valign="top"><p class="table"><a href="#_pid"><strong><code>pid</code></strong></a></p></td>
3182 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>posix</code></strong></a></p></td>
3183 <td align="left" valign="top"><p class="table"><a href="#_proc"><strong><code>proc</code></strong></a></p></td>
3184 <td align="left" valign="top"><p class="table"><a href="#_puts"><strong><code>puts</code></strong></a></p></td>
3185 <td align="left" valign="top"><p class="table"><a href="#_pwd"><strong><code>pwd</code></strong></a></p></td>
3186 </tr>
3187 <tr>
3188 <td align="left" valign="top"><p class="table"><a href="#_rand"><strong><code>rand</code></strong></a></p></td>
3189 <td align="left" valign="top"><p class="table"><a href="#_range"><strong><code>range</code></strong></a></p></td>
3190 <td align="left" valign="top"><p class="table"><a href="#_read"><strong><code>read</code></strong></a></p></td>
3191 <td align="left" valign="top"><p class="table"><a href="#_ref"><strong><code>ref</code></strong></a></p></td>
3192 <td align="left" valign="top"><p class="table"><a href="#_regexp"><strong><code>regexp</code></strong></a></p></td>
3193 <td align="left" valign="top"><p class="table"><a href="#_regsub"><strong><code>regsub</code></strong></a></p></td>
3194 <td align="left" valign="top"><p class="table"><a href="#_rename"><strong><code>rename</code></strong></a></p></td>
3195 <td align="left" valign="top"><p class="table"><a href="#_return"><strong><code>return</code></strong></a></p></td>
3196 </tr>
3197 <tr>
3198 <td align="left" valign="top"><p class="table"><a href="#_scan"><strong><code>scan</code></strong></a></p></td>
3199 <td align="left" valign="top"><p class="table"><a href="#_seek"><strong><code>seek</code></strong></a></p></td>
3200 <td align="left" valign="top"><p class="table"><a href="#_set"><strong><code>set</code></strong></a></p></td>
3201 <td align="left" valign="top"><p class="table"><a href="#_setref"><strong><code>setref</code></strong></a></p></td>
3202 <td align="left" valign="top"><p class="table"><a href="#_signal"><strong><code>signal</code></strong></a></p></td>
3203 <td align="left" valign="top"><p class="table"><a href="#_sleep"><strong><code>sleep</code></strong></a></p></td>
3204 <td align="left" valign="top"><p class="table"><a href="#_socket"><strong><code>socket</code></strong></a></p></td>
3205 <td align="left" valign="top"><p class="table"><a href="#_source"><strong><code>source</code></strong></a></p></td>
3206 </tr>
3207 <tr>
3208 <td align="left" valign="top"><p class="table"><a href="#_split"><strong><code>split</code></strong></a></p></td>
3209 <td align="left" valign="top"><p class="table"><a href="#_stackdump"><strong><code>stackdump</code></strong></a></p></td>
3210 <td align="left" valign="top"><p class="table"><a href="#_stacktrace"><strong><code>stacktrace</code></strong></a></p></td>
3211 <td align="left" valign="top"><p class="table"><a href="#_string"><strong><code>string</code></strong></a></p></td>
3212 <td align="left" valign="top"><p class="table"><a href="#_subst"><strong><code>subst</code></strong></a></p></td>
3213 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>super</code></strong></a></p></td>
3214 <td align="left" valign="top"><p class="table"><a href="#_switch"><strong><code>switch</code></strong></a></p></td>
3215 <td align="left" valign="top"><p class="table"><a href="#_syslog"><strong><code>syslog</code></strong></a></p></td>
3216 </tr>
3217 <tr>
3218 <td align="left" valign="top"><p class="table"><a href="#_tailcall"><strong><code>tailcall</code></strong></a></p></td>
3219 <td align="left" valign="top"><p class="table"><a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a></p></td>
3220 <td align="left" valign="top"><p class="table"><a href="#_tell"><strong><code>tell</code></strong></a></p></td>
3221 <td align="left" valign="top"><p class="table"><a href="#_throw"><strong><code>throw</code></strong></a></p></td>
3222 <td align="left" valign="top"><p class="table"><a href="#_time"><strong><code>time</code></strong></a></p></td>
3223 <td align="left" valign="top"><p class="table"><a href="#_tree"><strong><code>tree</code></strong></a></p></td>
3224 <td align="left" valign="top"><p class="table"><a href="#_try"><strong><code>try</code></strong></a></p></td>
3225 <td align="left" valign="top"><p class="table"><a href="#_unknown"><strong><code>unknown</code></strong></a></p></td>
3226 </tr>
3227 <tr>
3228 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>unpack</code></strong></a></p></td>
3229 <td align="left" valign="top"><p class="table"><a href="#_unset"><strong><code>unset</code></strong></a></p></td>
3230 <td align="left" valign="top"><p class="table"><a href="#_upcall"><strong><code>upcall</code></strong></a></p></td>
3231 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>update</code></strong></a></p></td>
3232 <td align="left" valign="top"><p class="table"><a href="#_uplevel"><strong><code>uplevel</code></strong></a></p></td>
3233 <td align="left" valign="top"><p class="table"><a href="#_upvar"><strong><code>upvar</code></strong></a></p></td>
3234 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>vwait</code></strong></a></p></td>
3235 <td align="left" valign="top"><p class="table"><a href="#_while"><strong><code>while</code></strong></a></p></td>
3236 </tr>
3237 </tbody>
3238 </table>
3239 </div>
3240 </div>
3241 <div class="sect2">
3242 <h3 id="_alarm">alarm</h3>
3243 <div class="paragraph"><p><code><strong>alarm</strong> <em>seconds</em></code></p></div>
3244 <div class="paragraph"><p>Delivers the <code>SIGALRM</code> signal to the process after the given
3245 number of seconds. If the platform supports <em>ualarm(3)</em> then
3246 the argument may be a floating point value. Otherwise it must
3247 be an integer.</p></div>
3248 <div class="paragraph"><p>Note that unless a signal handler for <code>SIGALRM</code> has been installed
3249 (see <a href="#_signal"><strong><code>signal</code></strong></a>), the process will exit on this signal.</p></div>
3250 </div>
3251 <div class="sect2">
3252 <h3 id="_alias">alias</h3>
3253 <div class="paragraph"><p><code><strong>alias</strong> <em>name args...</em></code></p></div>
3254 <div class="paragraph"><p>Creates a single word alias (command) for one or more words. For example,
3255 the following creates an alias for the command <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>.</p></div>
3256 <div class="literalblock">
3257 <div class="content">
3258 <pre><code>alias e info exists
3259 if {[e var]} {
3261 }</code></pre>
3262 </div></div>
3263 <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>
3264 <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>
3265 </div>
3266 <div class="sect2">
3267 <h3 id="_append">append</h3>
3268 <div class="paragraph"><p><code><strong>append</strong> <em>varName value ?value value &#8230;?</em></code></p></div>
3269 <div class="paragraph"><p>Append all of the <code><em>value</em></code> arguments to the current value
3270 of variable <code><em>varName</em></code>. If <code><em>varName</em></code> doesn&#8217;t exist,
3271 it is given a value equal to the concatenation of all the
3272 <code><em>value</em></code> arguments.</p></div>
3273 <div class="paragraph"><p>This command provides an efficient way to build up long
3274 variables incrementally.
3275 For example, "<a href="#_append"><strong><code>append</code></strong></a> <code>a $b</code>" is much more efficient than
3276 "<a href="#_set"><strong><code>set</code></strong></a> <code>a $a$b</code>" if <code>$a</code> is long.</p></div>
3277 </div>
3278 <div class="sect2">
3279 <h3 id="_apply">apply</h3>
3280 <div class="paragraph"><p><code><strong>apply</strong> <em>lambdaExpr ?arg1 arg2 ...?</em></code></p></div>
3281 <div class="paragraph"><p>The command <a href="#_apply"><strong><code>apply</code></strong></a> provides for anonymous procedure calls,
3282 similar to <a href="#_lambda"><strong><code>lambda</code></strong></a>, but without command name being created, even temporarily.</p></div>
3283 <div class="paragraph"><p>The function <code><em>lambdaExpr</em></code> is a two element list <code>{args body}</code>
3284 or a three element list <code>{args body namespace}</code>. The first element
3285 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>
3286 </div>
3287 <div class="sect2">
3288 <h3 id="_array">array</h3>
3289 <div class="paragraph"><p><code><strong>array</strong> <em>option arrayName ?arg...?</em></code></p></div>
3290 <div class="paragraph"><p>This command performs one of several operations on the
3291 variable given by <code><em>arrayName</em></code>.</p></div>
3292 <div class="paragraph"><p>Note that in general, if the named array does not exist, the <code><em>array</em></code> command behaves
3293 as though the array exists but is empty.</p></div>
3294 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3295 command. The legal <code><em>options</em></code> (which may be abbreviated) are:</p></div>
3296 <div class="dlist"><dl>
3297 <dt class="hdlist1">
3298 <code><strong>array exists</strong> <em>arrayName</em></code>
3299 </dt>
3300 <dd>
3302 Returns 1 if arrayName is an array variable, 0 if there is
3303 no variable by that name. This command is essentially
3304 identical to <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>
3305 </p>
3306 </dd>
3307 <dt class="hdlist1">
3308 <code><strong>array get</strong> <em>arrayName ?pattern?</em></code>
3309 </dt>
3310 <dd>
3312 Returns a list containing pairs of elements. The first
3313 element in each pair is the name of an element in arrayName
3314 and the second element of each pair is the value of the
3315 array element. The order of the pairs is undefined. If
3316 pattern is not specified, then all of the elements of the
3317 array are included in the result. If pattern is specified,
3318 then only those elements whose names match pattern (using
3319 the matching rules of string match) are included. If arrayName
3320 isn&#8217;t the name of an array variable, or if the array contains
3321 no elements, then an empty list is returned.
3322 </p>
3323 </dd>
3324 <dt class="hdlist1">
3325 <code><strong>array names</strong> <em>arrayName ?pattern?</em></code>
3326 </dt>
3327 <dd>
3329 Returns a list containing the names of all of the elements
3330 in the array that match pattern. If pattern is omitted then
3331 the command returns all of the element names in the array.
3332 If pattern is specified, then only those elements whose
3333 names match pattern (using the matching rules of string
3334 match) are included. If there are no (matching) elements
3335 in the array, or if arrayName isn&#8217;t the name of an array
3336 variable, then an empty string is returned.
3337 </p>
3338 </dd>
3339 <dt class="hdlist1">
3340 <code><strong>array set</strong> <em>arrayName list</em></code>
3341 </dt>
3342 <dd>
3344 Sets the values of one or more elements in arrayName. list
3345 must have a form like that returned by array get, consisting
3346 of an even number of elements. Each odd-numbered element
3347 in list is treated as an element name within arrayName, and
3348 the following element in list is used as a new value for
3349 that array element. If the variable arrayName does not
3350 already exist and list is empty, arrayName is created with
3351 an empty array value.
3352 </p>
3353 </dd>
3354 <dt class="hdlist1">
3355 <code><strong>array size</strong> <em>arrayName</em></code>
3356 </dt>
3357 <dd>
3359 Returns the number of elements in the array. If arrayName
3360 isn&#8217;t the name of an array then 0 is returned.
3361 </p>
3362 </dd>
3363 <dt class="hdlist1">
3364 <code><strong>array unset</strong> <em>arrayName ?pattern?</em></code>
3365 </dt>
3366 <dd>
3368 Unsets all of the elements in the array that match pattern
3369 (using the matching rules of string match). If arrayName
3370 isn&#8217;t the name of an array variable or there are no matching
3371 elements in the array, no error will be raised. If pattern
3372 is omitted and arrayName is an array variable, then the
3373 command unsets the entire array. The command always returns
3374 an empty string.
3375 </p>
3376 </dd>
3377 </dl></div>
3378 </div>
3379 <div class="sect2">
3380 <h3 id="_break">break</h3>
3381 <div class="paragraph"><p><code><strong>break</strong></code></p></div>
3382 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command
3383 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
3384 to signal the innermost containing loop command to return immediately.</p></div>
3385 </div>
3386 <div class="sect2">
3387 <h3 id="_case">case</h3>
3388 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? <em>patList body ?patList body &#8230;?</em></code></p></div>
3389 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? {<em>patList body ?patList body &#8230;?</em>}</code></p></div>
3390 <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
3391 with Tcl 6.x is desired.</p></div>
3392 <div class="paragraph"><p>Match <code><em>string</em></code> against each of the <code><em>patList</em></code> arguments
3393 in order. If one matches, then evaluate the following <code><em>body</em></code> argument
3394 by passing it recursively to the Tcl interpreter, and return the result
3395 of that evaluation. Each <code><em>patList</em></code> argument consists of a single
3396 pattern or list of patterns. Each pattern may contain any of the wild-cards
3397 described under <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.</p></div>
3398 <div class="paragraph"><p>If a <code><em>patList</em></code> argument is <code>default</code>, the corresponding body will be
3399 evaluated if no <code><em>patList</em></code> matches <code><em>string</em></code>. If no <code><em>patList</em></code> argument
3400 matches <code><em>string</em></code> and no default is given, then the <a href="#_case"><strong><code>case</code></strong></a> command returns
3401 an empty string.</p></div>
3402 <div class="paragraph"><p>Two syntaxes are provided.</p></div>
3403 <div class="paragraph"><p>The first uses a separate argument for each of the patterns and commands;
3404 this form is convenient if substitutions are desired on some of the
3405 patterns or commands.</p></div>
3406 <div class="paragraph"><p>The second form places all of the patterns and commands together into
3407 a single argument; the argument must have proper list structure, with
3408 the elements of the list being the patterns and commands.</p></div>
3409 <div class="paragraph"><p>The second form makes it easy to construct multi-line case commands,
3410 since the braces around the whole list make it unnecessary to include a
3411 backslash at the end of each line.</p></div>
3412 <div class="paragraph"><p>Since the <code><em>patList</em></code> arguments are in braces in the second form,
3413 no command or variable substitutions are performed on them; this makes
3414 the behaviour of the second form different than the first form in some
3415 cases.</p></div>
3416 <div class="paragraph"><p>Below are some examples of <a href="#_case"><strong><code>case</code></strong></a> commands:</p></div>
3417 <div class="literalblock">
3418 <div class="content">
3419 <pre><code>case abc in {a b} {format 1} default {format 2} a* {format 3}</code></pre>
3420 </div></div>
3421 <div class="paragraph"><p>will return <em>3</em>,</p></div>
3422 <div class="literalblock">
3423 <div class="content">
3424 <pre><code>case a in {
3425 {a b} {format 1}
3426 default {format 2}
3427 a* {format 3}
3428 }</code></pre>
3429 </div></div>
3430 <div class="paragraph"><p>will return <em>1</em>, and</p></div>
3431 <div class="literalblock">
3432 <div class="content">
3433 <pre><code>case xyz {
3434 {a b}
3435 {format 1}
3436 default
3437 {format 2}
3439 {format 3}
3440 }</code></pre>
3441 </div></div>
3442 <div class="paragraph"><p>will return <em>2</em>.</p></div>
3443 </div>
3444 <div class="sect2">
3445 <h3 id="_catch">catch</h3>
3446 <div class="paragraph"><p><code><strong>catch</strong> ?-?no?<em>code ...</em>? ?--? <em>command ?resultVarName? ?optionsVarName?</em></code></p></div>
3447 <div class="paragraph"><p>The <a href="#_catch"><strong><code>catch</code></strong></a> command may be used to prevent errors from aborting
3448 command interpretation. <a href="#_catch"><strong><code>catch</code></strong></a> evaluates <code><em>command</em></code>, and returns a
3449 <code>JIM_OK</code> code, regardless of any errors that might occur while
3450 executing <code><em>command</em></code> (with the possible exception of <code>JIM_SIGNAL</code> -
3451 see below).</p></div>
3452 <div class="paragraph"><p>The return value from <a href="#_catch"><strong><code>catch</code></strong></a> is a decimal string giving the code
3453 returned by the Tcl interpreter after executing <code><em>command</em></code>. This
3454 will be <em>0</em> (<code>JIM_OK</code>) if there were no errors in <code><em>command</em></code>; otherwise
3455 it will have a non-zero value corresponding to one of the exceptional
3456 return codes (see jim.h for the definitions of code values, or the
3457 <a href="#_info"><strong><code>info</code></strong></a> <code>returncodes</code> command).</p></div>
3458 <div class="paragraph"><p>If the <code><em>resultVarName</em></code> argument is given, then it gives the name
3459 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to the
3460 string returned from <code><em>command</em></code> (either a result or an error message).</p></div>
3461 <div class="paragraph"><p>If the <code><em>optionsVarName</em></code> argument is given, then it gives the name
3462 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to a
3463 dictionary. For any return code other than <code>JIM_RETURN</code>, the value
3464 for the key <code>-code</code> will be set to the return code. For <code>JIM_RETURN</code>
3465 it will be set to the code given in <a href="#_return"><strong><code>return</code></strong></a> <code>-code</code>. Additionally,
3466 for the return code <code>JIM_ERR</code>, the value of the key <code>-errorinfo</code>
3467 will contain the current stack trace (the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code>),
3468 the value of the key <code>-errorcode</code> will contain the
3469 same value as the global variable $::errorCode, and the value of
3470 the key <code>-level</code> will be the current return level (see <a href="#_return"><strong><code>return</code></strong></a> <code>-level</code>).
3471 This can be useful to rethrow an error:</p></div>
3472 <div class="literalblock">
3473 <div class="content">
3474 <pre><code>if {[catch {...} msg opts]} {
3475 ...maybe do something with the error...
3476 incr opts(-level)
3477 return {*}$opts $msg
3478 }</code></pre>
3479 </div></div>
3480 <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>.
3481 The set of codes which will be caught may be modified by specifying the one more codes before
3482 <code><em>command</em></code>.</p></div>
3483 <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>
3484 <div class="literalblock">
3485 <div class="content">
3486 <pre><code>catch -exit -nobreak -nocontinue -- { ... }</code></pre>
3487 </div></div>
3488 <div class="paragraph"><p>The use of <code>--</code> is optional. It signifies that no more return code options follow.</p></div>
3489 <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
3490 (stored in <code><em>resultVarName</em></code>) is name of the signal caught.</p></div>
3491 </div>
3492 <div class="sect2">
3493 <h3 id="_cd">cd</h3>
3494 <div class="paragraph"><p><code><strong>cd</strong> <em>dirName</em></code></p></div>
3495 <div class="paragraph"><p>Change the current working directory to <code><em>dirName</em></code>.</p></div>
3496 <div class="paragraph"><p>Returns an empty string.</p></div>
3497 <div class="paragraph"><p>This command can potentially be disruptive to an application, so it may
3498 be removed in some applications.</p></div>
3499 </div>
3500 <div class="sect2">
3501 <h3 id="_clock">clock</h3>
3502 <div class="dlist"><dl>
3503 <dt class="hdlist1">
3504 <code><strong>clock seconds</strong></code>
3505 </dt>
3506 <dd>
3508 Returns the current time as seconds since the epoch.
3509 </p>
3510 </dd>
3511 <dt class="hdlist1">
3512 <code><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em></code>
3513 </dt>
3514 <dd>
3516 Format the given time (seconds since the epoch) according to the given
3517 format. See strftime(3) for supported formats.
3518 If no format is supplied, "%c" is used.
3519 </p>
3520 </dd>
3521 <dt class="hdlist1">
3522 <code><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em></code>
3523 </dt>
3524 <dd>
3526 Scan the given time string using the given format string.
3527 See strptime(3) for supported formats.
3528 </p>
3529 </dd>
3530 </dl></div>
3531 </div>
3532 <div class="sect2">
3533 <h3 id="_close">close</h3>
3534 <div class="paragraph"><p><code><strong>close</strong> <em>fileId</em></code></p></div>
3535 <div class="paragraph"><p><code><em>fileId</em> <strong>close</strong></code></p></div>
3536 <div class="paragraph"><p>Closes the file given by <code><em>fileId</em></code>.
3537 <code><em>fileId</em></code> must be the return value from a previous invocation
3538 of the <a href="#_open"><strong><code>open</code></strong></a> command; after this command, it should not be
3539 used anymore.</p></div>
3540 </div>
3541 <div class="sect2">
3542 <h3 id="_collect">collect</h3>
3543 <div class="paragraph"><p><code><strong>collect</strong></code></p></div>
3544 <div class="paragraph"><p>Normally reference garbage collection is automatically performed periodically.
3545 However it may be run immediately with the <a href="#_collect"><strong><code>collect</code></strong></a> command.</p></div>
3546 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
3547 </div>
3548 <div class="sect2">
3549 <h3 id="_concat">concat</h3>
3550 <div class="paragraph"><p><code><strong>concat</strong> <em>arg ?arg ...?</em></code></p></div>
3551 <div class="paragraph"><p>This command treats each argument as a list and concatenates them
3552 into a single list. It permits any number of arguments. For example,
3553 the command</p></div>
3554 <div class="literalblock">
3555 <div class="content">
3556 <pre><code>concat a b {c d e} {f {g h}}</code></pre>
3557 </div></div>
3558 <div class="paragraph"><p>will return</p></div>
3559 <div class="literalblock">
3560 <div class="content">
3561 <pre><code>a b c d e f {g h}</code></pre>
3562 </div></div>
3563 <div class="paragraph"><p>as its result.</p></div>
3564 </div>
3565 <div class="sect2">
3566 <h3 id="_continue">continue</h3>
3567 <div class="paragraph"><p><code><strong>continue</strong></code></p></div>
3568 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command such
3569 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
3570 signal the innermost containing loop command to skip the remainder of
3571 the loop&#8217;s body but continue with the next iteration of the loop.</p></div>
3572 </div>
3573 <div class="sect2">
3574 <h3 id="_curry">curry</h3>
3575 <div class="paragraph"><p><code><strong>alias</strong> <em>args...</em></code></p></div>
3576 <div class="paragraph"><p>Similar to <a href="#_alias"><strong><code>alias</code></strong></a> except it creates an anonymous procedure (lambda) instead of
3577 a named procedure.</p></div>
3578 <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>
3579 <div class="literalblock">
3580 <div class="content">
3581 <pre><code>set e [local curry info exists]
3582 if {[$e var]} {
3584 }</code></pre>
3585 </div></div>
3586 <div class="paragraph"><p><a href="#_curry"><strong><code>curry</code></strong></a> returns the name of the procedure.</p></div>
3587 <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>
3588 </div>
3589 <div class="sect2">
3590 <h3 id="_dict">dict</h3>
3591 <div class="paragraph"><p><code><strong>dict</strong> <em>option ?arg...?</em></code></p></div>
3592 <div class="paragraph"><p>Performs one of several operations on dictionary values.</p></div>
3593 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3594 command. The legal <code><em>options</em></code> are:</p></div>
3595 <div class="dlist"><dl>
3596 <dt class="hdlist1">
3597 <code><strong>dict create</strong> <em>?key value ...?</em></code>
3598 </dt>
3599 <dd>
3601 Create and return a new dictionary value that contains each of
3602 the key/value mappings listed as arguments (keys and values
3603 alternating, with each key being followed by its associated
3604 value.)
3605 </p>
3606 </dd>
3607 <dt class="hdlist1">
3608 <code><strong>dict exists</strong> <em>dictionary key ?key ...?</em></code>
3609 </dt>
3610 <dd>
3612 Returns a boolean value indicating whether the given key (or path
3613 of keys through a set of nested dictionaries) exists in the given
3614 dictionary value. This returns a true value exactly when <a href="#_dict"><strong><code>dict</code></strong></a> <code>get</code>
3615 on that path will succeed.
3616 </p>
3617 </dd>
3618 <dt class="hdlist1">
3619 <code><strong>dict get</strong> <em>dictionary ?key ...?</em></code>
3620 </dt>
3621 <dd>
3623 Given a dictionary value (first argument) and a key (second argument),
3624 this will retrieve the value for that key. Where several keys are
3625 supplied, the behaviour of the command shall be as if the result
3626 of "<a href="#_dict"><strong><code>dict</code></strong></a> <code>get $dictVal $key</code>" was passed as the first argument to
3627 dict get with the remaining arguments as second (and possibly
3628 subsequent) arguments. This facilitates lookups in nested dictionaries.
3629 If no keys are provided, dict would return a list containing pairs
3630 of elements in a man- ner similar to array get. That is, the first
3631 element of each pair would be the key and the second element would
3632 be the value for that key. It is an error to attempt to retrieve
3633 a value for a key that is not present in the dictionary.
3634 </p>
3635 </dd>
3636 <dt class="hdlist1">
3637 <code><strong>dict keys</strong> <em>dictionary ?pattern?</em></code>
3638 </dt>
3639 <dd>
3641 Returns a list of the keys in the dictionary.
3642 If pattern is specified, then only those keys whose
3643 names match <code><em>pattern</em></code> (using the matching rules of string
3644 match) are included.
3645 </p>
3646 </dd>
3647 <dt class="hdlist1">
3648 <code><strong>dict merge</strong> ?<em>dictionary ...</em>?</code>
3649 </dt>
3650 <dd>
3652 Return a dictionary that contains the contents of each of the
3653 <code><em>dictionary</em></code> arguments. Where two (or more) dictionaries
3654 contain a mapping for the same key, the resulting dictionary
3655 maps that key to the value according to the last dictionary on
3656 the command line containing a mapping for that key.
3657 </p>
3658 </dd>
3659 <dt class="hdlist1">
3660 <code><strong>dict set</strong> <em>dictionaryName key ?key ...? value</em></code>
3661 </dt>
3662 <dd>
3664 This operation takes the <code><em>name</em></code> of a variable containing a dictionary
3665 value and places an updated dictionary value in that variable
3666 containing a mapping from the given key to the given value. When
3667 multiple keys are present, this operation creates or updates a chain
3668 of nested dictionaries.
3669 </p>
3670 </dd>
3671 <dt class="hdlist1">
3672 <code><strong>dict size</strong> <em>dictionary</em></code>
3673 </dt>
3674 <dd>
3676 Return the number of key/value mappings in the given dictionary value.
3677 </p>
3678 </dd>
3679 <dt class="hdlist1">
3680 <code><strong>dict unset</strong> <em>dictionaryName key ?key ...? value</em></code>
3681 </dt>
3682 <dd>
3684 This operation (the companion to <a href="#_dict"><strong><code>dict</code></strong></a> <code>set</code>) takes the name of a
3685 variable containing a dictionary value and places an updated
3686 dictionary value in that variable that does not contain a mapping
3687 for the given key. Where multiple keys are present, this describes
3688 a path through nested dictionaries to the mapping to remove. At
3689 least one key must be specified, but the last key on the key-path
3690 need not exist. All other components on the path must exist.
3691 </p>
3692 </dd>
3693 <dt class="hdlist1">
3694 <code><strong>dict with</strong> <em>dictionaryName key ?key ...? script</em></code>
3695 </dt>
3696 <dd>
3698 Execute the Tcl script in <code><em>script</em></code> with the value for each
3699 key in <code><em>dictionaryName</em></code> mapped to a variable with the same
3700 name. Where one or more keys are given, these indicate a chain
3701 of nested dictionaries, with the innermost dictionary being the
3702 one opened out for the execution of body. Making <code><em>dictionaryName</em></code>
3703 unreadable will make the updates to the dictionary be discarded,
3704 and this also happens if the contents of <code><em>dictionaryName</em></code> are
3705 adjusted so that the chain of dictionaries no longer exists.
3706 The result of <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> is (unless some kind of error occurs)
3707 the result of the evaluation of body.
3708 </p>
3709 </dd>
3710 <dt class="hdlist1">
3712 </dt>
3713 <dd>
3715 The variables are mapped in the scope enclosing the <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code>;
3716 it is recommended that this command only be used in a local
3717 scope (procedure). Because of this, the variables set by
3718 <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> will continue to exist after the command finishes (unless
3719 explicitly unset). Note that changes to the contents of <code><em>dictionaryName</em></code>
3720 only happen when <code><em>script</em></code> terminates.
3721 </p>
3722 </dd>
3723 </dl></div>
3724 <div class="paragraph"><p><code><strong>dict for, values, incr, append, lappend, update, info, replace</strong></code> to be documented&#8230;</p></div>
3725 </div>
3726 <div class="sect2">
3727 <h3 id="_env">env</h3>
3728 <div class="paragraph"><p><code><strong>env</strong> <em>?name? ?default?</em></code></p></div>
3729 <div class="paragraph"><p>If <code><em>name</em></code> is supplied, returns the value of <code><em>name</em></code> from the initial
3730 environment (see getenv(3)). An error is returned if <code><em>name</em></code> does not
3731 exist in the environment, unless <code><em>default</em></code> is supplied - in which case
3732 that value is returned instead.</p></div>
3733 <div class="paragraph"><p>If no arguments are supplied, returns a list of all environment variables
3734 and their values as <code>{name value ...}</code></p></div>
3735 <div class="paragraph"><p>See also the global variable <code>::env</code></p></div>
3736 </div>
3737 <div class="sect2">
3738 <h3 id="_eof">eof</h3>
3739 <div class="paragraph"><p><code><strong>eof</strong> <em>fileId</em></code></p></div>
3740 <div class="paragraph"><p><code><em>fileId</em> <strong>eof</strong></code></p></div>
3741 <div class="paragraph"><p>Returns 1 if an end-of-file condition has occurred on <code><em>fileId</em></code>,
3742 0 otherwise.</p></div>
3743 <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>,
3744 or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one of the
3745 standard I/O channels.</p></div>
3746 </div>
3747 <div class="sect2">
3748 <h3 id="_error">error</h3>
3749 <div class="paragraph"><p><code><strong>error</strong> <em>message ?stacktrace?</em></code></p></div>
3750 <div class="paragraph"><p>Returns a <code>JIM_ERR</code> code, which causes command interpretation to be
3751 unwound. <code><em>message</em></code> is a string that is returned to the application
3752 to indicate what went wrong.</p></div>
3753 <div class="paragraph"><p>If the <code><em>stacktrace</em></code> argument is provided and is non-empty,
3754 it is used to initialize the stacktrace.</p></div>
3755 <div class="paragraph"><p>This feature is most useful in conjunction with the <a href="#_catch"><strong><code>catch</code></strong></a> command:
3756 if a caught error cannot be handled successfully, <code><em>stacktrace</em></code> can be used
3757 to return a stack trace reflecting the original point of occurrence
3758 of the error:</p></div>
3759 <div class="literalblock">
3760 <div class="content">
3761 <pre><code>catch {...} errMsg
3763 error $errMsg [info stacktrace]</code></pre>
3764 </div></div>
3765 <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>
3766 </div>
3767 <div class="sect2">
3768 <h3 id="_errorinfo">errorInfo</h3>
3769 <div class="paragraph"><p><code><strong>errorInfo</strong> <em>error ?stacktrace?</em></code></p></div>
3770 <div class="paragraph"><p>Returns a human-readable representation of the given error message and stack trace.
3771 Typical usage is:</p></div>
3772 <div class="literalblock">
3773 <div class="content">
3774 <pre><code>if {[catch {...} error]} {
3775 puts stderr [errorInfo $error [info stacktrace]]
3776 exit 1
3777 }</code></pre>
3778 </div></div>
3779 <div class="paragraph"><p>See also <a href="#_error"><strong><code>error</code></strong></a>.</p></div>
3780 </div>
3781 <div class="sect2">
3782 <h3 id="_eval">eval</h3>
3783 <div class="paragraph"><p><code><strong>eval</strong> <em>arg ?arg...?</em></code></p></div>
3784 <div class="paragraph"><p><a href="#_eval"><strong><code>eval</code></strong></a> takes one or more arguments, which together comprise a Tcl
3785 command (or collection of Tcl commands separated by newlines in the
3786 usual way). <a href="#_eval"><strong><code>eval</code></strong></a> concatenates all its arguments in the same
3787 fashion as the <a href="#_concat"><strong><code>concat</code></strong></a> command, passes the concatenated string to the
3788 Tcl interpreter recursively, and returns the result of that
3789 evaluation (or any error generated by it).</p></div>
3790 </div>
3791 <div class="sect2">
3792 <h3 id="_exec">exec</h3>
3793 <div class="paragraph"><p><code><strong>exec</strong> <em>arg ?arg...?</em></code></p></div>
3794 <div class="paragraph"><p>This command treats its arguments as the specification
3795 of one or more UNIX commands to execute as subprocesses.
3796 The commands take the form of a standard shell pipeline;
3797 <code>|</code> arguments separate commands in the
3798 pipeline and cause standard output of the preceding command
3799 to be piped into standard input of the next command (or <code>|&amp;</code> for
3800 both standard output and standard error).</p></div>
3801 <div class="paragraph"><p>Under normal conditions the result of the <a href="#_exec"><strong><code>exec</code></strong></a> command
3802 consists of the standard output produced by the last command
3803 in the pipeline.</p></div>
3804 <div class="paragraph"><p>If any of the commands in the pipeline exit abnormally or
3805 are killed or suspended, then <a href="#_exec"><strong><code>exec</code></strong></a> will return an error
3806 and the error message will include the pipeline&#8217;s output followed by
3807 error messages describing the abnormal terminations.</p></div>
3808 <div class="paragraph"><p>If any of the commands writes to its standard error file,
3809 then <a href="#_exec"><strong><code>exec</code></strong></a> will return an error, and the error message
3810 will include the pipeline&#8217;s output, followed by messages
3811 about abnormal terminations (if any), followed by the standard error
3812 output.</p></div>
3813 <div class="paragraph"><p>If the last character of the result or error message
3814 is a newline then that character is deleted from the result
3815 or error message for consistency with normal
3816 Tcl return values.</p></div>
3817 <div class="paragraph"><p>An <code><em>arg</em></code> may have one of the following special forms:</p></div>
3818 <div class="dlist"><dl>
3819 <dt class="hdlist1">
3820 <code>&gt;filename</code>
3821 </dt>
3822 <dd>
3824 The standard output of the last command in the pipeline
3825 is redirected to the file. In this situation <a href="#_exec"><strong><code>exec</code></strong></a>
3826 will normally return an empty string.
3827 </p>
3828 </dd>
3829 <dt class="hdlist1">
3830 <code>&gt;&gt;filename</code>
3831 </dt>
3832 <dd>
3834 As above, but append to the file.
3835 </p>
3836 </dd>
3837 <dt class="hdlist1">
3838 <code>&gt;@fileId</code>
3839 </dt>
3840 <dd>
3842 The standard output of the last command in the pipeline is
3843 redirected to the given (writable) file descriptor (e.g. stdout,
3844 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>
3845 will normally return an empty string.
3846 </p>
3847 </dd>
3848 <dt class="hdlist1">
3849 <code>2&gt;filename</code>
3850 </dt>
3851 <dd>
3853 The standard error of the last command in the pipeline
3854 is redirected to the file.
3855 </p>
3856 </dd>
3857 <dt class="hdlist1">
3858 <code>2&gt;&gt;filename</code>
3859 </dt>
3860 <dd>
3862 As above, but append to the file.
3863 </p>
3864 </dd>
3865 <dt class="hdlist1">
3866 <code>2&gt;@fileId</code>
3867 </dt>
3868 <dd>
3870 The standard error of the last command in the pipeline is
3871 redirected to the given (writable) file descriptor.
3872 </p>
3873 </dd>
3874 <dt class="hdlist1">
3875 <code>2&gt;@1</code>
3876 </dt>
3877 <dd>
3879 The standard error of the last command in the pipeline is
3880 redirected to the same file descriptor as the standard output.
3881 </p>
3882 </dd>
3883 <dt class="hdlist1">
3884 <code>&gt;&amp;filename</code>
3885 </dt>
3886 <dd>
3888 Both the standard output and standard error of the last command
3889 in the pipeline is redirected to the file.
3890 </p>
3891 </dd>
3892 <dt class="hdlist1">
3893 <code>&gt;&gt;&amp;filename</code>
3894 </dt>
3895 <dd>
3897 As above, but append to the file.
3898 </p>
3899 </dd>
3900 <dt class="hdlist1">
3901 <code>&lt;filename</code>
3902 </dt>
3903 <dd>
3905 The standard input of the first command in the pipeline
3906 is taken from the file.
3907 </p>
3908 </dd>
3909 <dt class="hdlist1">
3910 <code>&lt;&lt;string</code>
3911 </dt>
3912 <dd>
3914 The standard input of the first command is taken as the
3915 given immediate value.
3916 </p>
3917 </dd>
3918 <dt class="hdlist1">
3919 <code>&lt;@fileId</code>
3920 </dt>
3921 <dd>
3923 The standard input of the first command in the pipeline
3924 is taken from the given (readable) file descriptor.
3925 </p>
3926 </dd>
3927 </dl></div>
3928 <div class="paragraph"><p>If there is no redirection of standard input, standard error
3929 or standard output, these are connected to the corresponding
3930 input or output of the application.</p></div>
3931 <div class="paragraph"><p>If the last <code><em>arg</em></code> is <code>&amp;</code> then the command will be
3932 executed in background.
3933 In this case the standard output from the last command
3934 in the pipeline will
3935 go to the application&#8217;s standard output unless
3936 redirected in the command, and error output from all
3937 the commands in the pipeline will go to the application&#8217;s
3938 standard error file. The return value of exec in this case
3939 is a list of process ids (pids) in the pipeline.</p></div>
3940 <div class="paragraph"><p>Each <code><em>arg</em></code> becomes one word for a command, except for
3941 <code>|</code>, <code>&lt;</code>, <code>&lt;&lt;</code>, <code>&gt;</code>, and <code>&amp;</code> arguments, and the
3942 arguments that follow <code>&lt;</code>, <code>&lt;&lt;</code>, and <code>&gt;</code>.</p></div>
3943 <div class="paragraph"><p>The first word in each command is taken as the command name;
3944 the directories in the PATH environment variable are searched for
3945 an executable by the given name.</p></div>
3946 <div class="paragraph"><p>No <a href="#_glob"><strong><code>glob</code></strong></a> expansion or other shell-like substitutions
3947 are performed on the arguments to commands.</p></div>
3948 <div class="paragraph"><p>If the command fails, the global $::errorCode (and the -errorcode
3949 option in <a href="#_catch"><strong><code>catch</code></strong></a>) will be set to a list, as follows:</p></div>
3950 <div class="dlist"><dl>
3951 <dt class="hdlist1">
3952 <code><strong>CHILDKILLED</strong> <em>pid sigName msg</em></code>
3953 </dt>
3954 <dd>
3956 This format is used when a child process has been killed
3957 because of a signal. The pid element will be the process&#8217;s
3958 identifier (in decimal). The sigName element will be the
3959 symbolic name of the signal that caused the process to
3960 terminate; it will be one of the names from the include
3961 file signal.h, such as SIGPIPE. The msg element will be a
3962 short human-readable message describing the signal, such
3963 as "write on pipe with no readers" for SIGPIPE.
3964 </p>
3965 </dd>
3966 <dt class="hdlist1">
3967 <code><strong>CHILDSUSP</strong> <em>pid sigName msg</em></code>
3968 </dt>
3969 <dd>
3971 This format is used when a child process has been suspended
3972 because of a signal. The pid element will be the process&#8217;s
3973 identifier, in decimal. The sigName element will be the
3974 symbolic name of the signal that caused the process to
3975 suspend; this will be one of the names from the include
3976 file signal.h, such as SIGTTIN. The msg element will be a
3977 short human-readable message describing the signal, such
3978 as "background tty read" for SIGTTIN.
3979 </p>
3980 </dd>
3981 <dt class="hdlist1">
3982 <code><strong>CHILDSTATUS</strong> <em>pid code</em></code>
3983 </dt>
3984 <dd>
3986 This format is used when a child process has exited with a
3987 non-zero exit status. The pid element will be the process&#8217;s
3988 identifier (in decimal) and the code element will be the
3989 exit code returned by the process (also in decimal).
3990 </p>
3991 </dd>
3992 </dl></div>
3993 <div class="paragraph"><p>The environment for the executed command is set from $::env (unless
3994 this variable is unset, in which case the original environment is used).</p></div>
3995 </div>
3996 <div class="sect2">
3997 <h3 id="_exists">exists</h3>
3998 <div class="paragraph"><p><code><strong>exists ?-var|-proc|-command|-alias?</strong> <em>name</em></code></p></div>
3999 <div class="paragraph"><p>Checks the existence of the given variable, procedure, command
4000 or alias respectively and returns 1 if it exists or 0 if not. This command
4001 provides a more simplified/convenient version of <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>,
4002 <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>
4003 <div class="paragraph"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
4004 </div>
4005 <div class="sect2">
4006 <h3 id="_exit">exit</h3>
4007 <div class="paragraph"><p><code><strong>exit</strong> <em>?returnCode?</em></code></p></div>
4008 <div class="paragraph"><p>Terminate the process, returning <code><em>returnCode</em></code> to the
4009 parent as the exit status.</p></div>
4010 <div class="paragraph"><p>If <code><em>returnCode</em></code> isn&#8217;t specified then it defaults
4011 to 0.</p></div>
4012 <div class="paragraph"><p>Note that exit can be caught with <a href="#_catch"><strong><code>catch</code></strong></a>.</p></div>
4013 </div>
4014 <div class="sect2">
4015 <h3 id="_expr">expr</h3>
4016 <div class="paragraph"><p><code><strong>expr</strong> <em>arg</em></code></p></div>
4017 <div class="paragraph"><p>Calls the expression processor to evaluate <code><em>arg</em></code>, and returns
4018 the result as a string. See the section EXPRESSIONS above.</p></div>
4019 <div class="paragraph"><p>Note that Jim supports a shorthand syntax for <a href="#_expr"><strong><code>expr</code></strong></a> as <code>$(...)</code>
4020 The following two are identical.</p></div>
4021 <div class="literalblock">
4022 <div class="content">
4023 <pre><code>set x [expr {3 * 2 + 1}]
4024 set x $(3 * 2 + 1)</code></pre>
4025 </div></div>
4026 </div>
4027 <div class="sect2">
4028 <h3 id="_file">file</h3>
4029 <div class="paragraph"><p><code><strong>file</strong> <em>option name ?arg...?</em></code></p></div>
4030 <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>
4031 <div class="paragraph"><p><code><em>option</em></code> indicates what to do with the file name. Any unique
4032 abbreviation for <code><em>option</em></code> is acceptable. The valid options are:</p></div>
4033 <div class="dlist"><dl>
4034 <dt class="hdlist1">
4035 <code><strong>file atime</strong> <em>name</em></code>
4036 </dt>
4037 <dd>
4039 Return a decimal string giving the time at which file <code><em>name</em></code>
4040 was last accessed. The time is measured in the standard UNIX
4041 fashion as seconds from a fixed starting time (often January 1, 1970).
4042 If the file doesn&#8217;t exist or its access time cannot be queried then an
4043 error is generated.
4044 </p>
4045 </dd>
4046 <dt class="hdlist1">
4047 <code><strong>file copy ?-force?</strong> <em>source target</em></code>
4048 </dt>
4049 <dd>
4051 Copies file <code><em>source</em></code> to file <code><em>target</em></code>. The source file must exist.
4052 The target file must not exist, unless <code>-force</code> is specified.
4053 </p>
4054 </dd>
4055 <dt class="hdlist1">
4056 <code><strong>file delete ?-force? ?--?</strong> <em>name...</em></code>
4057 </dt>
4058 <dd>
4060 Deletes file or directory <code><em>name</em></code>. If the file or directory doesn&#8217;t exist, nothing happens.
4061 If it can&#8217;t be deleted, an error is generated. Non-empty directories will not be deleted
4062 unless the <code>-force</code> options is given. In this case no errors will be generated, even
4063 if the file/directory can&#8217;t be deleted. Use <code><em>--</em></code> if there is any possibility of
4064 the first name being <code><em>-force</em></code>.
4065 </p>
4066 </dd>
4067 <dt class="hdlist1">
4068 <code><strong>file dirname</strong> <em>name</em></code>
4069 </dt>
4070 <dd>
4072 Return all of the characters in <code><em>name</em></code> up to but not including
4073 the last slash character. If there are no slashes in <code><em>name</em></code>
4074 then return <code>.</code> (a single dot). If the last slash in <code><em>name</em></code> is its first
4075 character, then return <code>/</code>.
4076 </p>
4077 </dd>
4078 <dt class="hdlist1">
4079 <code><strong>file executable</strong> <em>name</em></code>
4080 </dt>
4081 <dd>
4083 Return <em>1</em> if file <code><em>name</em></code> is executable by
4084 the current user, <em>0</em> otherwise.
4085 </p>
4086 </dd>
4087 <dt class="hdlist1">
4088 <code><strong>file exists</strong> <em>name</em></code>
4089 </dt>
4090 <dd>
4092 Return <em>1</em> if file <code><em>name</em></code> exists and the current user has
4093 search privileges for the directories leading to it, <em>0</em> otherwise.
4094 </p>
4095 </dd>
4096 <dt class="hdlist1">
4097 <code><strong>file extension</strong> <em>name</em></code>
4098 </dt>
4099 <dd>
4101 Return all of the characters in <code><em>name</em></code> after and including the
4102 last dot in <code><em>name</em></code>. If there is no dot in <code><em>name</em></code> then return
4103 the empty string.
4104 </p>
4105 </dd>
4106 <dt class="hdlist1">
4107 <code><strong>file isdirectory</strong> <em>name</em></code>
4108 </dt>
4109 <dd>
4111 Return <em>1</em> if file <code><em>name</em></code> is a directory,
4112 <em>0</em> otherwise.
4113 </p>
4114 </dd>
4115 <dt class="hdlist1">
4116 <code><strong>file isfile</strong> <em>name</em></code>
4117 </dt>
4118 <dd>
4120 Return <em>1</em> if file <code><em>name</em></code> is a regular file,
4121 <em>0</em> otherwise.
4122 </p>
4123 </dd>
4124 <dt class="hdlist1">
4125 <code><strong>file join</strong> <em>arg...</em></code>
4126 </dt>
4127 <dd>
4129 Joins multiple path components. Note that if any components is
4130 an absolute path, the preceding components are ignored.
4131 Thus <code>"<a href="#_file"><strong><code>file</code></strong></a> join /tmp /root"</code> returns <code>"/root"</code>.
4132 </p>
4133 </dd>
4134 <dt class="hdlist1">
4135 <code><strong>file link</strong> ?<strong>-hard|-symbolic</strong>? <em>newname target</em></code>
4136 </dt>
4137 <dd>
4139 Creates a hard link (default) or symbolic link from <code><em>newname</em></code> to <code><em>target</em></code>.
4140 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>
4141 and also of <code>ln</code>, but this is compatible with Tcl.
4142 An error is returned if <code><em>target</em></code> doesn&#8217;t exist or <code><em>newname</em></code> already exists.
4143 </p>
4144 </dd>
4145 <dt class="hdlist1">
4146 <code><strong>file lstat</strong> <em>name varName</em></code>
4147 </dt>
4148 <dd>
4150 Same as <em>stat</em> option (see below) except uses the <code><em>lstat</em></code>
4151 kernel call instead of <code><em>stat</em></code>. This means that if <code><em>name</em></code>
4152 refers to a symbolic link the information returned in <code><em>varName</em></code>
4153 is for the link rather than the file it refers to. On systems that
4154 don&#8217;t support symbolic links this option behaves exactly the same
4155 as the <em>stat</em> option.
4156 </p>
4157 </dd>
4158 <dt class="hdlist1">
4159 <code><strong>file mkdir</strong> <em>dir1 ?dir2...?</em></code>
4160 </dt>
4161 <dd>
4163 Creates each directory specified. For each pathname <code><em>dir</em></code> specified,
4164 this command will create all non-existing parent directories
4165 as well as <code><em>dir</em></code> itself. If an existing directory is specified,
4166 then no action is taken and no error is returned. Trying to
4167 overwrite an existing file with a directory will result in an
4168 error. Arguments are processed in the order specified, halting
4169 at the first error, if any.
4170 </p>
4171 </dd>
4172 <dt class="hdlist1">
4173 <code><strong>file mtime</strong> <em>name ?time?</em></code>
4174 </dt>
4175 <dd>
4177 Return a decimal string giving the time at which file <code><em>name</em></code>
4178 was last modified. The time is measured in the standard UNIX
4179 fashion as seconds from a fixed starting time (often January 1, 1970).
4180 If the file doesn&#8217;t exist or its modified time cannot be queried then an
4181 error is generated. If <code><em>time</em></code> is given, sets the modification time
4182 of the file to the given value.
4183 </p>
4184 </dd>
4185 <dt class="hdlist1">
4186 <code><strong>file normalize</strong> <em>name</em></code>
4187 </dt>
4188 <dd>
4190 Return the normalized path of <code><em>name</em></code>. See <em>realpath(3)</em>.
4191 </p>
4192 </dd>
4193 <dt class="hdlist1">
4194 <code><strong>file owned</strong> <em>name</em></code>
4195 </dt>
4196 <dd>
4198 Return <em>1</em> if file <code><em>name</em></code> is owned by the current user,
4199 <em>0</em> otherwise.
4200 </p>
4201 </dd>
4202 <dt class="hdlist1">
4203 <code><strong>file readable</strong> <em>name</em></code>
4204 </dt>
4205 <dd>
4207 Return <em>1</em> if file <code><em>name</em></code> is readable by
4208 the current user, <em>0</em> otherwise.
4209 </p>
4210 </dd>
4211 <dt class="hdlist1">
4212 <code><strong>file readlink</strong> <em>name</em></code>
4213 </dt>
4214 <dd>
4216 Returns the value of the symbolic link given by <code><em>name</em></code> (i.e. the
4217 name of the file it points to). If
4218 <code><em>name</em></code> isn&#8217;t a symbolic link or its value cannot be read, then
4219 an error is returned. On systems that don&#8217;t support symbolic links
4220 this option is undefined.
4221 </p>
4222 </dd>
4223 <dt class="hdlist1">
4224 <code><strong>file rename</strong> ?<strong>-force</strong>? <em>oldname</em> <em>newname</em></code>
4225 </dt>
4226 <dd>
4228 Renames the file from the old name to the new name.
4229 If <code><em>newname</em></code> already exists, an error is returned unless <code><em>-force</em></code> is
4230 specified.
4231 </p>
4232 </dd>
4233 <dt class="hdlist1">
4234 <code><strong>file rootname</strong> <em>name</em></code>
4235 </dt>
4236 <dd>
4238 Return all of the characters in <code><em>name</em></code> up to but not including
4239 the last <em>.</em> character in the name. If <code><em>name</em></code> doesn&#8217;t contain
4240 a dot, then return <code><em>name</em></code>.
4241 </p>
4242 </dd>
4243 <dt class="hdlist1">
4244 <code><strong>file size</strong> <em>name</em></code>
4245 </dt>
4246 <dd>
4248 Return a decimal string giving the size of file <code><em>name</em></code> in bytes.
4249 If the file doesn&#8217;t exist or its size cannot be queried then an
4250 error is generated.
4251 </p>
4252 </dd>
4253 <dt class="hdlist1">
4254 <code><strong>file stat</strong> <em>name ?varName?</em></code>
4255 </dt>
4256 <dd>
4258 Invoke the <em>stat</em> kernel call on <code><em>name</em></code>, and return the result
4259 as a dictionary with the following keys: <em>atime</em>,
4260 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
4261 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>.
4262 Each element except <em>type</em> is a decimal string with the value of
4263 the corresponding field from the <em>stat</em> return structure; see the
4264 manual entry for <em>stat</em> for details on the meanings of the values.
4265 The <em>type</em> element gives the type of the file in the same form
4266 returned by the command <a href="#_file"><strong><code>file</code></strong></a> <code>type</code>.
4267 If <code><em>varName</em></code> is specified, it is taken to be the name of an array
4268 variable and the values are also stored into the array.
4269 </p>
4270 </dd>
4271 <dt class="hdlist1">
4272 <code><strong>file tail</strong> <em>name</em></code>
4273 </dt>
4274 <dd>
4276 Return all of the characters in <code><em>name</em></code> after the last slash.
4277 If <code><em>name</em></code> contains no slashes then return <code><em>name</em></code>.
4278 </p>
4279 </dd>
4280 <dt class="hdlist1">
4281 <code><strong>file tempfile</strong> <em>?template?</em></code>
4282 </dt>
4283 <dd>
4285 Creates and returns the name of a unique temporary file. If <code><em>template</em></code> is omitted, a
4286 default template will be used to place the file in /tmp. See <em>mkstemp(3)</em> for
4287 the format of the template and security concerns.
4288 </p>
4289 </dd>
4290 <dt class="hdlist1">
4291 <code><strong>file type</strong> <em>name</em></code>
4292 </dt>
4293 <dd>
4295 Returns a string giving the type of file <code><em>name</em></code>, which will be
4296 one of <code>file</code>, <code>directory</code>, <code>characterSpecial</code>,
4297 <code>blockSpecial</code>, <code>fifo</code>, <code>link</code>, or <code>socket</code>.
4298 </p>
4299 </dd>
4300 <dt class="hdlist1">
4301 <code><strong>file writable</strong> <em>name</em></code>
4302 </dt>
4303 <dd>
4305 Return <em>1</em> if file <code><em>name</em></code> is writable by
4306 the current user, <em>0</em> otherwise.
4307 </p>
4308 </dd>
4309 </dl></div>
4310 <div class="paragraph"><p>The <a href="#_file"><strong><code>file</code></strong></a> commands that return 0/1 results are often used in
4311 conditional or looping commands, for example:</p></div>
4312 <div class="literalblock">
4313 <div class="content">
4314 <pre><code>if {![file exists foo]} {
4315 error {bad file name}
4316 } else {
4318 }</code></pre>
4319 </div></div>
4320 </div>
4321 <div class="sect2">
4322 <h3 id="_finalize">finalize</h3>
4323 <div class="paragraph"><p><code><strong>finalize</strong> <em>reference ?command?</em></code></p></div>
4324 <div class="paragraph"><p>If <code><em>command</em></code> is omitted, returns the finalizer command for the given reference.</p></div>
4325 <div class="paragraph"><p>Otherwise, sets a new finalizer command for the given reference. <code><em>command</em></code> may be
4326 the empty string to remove the current finalizer.</p></div>
4327 <div class="paragraph"><p>The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
4328 command.</p></div>
4329 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4330 </div>
4331 <div class="sect2">
4332 <h3 id="_flush">flush</h3>
4333 <div class="paragraph"><p><code><strong>flush</strong> <em>fileId</em></code></p></div>
4334 <div class="paragraph"><p><code><em>fileId</em> <strong>flush</strong></code></p></div>
4335 <div class="paragraph"><p>Flushes any output that has been buffered for <code><em>fileId</em></code>. <code><em>fileId</em></code> must
4336 have been the return value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
4337 <code>stdout</code> or <code>stderr</code> to access one of the standard I/O streams; it must
4338 refer to a file that was opened for writing. This command returns an
4339 empty string.</p></div>
4340 </div>
4341 <div class="sect2">
4342 <h3 id="_for">for</h3>
4343 <div class="paragraph"><p><code><strong>for</strong> <em>start test next body</em></code></p></div>
4344 <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.
4345 The <code><em>start</em></code>, <code><em>next</em></code>, and <code><em>body</em></code> arguments must be Tcl command strings,
4346 and <code><em>test</em></code> is an expression string.</p></div>
4347 <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>.
4348 Then it repeatedly evaluates <code><em>test</em></code> as an expression; if the result is
4349 non-zero it invokes the Tcl interpreter on <code><em>body</em></code>, then invokes the Tcl
4350 interpreter on <code><em>next</em></code>, then repeats the loop. The command terminates
4351 when <code><em>test</em></code> evaluates to 0.</p></div>
4352 <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
4353 commands in the current execution of <code><em>body</em></code> are skipped; processing
4354 continues by invoking the Tcl interpreter on <code><em>next</em></code>, then evaluating
4355 <code><em>test</em></code>, and so on.</p></div>
4356 <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>
4357 command will return immediately.</p></div>
4358 <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
4359 statements in C.</p></div>
4360 <div class="paragraph"><p><a href="#_for"><strong><code>for</code></strong></a> returns an empty string.</p></div>
4361 </div>
4362 <div class="sect2">
4363 <h3 id="_foreach">foreach</h3>
4364 <div class="paragraph"><p><code><strong>foreach</strong> <em>varName list body</em></code></p></div>
4365 <div class="paragraph"><p><code><strong>foreach</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
4366 <div class="paragraph"><p>In this command, <code><em>varName</em></code> is the name of a variable, <code><em>list</em></code>
4367 is a list of values to assign to <code><em>varName</em></code>, and <code><em>body</em></code> is a
4368 collection of Tcl commands.</p></div>
4369 <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
4370 the contents of the field to <code><em>varName</em></code> (as if the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4371 had been used to extract the field), then calls the Tcl interpreter to
4372 execute <code><em>body</em></code>.</p></div>
4373 <div class="paragraph"><p>If instead of being a simple name, <code><em>varList</em></code> is used, multiple assignments
4374 are made each time through the loop, one for each element of <code><em>varList</em></code>.</p></div>
4375 <div class="paragraph"><p>For example, if there are two elements in <code><em>varList</em></code> and six elements in
4376 the list, the loop will be executed three times.</p></div>
4377 <div class="paragraph"><p>If the length of the list doesn&#8217;t evenly divide by the number of elements
4378 in <code><em>varList</em></code>, the value of the remaining variables in the last iteration
4379 of the loop are undefined.</p></div>
4380 <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>,
4381 with the same effect as in the <a href="#_for"><strong><code>for</code></strong></a> command.</p></div>
4382 <div class="paragraph"><p><a href="#_foreach"><strong><code>foreach</code></strong></a> returns an empty string.</p></div>
4383 </div>
4384 <div class="sect2">
4385 <h3 id="_format">format</h3>
4386 <div class="paragraph"><p><code><strong>format</strong> <em>formatString ?arg ...?</em></code></p></div>
4387 <div class="paragraph"><p>This command generates a formatted string in the same way as the
4388 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
4389 implementation). <code><em>formatString</em></code> indicates how to format
4390 the result, using <code>%</code> fields as in <em>sprintf</em>, and the additional
4391 arguments, if any, provide values to be substituted into the result.</p></div>
4392 <div class="paragraph"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
4393 man page for details. Each <code><em>arg</em></code> must match the expected type
4394 from the <code>%</code> field in <code><em>formatString</em></code>; the <a href="#_format"><strong><code>format</code></strong></a> command
4395 converts each argument to the correct type (floating, integer, etc.)
4396 before passing it to <em>sprintf</em> for formatting.</p></div>
4397 <div class="paragraph"><p>The only unusual conversion is for <code>%c</code>; in this case the argument
4398 must be a decimal string, which will then be converted to the corresponding
4399 ASCII (or UTF-8) character value.</p></div>
4400 <div class="paragraph"><p>In addition, Jim Tcl provides basic support for conversion to binary with <code>%b</code>.</p></div>
4401 <div class="paragraph"><p><a href="#_format"><strong><code>format</code></strong></a> does backslash substitution on its <code><em>formatString</em></code>
4402 argument, so backslash sequences in <code><em>formatString</em></code> will be handled
4403 correctly even if the argument is in braces.</p></div>
4404 <div class="paragraph"><p>The return value from <a href="#_format"><strong><code>format</code></strong></a> is the formatted string.</p></div>
4405 </div>
4406 <div class="sect2">
4407 <h3 id="_getref">getref</h3>
4408 <div class="paragraph"><p><code><strong>getref</strong> <em>reference</em></code></p></div>
4409 <div class="paragraph"><p>Returns the string associated with <code><em>reference</em></code>. The reference must
4410 be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a> command.</p></div>
4411 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4412 </div>
4413 <div class="sect2">
4414 <h3 id="_gets">gets</h3>
4415 <div class="paragraph"><p><code><strong>gets</strong> <em>fileId ?varName?</em></code></p></div>
4416 <div class="paragraph"><p><code><em>fileId</em> <strong>gets</strong> <em>?varName?</em></code></p></div>
4417 <div class="paragraph"><p>Reads the next line from the file given by <code><em>fileId</em></code> and discards
4418 the terminating newline character.</p></div>
4419 <div class="paragraph"><p>If <code><em>varName</em></code> is specified, then the line is placed in the variable
4420 by that name and the return value is a count of the number of characters
4421 read (not including the newline).</p></div>
4422 <div class="paragraph"><p>If the end of the file is reached before reading
4423 any characters then -1 is returned and <code><em>varName</em></code> is set to an
4424 empty string.</p></div>
4425 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified then the return value will be
4426 the line (minus the newline character) or an empty string if
4427 the end of the file is reached before reading any characters.</p></div>
4428 <div class="paragraph"><p>An empty string will also be returned if a line contains no characters
4429 except the newline, so <a href="#_eof"><strong><code>eof</code></strong></a> may have to be used to determine
4430 what really happened.</p></div>
4431 <div class="paragraph"><p>If the last character in the file is not a newline character, then
4432 <a href="#_gets"><strong><code>gets</code></strong></a> behaves as if there were an additional newline character
4433 at the end of the file.</p></div>
4434 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous
4435 call to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened
4436 for reading.</p></div>
4437 </div>
4438 <div class="sect2">
4439 <h3 id="_glob">glob</h3>
4440 <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>
4441 <div class="paragraph"><p>This command performs filename globbing, using csh rules. The returned
4442 value from <a href="#_glob"><strong><code>glob</code></strong></a> is the list of expanded filenames.</p></div>
4443 <div class="paragraph"><p>If <code>-nocomplain</code> is specified as the first argument then an empty
4444 list may be returned; otherwise an error is returned if the expanded
4445 list is empty. The <code>-nocomplain</code> argument must be provided
4446 exactly: an abbreviation will not be accepted.</p></div>
4447 <div class="paragraph"><p>If <code>-directory</code> is given, the <code><em>dir</em></code> is understood to contain a
4448 directory name to search in. This allows globbing inside directories
4449 whose names may contain glob-sensitive characters. The returned names
4450 include the directory name unless <code><em>-tails</em></code> is specified.</p></div>
4451 <div class="paragraph"><p>If <code><em>-tails</em></code> is specified, along with <code>-directory</code>, the returned names
4452 are relative to the given directory.</p></div>
4453 </div>
4454 <div class="sect2">
4455 <h3 id="_global">global</h3>
4456 <div class="paragraph"><p><code><strong>global</strong> <em>varName ?varName ...?</em></code></p></div>
4457 <div class="paragraph"><p>This command is ignored unless a Tcl procedure is being interpreted.
4458 If so, then it declares each given <code><em>varName</em></code> to be a global variable
4459 rather than a local one. For the duration of the current procedure
4460 (and only while executing in the current procedure), any reference to
4461 <code><em>varName</em></code> will be bound to a global variable instead
4462 of a local one.</p></div>
4463 <div class="paragraph"><p>An alternative to using <a href="#_global"><strong><code>global</code></strong></a> is to use the <code>::</code> prefix
4464 to explicitly name a variable in the global scope.</p></div>
4465 </div>
4466 <div class="sect2">
4467 <h3 id="_if">if</h3>
4468 <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>
4469 <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
4470 that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument). The value of the expression must
4471 be numeric; if it is non-zero then <code><em>body1</em></code> is executed by passing it to
4472 the Tcl interpreter.</p></div>
4473 <div class="paragraph"><p>Otherwise <code><em>expr2</em></code> is evaluated as an expression and if it is non-zero
4474 then <code><em>body2</em></code> is executed, and so on.</p></div>
4475 <div class="paragraph"><p>If none of the expressions evaluates to non-zero then <code><em>bodyN</em></code> is executed.</p></div>
4476 <div class="paragraph"><p>The <code>then</code> and <code>else</code> arguments are optional "noise words" to make the
4477 command easier to read.</p></div>
4478 <div class="paragraph"><p>There may be any number of <code>elseif</code> clauses, including zero. <code><em>bodyN</em></code>
4479 may also be omitted as long as <code>else</code> is omitted too.</p></div>
4480 <div class="paragraph"><p>The return value from the command is the result of the body script that
4481 was executed, or an empty string if none of the expressions was non-zero
4482 and there was no <code><em>bodyN</em></code>.</p></div>
4483 </div>
4484 <div class="sect2">
4485 <h3 id="_incr">incr</h3>
4486 <div class="paragraph"><p><code><strong>incr</strong> <em>varName ?increment?</em></code></p></div>
4487 <div class="paragraph"><p>Increment the value stored in the variable whose name is <code><em>varName</em></code>.
4488 The value of the variable must be integral.</p></div>
4489 <div class="paragraph"><p>If <code><em>increment</em></code> is supplied then its value (which must be an
4490 integer) is added to the value of variable <code><em>varName</em></code>; otherwise
4491 1 is added to <code><em>varName</em></code>.</p></div>
4492 <div class="paragraph"><p>The new value is stored as a decimal string in variable <code><em>varName</em></code>
4493 and also returned as result.</p></div>
4494 <div class="paragraph"><p>If the variable does not exist, the variable is implicitly created
4495 and set to <code>0</code> first.</p></div>
4496 </div>
4497 <div class="sect2">
4498 <h3 id="_info">info</h3>
4499 <div class="dlist"><dl>
4500 <dt class="hdlist1">
4501 <code><strong>info</strong> <em>option ?arg...?</em></code>
4502 </dt>
4503 <dd>
4505 Provide information about various internals to the Tcl interpreter.
4506 The legal <code><em>option</em></code>'s (which may be abbreviated) are:
4507 </p>
4508 </dd>
4509 <dt class="hdlist1">
4510 <code><strong>info args</strong> <em>procname</em></code>
4511 </dt>
4512 <dd>
4514 Returns a list containing the names of the arguments to procedure
4515 <code><em>procname</em></code>, in order. <code><em>procname</em></code> must be the name of a
4516 Tcl command procedure.
4517 </p>
4518 </dd>
4519 <dt class="hdlist1">
4520 <code><strong>info alias</strong> <em>command</em></code>
4521 </dt>
4522 <dd>
4524 <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
4525 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>
4526 </p>
4527 </dd>
4528 <dt class="hdlist1">
4529 <code><strong>info body</strong> <em>procname</em></code>
4530 </dt>
4531 <dd>
4533 Returns the body of procedure <code><em>procname</em></code>. <code><em>procname</em></code> must be
4534 the name of a Tcl command procedure.
4535 </p>
4536 </dd>
4537 <dt class="hdlist1">
4538 <code><strong>info channels</strong></code>
4539 </dt>
4540 <dd>
4542 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>
4543 </p>
4544 </dd>
4545 <dt class="hdlist1">
4546 <code><strong>info commands</strong> ?<em>pattern</em>?</code>
4547 </dt>
4548 <dd>
4550 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of names of all the
4551 Tcl commands, including both the built-in commands written in C and
4552 the command procedures defined using the <a href="#_proc"><strong><code>proc</code></strong></a> command.
4553 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4554 are returned. Matching is determined using the same rules as for
4555 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4556 </p>
4557 </dd>
4558 <dt class="hdlist1">
4559 <code><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</code>
4560 </dt>
4561 <dd>
4563 Returns 1 if <code><em>command</em></code> is a complete Tcl command in the sense of
4564 having no unclosed quotes, braces, brackets or array element names,
4565 If the command doesn&#8217;t appear to be complete then 0 is returned.
4566 This command is typically used in line-oriented input environments
4567 to allow users to type in commands that span multiple lines; if the
4568 command isn&#8217;t complete, the script can delay evaluating it until additional
4569 lines have been typed to complete the command. If <code><em>varName</em></code> is specified, the
4570 missing character is stored in the variable with that name.
4571 </p>
4572 </dd>
4573 <dt class="hdlist1">
4574 <code><strong>info exists</strong> <em>varName</em></code>
4575 </dt>
4576 <dd>
4578 Returns <em>1</em> if the variable named <code><em>varName</em></code> exists in the
4579 current context (either as a global or local variable), returns <em>0</em>
4580 otherwise.
4581 </p>
4582 </dd>
4583 <dt class="hdlist1">
4584 <code><strong>info frame</strong> ?<em>number</em>?</code>
4585 </dt>
4586 <dd>
4588 If <code><em>number</em></code> is not specified, this command returns a number
4589 which is the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> - the current stack frame level.
4590 If <code><em>number</em></code> is specified, then the result is a list consisting of the procedure,
4591 filename and line number for the procedure call at level <code><em>number</em></code> on the stack.
4592 If <code><em>number</em></code> is positive then it selects a particular stack level (1 refers
4593 to the top-most active procedure, 2 to the procedure it called, and
4594 so on); otherwise it gives a level relative to the current level
4595 (0 refers to the current procedure, -1 to its caller, and so on).
4596 The level has an identical meaning to <a href="#_info"><strong><code>info</code></strong></a> <code>level</code>.
4597 </p>
4598 </dd>
4599 <dt class="hdlist1">
4600 <code><strong>info globals</strong> ?<em>pattern</em>?</code>
4601 </dt>
4602 <dd>
4604 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4605 of currently-defined global variables.
4606 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4607 are returned. Matching is determined using the same rules as for
4608 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4609 </p>
4610 </dd>
4611 <dt class="hdlist1">
4612 <code><strong>info hostname</strong></code>
4613 </dt>
4614 <dd>
4616 An alias for <a href="#cmd_1"><strong><code>os.gethostname</code></strong></a> for compatibility with Tcl 6.x
4617 </p>
4618 </dd>
4619 <dt class="hdlist1">
4620 <code><strong>info level</strong> ?<em>number</em>?</code>
4621 </dt>
4622 <dd>
4624 If <code><em>number</em></code> is not specified, this command returns a number
4625 giving the stack level of the invoking procedure, or 0 if the
4626 command is invoked at top-level. If <code><em>number</em></code> is specified,
4627 then the result is a list consisting of the name and arguments for the
4628 procedure call at level <code><em>number</em></code> on the stack. If <code><em>number</em></code>
4629 is positive then it selects a particular stack level (1 refers
4630 to the top-most active procedure, 2 to the procedure it called, and
4631 so on); otherwise it gives a level relative to the current level
4632 (0 refers to the current procedure, -1 to its caller, and so on).
4633 See the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command for more information on what stack
4634 levels mean.
4635 </p>
4636 </dd>
4637 <dt class="hdlist1">
4638 <code><strong>info locals</strong> ?<em>pattern</em>?</code>
4639 </dt>
4640 <dd>
4642 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4643 of currently-defined local variables, including arguments to the
4644 current procedure, if any. Variables defined with the <a href="#_global"><strong><code>global</code></strong></a>
4645 and <a href="#_upvar"><strong><code>upvar</code></strong></a> commands will not be returned. If <code><em>pattern</em></code> is
4646 specified, only those names matching <code><em>pattern</em></code> are returned.
4647 Matching is determined using the same rules as for <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4648 </p>
4649 </dd>
4650 <dt class="hdlist1">
4651 <code><strong>info nameofexecutable</strong></code>
4652 </dt>
4653 <dd>
4655 Returns the name of the binary file from which the application
4656 was invoked. A full path will be returned, unless the path
4657 can&#8217;t be determined, in which case the empty string will be returned.
4658 </p>
4659 </dd>
4660 <dt class="hdlist1">
4661 <code><strong>info procs</strong> ?<em>pattern</em>?</code>
4662 </dt>
4663 <dd>
4665 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the
4666 names of Tcl command procedures.
4667 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4668 are returned. Matching is determined using the same rules as for
4669 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4670 </p>
4671 </dd>
4672 <dt class="hdlist1">
4673 <code><strong>info references</strong></code>
4674 </dt>
4675 <dd>
4677 Returns a list of all references which have not yet been garbage
4678 collected.
4679 </p>
4680 </dd>
4681 <dt class="hdlist1">
4682 <code><strong>info returncodes</strong> ?<em>code</em>?</code>
4683 </dt>
4684 <dd>
4686 Returns a list representing the mapping of standard return codes
4687 to names. e.g. <code>{0 ok 1 error 2 return ...}</code>. If a code is given,
4688 instead returns the name for the given code.
4689 </p>
4690 </dd>
4691 <dt class="hdlist1">
4692 <code><strong>info script</strong></code>
4693 </dt>
4694 <dd>
4696 If a Tcl script file is currently being evaluated (i.e. there is a
4697 call to <em>Jim_EvalFile</em> active or there is an active invocation
4698 of the <a href="#_source"><strong><code>source</code></strong></a> command), then this command returns the name
4699 of the innermost file being processed. Otherwise the command returns an
4700 empty string.
4701 </p>
4702 </dd>
4703 <dt class="hdlist1">
4704 <code><strong>info source</strong> <em>script ?filename line?</em></code>
4705 </dt>
4706 <dd>
4708 With a single argument, returns the original source location of the given script as a list of
4709 <code>{filename linenumber}</code>. If the source location can&#8217;t be determined, the
4710 list <code>{{} 0}</code> is returned. If <code><em>filename</em></code> and <code><em>line</em></code> are given, returns a copy
4711 of <code><em>script</em></code> with the associate source information. This can be useful to produce
4712 useful messages from <a href="#_eval"><strong><code>eval</code></strong></a>, etc. if the original source information may be lost.
4713 </p>
4714 </dd>
4715 <dt class="hdlist1">
4716 <code><strong>info stacktrace</strong></code>
4717 </dt>
4718 <dd>
4720 After an error is caught with <a href="#_catch"><strong><code>catch</code></strong></a>, returns the stack trace as a list
4721 of <code>{procedure filename line ...}</code>.
4722 </p>
4723 </dd>
4724 <dt class="hdlist1">
4725 <code><strong>info statics</strong> <em>procname</em></code>
4726 </dt>
4727 <dd>
4729 Returns a dictionary of the static variables of procedure
4730 <code><em>procname</em></code>. <code><em>procname</em></code> must be the name of a Tcl command
4731 procedure. An empty dictionary is returned if the procedure has
4732 no static variables.
4733 </p>
4734 </dd>
4735 <dt class="hdlist1">
4736 <code><strong>info version</strong></code>
4737 </dt>
4738 <dd>
4740 Returns the version number for this version of Jim in the form <code><strong>x.yy</strong></code>.
4741 </p>
4742 </dd>
4743 <dt class="hdlist1">
4744 <code><strong>info vars</strong> ?<em>pattern</em>?</code>
4745 </dt>
4746 <dd>
4748 If <code><em>pattern</em></code> isn&#8217;t specified,
4749 returns a list of all the names of currently-visible variables, including
4750 both locals and currently-visible globals.
4751 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4752 are returned. Matching is determined using the same rules as for
4753 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4754 </p>
4755 </dd>
4756 </dl></div>
4757 </div>
4758 <div class="sect2">
4759 <h3 id="_join">join</h3>
4760 <div class="paragraph"><p><code><strong>join</strong> <em>list ?joinString?</em></code></p></div>
4761 <div class="paragraph"><p>The <code><em>list</em></code> argument must be a valid Tcl list. This command returns the
4762 string formed by joining all of the elements of <code><em>list</em></code> together with
4763 <code><em>joinString</em></code> separating each adjacent pair of elements.</p></div>
4764 <div class="paragraph"><p>The <code><em>joinString</em></code> argument defaults to a space character.</p></div>
4765 </div>
4766 <div class="sect2">
4767 <h3 id="_kill">kill</h3>
4768 <div class="paragraph"><p><code><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></code></p></div>
4769 <div class="paragraph"><p>Sends the given signal to the process identified by <code><em>pid</em></code>.</p></div>
4770 <div class="paragraph"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4771 <div class="ulist"><ul>
4772 <li>
4774 <code>TERM</code>
4775 </p>
4776 </li>
4777 <li>
4779 <code>SIGTERM</code>
4780 </p>
4781 </li>
4782 <li>
4784 <code>-TERM</code>
4785 </p>
4786 </li>
4787 <li>
4789 <code>15</code>
4790 </p>
4791 </li>
4792 <li>
4794 <code>-15</code>
4795 </p>
4796 </li>
4797 </ul></div>
4798 <div class="paragraph"><p>The signal name may be in either upper or lower case.</p></div>
4799 <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>
4800 <div class="paragraph"><p>If no signal is specified, SIGTERM is used.</p></div>
4801 <div class="paragraph"><p>An error is raised if the signal could not be delivered.</p></div>
4802 </div>
4803 <div class="sect2">
4804 <h3 id="_lambda_2">lambda</h3>
4805 <div class="paragraph"><p><code><strong>lambda</strong> <em>args ?statics? body</em></code></p></div>
4806 <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
4807 creating a named procedure, it creates an anonymous procedure and returns
4808 the name of the procedure.</p></div>
4809 <div class="paragraph"><p>See <a href="#_proc"><strong><code>proc</code></strong></a> and GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4810 </div>
4811 <div class="sect2">
4812 <h3 id="_lappend">lappend</h3>
4813 <div class="paragraph"><p><code><strong>lappend</strong> <em>varName value ?value value ...?</em></code></p></div>
4814 <div class="paragraph"><p>Treat the variable given by <code><em>varName</em></code> as a list and append each of
4815 the <code><em>value</em></code> arguments to that list as a separate element, with spaces
4816 between elements.</p></div>
4817 <div class="paragraph"><p>If <code><em>varName</em></code> doesn&#8217;t exist, it is created as a list with elements given
4818 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
4819 each <code><em>value</em></code> is appended as a list element rather than raw text.</p></div>
4820 <div class="paragraph"><p>This command provides a relatively efficient way to build up large lists.
4821 For example,</p></div>
4822 <div class="literalblock">
4823 <div class="content">
4824 <pre><code>lappend a $b</code></pre>
4825 </div></div>
4826 <div class="paragraph"><p>is much more efficient than</p></div>
4827 <div class="literalblock">
4828 <div class="content">
4829 <pre><code>set a [concat $a [list $b]]</code></pre>
4830 </div></div>
4831 <div class="paragraph"><p>when <code>$a</code> is long.</p></div>
4832 </div>
4833 <div class="sect2">
4834 <h3 id="_lassign">lassign</h3>
4835 <div class="paragraph"><p><code><strong>lassign</strong> <em>list varName ?varName ...?</em></code></p></div>
4836 <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
4837 the variables given by the <code><em>varName</em></code> arguments in order. If there are more variable names than
4838 list elements, the remaining variables are set to the empty string. If there are more list ele-
4839 ments than variables, a list of unassigned elements is returned.</p></div>
4840 <div class="literalblock">
4841 <div class="content">
4842 <pre><code>jim&gt; lassign {1 2 3} a b; puts a=$a,b=$b
4844 a=1,b=2</code></pre>
4845 </div></div>
4846 </div>
4847 <div class="sect2">
4848 <h3 id="_local">local</h3>
4849 <div class="paragraph"><p><code><strong>local</strong> <em>cmd ?arg...?</em></code></p></div>
4850 <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
4851 be the name of an existing command, which is marked as having local scope.
4852 This means that when the current procedure exits, the specified
4853 command is deleted. This can be useful with <a href="#_lambda"><strong><code>lambda</code></strong></a>, local procedures or
4854 to automatically close a filehandle.</p></div>
4855 <div class="paragraph"><p>In addition, if a command already exists with the same name,
4856 the existing command will be kept rather than deleted, and may be called
4857 via <a href="#_upcall"><strong><code>upcall</code></strong></a>. The previous command will be restored when the current
4858 procedure exits. See <a href="#_upcall"><strong><code>upcall</code></strong></a> for more details.</p></div>
4859 <div class="paragraph"><p>In this example, a local procedure is created. Note that the procedure
4860 continues to have global scope while it is active.</p></div>
4861 <div class="literalblock">
4862 <div class="content">
4863 <pre><code>proc outer {} {
4864 # proc ... returns "inner" which is marked local
4865 local proc inner {} {
4866 # will be deleted when 'outer' exits
4867 }</code></pre>
4868 </div></div>
4869 <div class="literalblock">
4870 <div class="content">
4871 <pre><code> inner
4873 }</code></pre>
4874 </div></div>
4875 <div class="paragraph"><p>In this example, the lambda is deleted at the end of the procedure rather
4876 than waiting until garbage collection.</p></div>
4877 <div class="literalblock">
4878 <div class="content">
4879 <pre><code>proc outer {} {
4880 set x [lambda inner {args} {
4881 # will be deleted when 'outer' exits
4883 # Use 'function' here which simply returns $x
4884 local function $x</code></pre>
4885 </div></div>
4886 <div class="literalblock">
4887 <div class="content">
4888 <pre><code> $x ...
4890 }</code></pre>
4891 </div></div>
4892 </div>
4893 <div class="sect2">
4894 <h3 id="_loop">loop</h3>
4895 <div class="paragraph"><p><code><strong>loop</strong> <em>var first limit ?incr? body</em></code></p></div>
4896 <div class="paragraph"><p>Similar to <a href="#_for"><strong><code>for</code></strong></a> except simpler and possibly more efficient.
4897 With a positive increment, equivalent to:</p></div>
4898 <div class="literalblock">
4899 <div class="content">
4900 <pre><code>for {set var $first} {$var &lt; $limit} {incr var $incr} $body</code></pre>
4901 </div></div>
4902 <div class="paragraph"><p>If <code><em>incr</em></code> is not specified, 1 is used.
4903 Note that setting the loop variable inside the loop does not
4904 affect the loop count.</p></div>
4905 </div>
4906 <div class="sect2">
4907 <h3 id="_lindex">lindex</h3>
4908 <div class="paragraph"><p><code><strong>lindex</strong> <em>list ?index &#8230;?</em></code></p></div>
4909 <div class="paragraph"><p>Treats <code><em>list</em></code> as a Tcl list and returns element <code><em>index</em></code> from it
4910 (0 refers to the first element of the list).
4911 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4912 <div class="paragraph"><p>In extracting the element, <code><em>lindex</em></code> observes the same rules concerning
4913 braces and quotes and backslashes as the Tcl command interpreter; however,
4914 variable substitution and command substitution do not occur.</p></div>
4915 <div class="paragraph"><p>If no index values are given, simply returns <code><em>list</em></code></p></div>
4916 <div class="paragraph"><p>If <code><em>index</em></code> is negative or greater than or equal to the number of elements
4917 in <code><em>list</em></code>, then an empty string is returned.</p></div>
4918 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
4919 used in turn to select an element from the previous indexing
4920 operation, allowing the script to select elements from sublists.</p></div>
4921 </div>
4922 <div class="sect2">
4923 <h3 id="_linsert">linsert</h3>
4924 <div class="paragraph"><p><code><strong>linsert</strong> <em>list index element ?element element ...?</em></code></p></div>
4925 <div class="paragraph"><p>This command produces a new list from <code><em>list</em></code> by inserting all
4926 of the <code><em>element</em></code> arguments just before the element <code><em>index</em></code>
4927 of <code><em>list</em></code>. Each <code><em>element</em></code> argument will become
4928 a separate element of the new list. If <code><em>index</em></code> is less than
4929 or equal to zero, then the new elements are inserted at the
4930 beginning of the list. If <code><em>index</em></code> is greater than or equal
4931 to the number of elements in the list, then the new elements are
4932 appended to the list.</p></div>
4933 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4934 </div>
4935 <div class="sect2">
4936 <h3 id="_list">list</h3>
4937 <div class="paragraph"><p><code><strong>list</strong> <em>arg ?arg ...?</em></code></p></div>
4938 <div class="paragraph"><p>This command returns a list comprised of all the arguments, <code><em>arg</em></code>. Braces
4939 and backslashes get added as necessary, so that the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4940 may be used on the result to re-extract the original arguments, and also
4941 so that <a href="#_eval"><strong><code>eval</code></strong></a> may be used to execute the resulting list, with
4942 <code><em>arg1</em></code> comprising the command&#8217;s name and the other args comprising
4943 its arguments. <a href="#_list"><strong><code>list</code></strong></a> produces slightly different results than
4944 <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
4945 the list, while <a href="#_list"><strong><code>list</code></strong></a> works directly from the original arguments.
4946 For example, the command</p></div>
4947 <div class="literalblock">
4948 <div class="content">
4949 <pre><code>list a b {c d e} {f {g h}}</code></pre>
4950 </div></div>
4951 <div class="paragraph"><p>will return</p></div>
4952 <div class="literalblock">
4953 <div class="content">
4954 <pre><code>a b {c d e} {f {g h}}</code></pre>
4955 </div></div>
4956 <div class="paragraph"><p>while <a href="#_concat"><strong><code>concat</code></strong></a> with the same arguments will return</p></div>
4957 <div class="literalblock">
4958 <div class="content">
4959 <pre><code>a b c d e f {g h}</code></pre>
4960 </div></div>
4961 </div>
4962 <div class="sect2">
4963 <h3 id="_llength">llength</h3>
4964 <div class="paragraph"><p><code><strong>llength</strong> <em>list</em></code></p></div>
4965 <div class="paragraph"><p>Treats <code><em>list</em></code> as a list and returns a decimal string giving
4966 the number of elements in it.</p></div>
4967 </div>
4968 <div class="sect2">
4969 <h3 id="_lset">lset</h3>
4970 <div class="paragraph"><p><code><strong>lset</strong> <em>varName ?index ..? newValue</em></code></p></div>
4971 <div class="paragraph"><p>Sets an element in a list.</p></div>
4972 <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
4973 as the name of a variable containing a Tcl list. It also accepts
4974 zero or more indices into the list. Finally, it accepts a new value
4975 for an element of varName. If no indices are presented, the command
4976 takes the form:</p></div>
4977 <div class="literalblock">
4978 <div class="content">
4979 <pre><code>lset varName newValue</code></pre>
4980 </div></div>
4981 <div class="paragraph"><p>In this case, newValue replaces the old value of the variable
4982 varName.</p></div>
4983 <div class="paragraph"><p>When presented with a single index, the <a href="#_lset"><strong><code>lset</code></strong></a> command
4984 treats the content of the varName variable as a Tcl list. It addresses
4985 the index&#8217;th element in it (0 refers to the first element of the
4986 list). When interpreting the list, <a href="#_lset"><strong><code>lset</code></strong></a> observes the same rules
4987 concerning braces and quotes and backslashes as the Tcl command
4988 interpreter; however, variable substitution and command substitution
4989 do not occur. The command constructs a new list in which the
4990 designated element is replaced with newValue. This new list is
4991 stored in the variable varName, and is also the return value from
4992 the <a href="#_lset"><strong><code>lset</code></strong></a> command.</p></div>
4993 <div class="paragraph"><p>If index is negative or greater than or equal to the number of
4994 elements in $varName, then an error occurs.</p></div>
4995 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4996 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
4997 used in turn to address an element within a sublist designated by
4998 the previous indexing operation, allowing the script to alter
4999 elements in sublists. The command,</p></div>
5000 <div class="literalblock">
5001 <div class="content">
5002 <pre><code>lset a 1 2 newValue</code></pre>
5003 </div></div>
5004 <div class="paragraph"><p>replaces element 2 of sublist 1 with <code><em>newValue</em></code>.</p></div>
5005 <div class="paragraph"><p>The integer appearing in each index argument must be greater than
5006 or equal to zero. The integer appearing in each index argument must
5007 be strictly less than the length of the corresponding list. In other
5008 words, the <a href="#_lset"><strong><code>lset</code></strong></a> command cannot change the size of a list. If an
5009 index is outside the permitted range, an error is reported.</p></div>
5010 </div>
5011 <div class="sect2">
5012 <h3 id="_lmap">lmap</h3>
5013 <div class="paragraph"><p><code><strong>lmap</strong> <em>varName list body</em></code></p></div>
5014 <div class="paragraph"><p><code><strong>lmap</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
5015 <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>
5016 <div class="paragraph"><p>For example:</p></div>
5017 <div class="literalblock">
5018 <div class="content">
5019 <pre><code>jim&gt; lmap i {1 2 3 4 5} {expr $i*$i}
5020 1 4 9 16 25
5021 jim&gt; lmap a {1 2 3} b {A B C} {list $a $b}
5022 {1 A} {2 B} {3 C}</code></pre>
5023 </div></div>
5024 <div class="paragraph"><p>If the body invokes <a href="#_continue"><strong><code>continue</code></strong></a>, no value is added for this iteration.
5025 If the body invokes <a href="#_break"><strong><code>break</code></strong></a>, the loop ends and no more values are added.</p></div>
5026 </div>
5027 <div class="sect2">
5028 <h3 id="_load">load</h3>
5029 <div class="paragraph"><p><code><strong>load</strong> <em>filename</em></code></p></div>
5030 <div class="paragraph"><p>Loads the dynamic extension, <code><em>filename</em></code>. Generally the filename should have
5031 the extension <code>.so</code>. The initialisation function for the module must be based
5032 on the name of the file. For example loading <code>hwaccess.so</code> will invoke
5033 the initialisation function, <code>Jim_hwaccessInit</code>. Normally the <a href="#_load"><strong><code>load</code></strong></a> command
5034 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>
5035 </div>
5036 <div class="sect2">
5037 <h3 id="_lrange">lrange</h3>
5038 <div class="paragraph"><p><code><strong>lrange</strong> <em>list first last</em></code></p></div>
5039 <div class="paragraph"><p><code><em>list</em></code> must be a valid Tcl list. This command will return a new
5040 list consisting of elements <code><em>first</em></code> through <code><em>last</em></code>, inclusive.</p></div>
5041 <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>
5042 <div class="paragraph"><p>If <code><em>last</em></code> is greater than or equal to the number of elements
5043 in the list, then it is treated as if it were <code>end</code>.</p></div>
5044 <div class="paragraph"><p>If <code><em>first</em></code> is greater than <code><em>last</em></code> then an empty string
5045 is returned.</p></div>
5046 <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
5047 same result as <code>"<a href="#_lindex"><strong><code>lindex</code></strong></a> <em>list first</em>"</code> (although it often does
5048 for simple fields that aren&#8217;t enclosed in braces); it does, however,
5049 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>
5050 </div>
5051 <div class="sect2">
5052 <h3 id="_lreplace">lreplace</h3>
5053 <div class="paragraph"><p><code><strong>lreplace</strong> <em>list first last ?element element ...?</em></code></p></div>
5054 <div class="paragraph"><p>Returns a new list formed by replacing one or more elements of
5055 <code><em>list</em></code> with the <code><em>element</em></code> arguments.</p></div>
5056 <div class="paragraph"><p><code><em>first</em></code> gives the index in <code><em>list</em></code> of the first element
5057 to be replaced.</p></div>
5058 <div class="paragraph"><p>If <code><em>first</em></code> is less than zero then it refers to the first
5059 element of <code><em>list</em></code>; the element indicated by <code><em>first</em></code>
5060 must exist in the list.</p></div>
5061 <div class="paragraph"><p><code><em>last</em></code> gives the index in <code><em>list</em></code> of the last element
5062 to be replaced; it must be greater than or equal to <code><em>first</em></code>.</p></div>
5063 <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>
5064 <div class="paragraph"><p>The <code><em>element</em></code> arguments specify zero or more new arguments to
5065 be added to the list in place of those that were deleted.</p></div>
5066 <div class="paragraph"><p>Each <code><em>element</em></code> argument will become a separate element of
5067 the list.</p></div>
5068 <div class="paragraph"><p>If no <code><em>element</em></code> arguments are specified, then the elements
5069 between <code><em>first</em></code> and <code><em>last</em></code> are simply deleted.</p></div>
5070 </div>
5071 <div class="sect2">
5072 <h3 id="_lrepeat">lrepeat</h3>
5073 <div class="paragraph"><p><code><strong>lrepeat</strong> <em>number element1 ?element2 ...?</em></code></p></div>
5074 <div class="paragraph"><p>Build a list by repeating elements <code><em>number</em></code> times (which must be
5075 a positive integer).</p></div>
5076 <div class="literalblock">
5077 <div class="content">
5078 <pre><code>jim&gt; lrepeat 3 a b
5079 a b a b a b</code></pre>
5080 </div></div>
5081 </div>
5082 <div class="sect2">
5083 <h3 id="_lreverse">lreverse</h3>
5084 <div class="paragraph"><p><code><strong>lreverse</strong> <em>list</em></code></p></div>
5085 <div class="paragraph"><p>Returns the list in reverse order.</p></div>
5086 <div class="literalblock">
5087 <div class="content">
5088 <pre><code>jim&gt; lreverse {1 2 3}
5089 3 2 1</code></pre>
5090 </div></div>
5091 </div>
5092 <div class="sect2">
5093 <h3 id="_lsearch">lsearch</h3>
5094 <div class="paragraph"><p><code><strong>lsearch</strong> <em>?options? list pattern</em></code></p></div>
5095 <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
5096 command returns the index of the first matching element (unless the options <code>-all</code>, <code>-inline</code> or <code>-bool</code> are
5097 specified.) If not, the command returns -1. The option arguments indicates how the elements of
5098 the list are to be matched against pattern and must have one of the values below:</p></div>
5099 <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>
5100 <div class="dlist"><dl>
5101 <dt class="hdlist1">
5102 <code><strong>-exact</strong></code>
5103 </dt>
5104 <dd>
5106 <code><em>pattern</em></code> is a literal string that is compared for exact equality against each list element.
5107 This is the default.
5108 </p>
5109 </dd>
5110 <dt class="hdlist1">
5111 <code><strong>-glob</strong></code>
5112 </dt>
5113 <dd>
5115 <code><em>pattern</em></code> is a glob-style pattern which is matched against each list element using the same
5116 rules as the string match command.
5117 </p>
5118 </dd>
5119 <dt class="hdlist1">
5120 <code><strong>-regexp</strong></code>
5121 </dt>
5122 <dd>
5124 <code><em>pattern</em></code> is treated as a regular expression and matched against each list element using
5125 the rules described by <a href="#_regexp"><strong><code>regexp</code></strong></a>.
5126 </p>
5127 </dd>
5128 <dt class="hdlist1">
5129 <code><strong>-command</strong> <em>cmdname</em></code>
5130 </dt>
5131 <dd>
5133 <code><em>cmdname</em></code> is a command which is used to match the pattern against each element of the
5134 list. It is invoked as <code><em>cmdname</em> ?<strong>-nocase</strong>? <em>pattern listvalue</em></code> and should return 1
5135 for a match, or 0 for no match.
5136 </p>
5137 </dd>
5138 <dt class="hdlist1">
5139 <code><strong>-all</strong></code>
5140 </dt>
5141 <dd>
5143 Changes the result to be the list of all matching indices (or all matching values if
5144 <code>-inline</code> is specified as well). If indices are returned, the indices will be in numeric
5145 order. If values are returned, the order of the values will be the order of those values
5146 within the input list.
5147 </p>
5148 </dd>
5149 <dt class="hdlist1">
5150 <code><strong>-inline</strong></code>
5151 </dt>
5152 <dd>
5154 The matching value is returned instead of its index (or an empty string if no value
5155 matches). If <code>-all</code> is also specified, then the result of the command is the list of all
5156 values that matched. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5157 </p>
5158 </dd>
5159 <dt class="hdlist1">
5160 <code><strong>-bool</strong></code>
5161 </dt>
5162 <dd>
5164 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <code>-all</code> is also specified,
5165 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
5166 the corresponding element matches. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5167 </p>
5168 </dd>
5169 <dt class="hdlist1">
5170 <code><strong>-not</strong></code>
5171 </dt>
5172 <dd>
5174 This negates the sense of the match, returning the index (or value
5175 if <code>-inline</code> is specified) of the first non-matching value in the
5176 list. If <code>-bool</code> is also specified, the <em>0</em> will be returned if a
5177 match is found, or <em>1</em> otherwise. If <code>-all</code> is also specified,
5178 non-matches will be returned rather than matches.
5179 </p>
5180 </dd>
5181 <dt class="hdlist1">
5182 <code><strong>-nocase</strong></code>
5183 </dt>
5184 <dd>
5186 Causes comparisons to be handled in a case-insensitive manner.
5187 </p>
5188 </dd>
5189 </dl></div>
5190 </div>
5191 <div class="sect2">
5192 <h3 id="_lsort">lsort</h3>
5193 <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>
5194 <div class="paragraph"><p>Sort the elements of <code><em>list</em></code>, returning a new list in sorted order.
5195 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.</p></div>
5196 <div class="paragraph"><p>If <code>-nocase</code> is specified, comparisons are case-insenstive.</p></div>
5197 <div class="paragraph"><p>If <code>-integer</code> is specified, numeric sorting is used.</p></div>
5198 <div class="paragraph"><p>If <code>-real</code> is specified, floating point number sorting is used.</p></div>
5199 <div class="paragraph"><p>If <code>-command <em>cmdname</em></code> is specified, <code><em>cmdname</em></code> is treated as a command
5200 name. For each comparison, <code><em>cmdname $value1 $value2</code></em> is called which
5201 should compare the values and return an integer less than, equal
5202 to, or greater than zero if the <code><em>$value1</em></code> is to be considered less
5203 than, equal to, or greater than <code><em>$value2</em></code>, respectively.</p></div>
5204 <div class="paragraph"><p>If <code>-decreasing</code> is specified, the resulting list is in the opposite
5205 order to what it would be otherwise. <code>-increasing</code> is the default.</p></div>
5206 <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.
5207 Note that duplicates are determined relative to the comparison used in the sort. Thus if <code>-index 0</code> is used,
5208 <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>
5209 <div class="paragraph"><p>If <code>-index <em>listindex</em></code> is specified, each element of the list is treated as a list and
5210 the given index is extracted from the list for comparison. The list index may
5211 be any valid list index, such as <code>1</code>, <code>end</code> or <code>end-2</code>.</p></div>
5212 </div>
5213 <div class="sect2">
5214 <h3 id="_open">open</h3>
5215 <div class="paragraph"><p><code><strong>open</strong> <em>fileName ?access?</em></code></p></div>
5216 <div class="paragraph"><p><code><strong>open</strong> <em>|command-pipeline ?access?</em></code></p></div>
5217 <div class="paragraph"><p>Opens a file and returns an identifier
5218 that may be used in future invocations
5219 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>.
5220 <code><em>fileName</em></code> gives the name of the file to open.</p></div>
5221 <div class="paragraph"><p>The <code><em>access</em></code> argument indicates the way in which the file is to be accessed.
5222 It may have any of the following values:</p></div>
5223 <div class="dlist"><dl>
5224 <dt class="hdlist1">
5225 <code>r</code>
5226 </dt>
5227 <dd>
5229 Open the file for reading only; the file must already exist.
5230 </p>
5231 </dd>
5232 <dt class="hdlist1">
5233 <code>r</code>+
5234 </dt>
5235 <dd>
5237 Open the file for both reading and writing; the file must
5238 already exist.
5239 </p>
5240 </dd>
5241 <dt class="hdlist1">
5242 <code>w</code>
5243 </dt>
5244 <dd>
5246 Open the file for writing only. Truncate it if it exists. If it doesn&#8217;t
5247 exist, create a new file.
5248 </p>
5249 </dd>
5250 <dt class="hdlist1">
5251 <code>w</code>+
5252 </dt>
5253 <dd>
5255 Open the file for reading and writing. Truncate it if it exists.
5256 If it doesn&#8217;t exist, create a new file.
5257 </p>
5258 </dd>
5259 <dt class="hdlist1">
5260 <code>a</code>
5261 </dt>
5262 <dd>
5264 Open the file for writing only. The file must already exist, and the file
5265 is positioned so that new data is appended to the file.
5266 </p>
5267 </dd>
5268 <dt class="hdlist1">
5269 <code>a</code>+
5270 </dt>
5271 <dd>
5273 Open the file for reading and writing. If the file doesn&#8217;t
5274 exist, create a new empty file. Set the initial access position
5275 to the end of the file.
5276 </p>
5277 </dd>
5278 </dl></div>
5279 <div class="paragraph"><p><code><em>access</em></code> defaults to <em>r</em>.</p></div>
5280 <div class="paragraph"><p>If a file is opened for both reading and writing, then <a href="#_seek"><strong><code>seek</code></strong></a>
5281 must be invoked between a read and a write, or vice versa.</p></div>
5282 <div class="paragraph"><p>If the first character of <code><em>fileName</em></code> is "|" then the remaining
5283 characters of <code><em>fileName</em></code> are treated as a list of arguments that
5284 describe a command pipeline to invoke, in the same style as the
5285 arguments for exec. In this case, the channel identifier returned
5286 by open may be used to write to the command&#8217;s input pipe or read
5287 from its output pipe, depending on the value of <code><em>access</em></code>. If write-only
5288 access is used (e.g. <code><em>access</em></code> is <em>w</em>), then standard output for the
5289 pipeline is directed to the current standard output unless overridden
5290 by the command. If read-only access is used (e.g. <code><em>access</em></code> is r),
5291 standard input for the pipeline is taken from the current standard
5292 input unless overridden by the command.</p></div>
5293 <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
5294 forming the command pipeline.</p></div>
5295 <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>
5296 </div>
5297 <div class="sect2">
5298 <h3 id="_package">package</h3>
5299 <div class="paragraph"><p><code><strong>package provide</strong> <em>name ?version?</em></code></p></div>
5300 <div class="paragraph"><p>Indicates that the current script provides the package named <code><em>name</em></code>.
5301 If no version is specified, <em>1.0</em> is used.</p></div>
5302 <div class="paragraph"><p>Any script which provides a package may include this statement
5303 as the first statement, although it is not required.</p></div>
5304 <div class="paragraph"><p><code><strong>package require</strong> <em>name ?version?</em>*</code></p></div>
5305 <div class="paragraph"><p>Searches for the package with the given <code><em>name</em></code> by examining each path
5306 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
5307 or <em>$path/$name.tcl</em> as a script package.</p></div>
5308 <div class="paragraph"><p>The first such file which is found is considered to provide the the package.
5309 (The version number is ignored).</p></div>
5310 <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,
5311 otherwise if <em>$name.tcl</em> exists it is loaded with the <a href="#_source"><strong><code>source</code></strong></a> command.</p></div>
5312 <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.
5313 No further attempt will be made to locate the file.</p></div>
5314 </div>
5315 <div class="sect2">
5316 <h3 id="_pid">pid</h3>
5317 <div class="paragraph"><p><code><strong>pid</strong></code></p></div>
5318 <div class="paragraph"><p><code><strong>pid</strong> <em>fileId</em></code></p></div>
5319 <div class="paragraph"><p>The first form returns the process identifier of the current process.</p></div>
5320 <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
5321 of the process ids forming the pipeline in the same form as <a href="#_exec"><strong><code>exec</code></strong></a> <code>... &amp;</code>.
5322 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
5323 the empty string is returned instead.</p></div>
5324 <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>
5325 </div>
5326 <div class="sect2">
5327 <h3 id="_proc">proc</h3>
5328 <div class="paragraph"><p><code><strong>proc</strong> <em>name args ?statics? body</em></code></p></div>
5329 <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>.
5330 When the new command is invoked, the contents of <code><em>body</em></code> will be executed.
5331 Tcl interpreter. <code><em>args</em></code> specifies the formal arguments to the procedure.
5332 If specified, <code><em>static</em></code>, declares static variables which are bound to the
5333 procedure.</p></div>
5334 <div class="paragraph"><p>See PROCEDURES for detailed information about Tcl procedures.</p></div>
5335 <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>
5336 <div class="paragraph"><p>When a procedure is invoked, the procedure&#8217;s return value is the
5337 value specified in a <a href="#_return"><strong><code>return</code></strong></a> command. If the procedure doesn&#8217;t
5338 execute an explicit <a href="#_return"><strong><code>return</code></strong></a>, then its return value is the value
5339 of the last command executed in the procedure&#8217;s body.</p></div>
5340 <div class="paragraph"><p>If an error occurs while executing the procedure body, then the
5341 procedure-as-a-whole will return that same error.</p></div>
5342 </div>
5343 <div class="sect2">
5344 <h3 id="_puts">puts</h3>
5345 <div class="paragraph"><p><code><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></code></p></div>
5346 <div class="paragraph"><p><code><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></code></p></div>
5347 <div class="paragraph"><p>Writes the characters given by <code><em>string</em></code> to the file given
5348 by <code><em>fileId</em></code>. <code><em>fileId</em></code> must have been the return
5349 value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
5350 <code>stdout</code> or <code>stderr</code> to refer to one of the standard I/O
5351 channels; it must refer to a file that was opened for
5352 writing.</p></div>
5353 <div class="paragraph"><p>In the first form, if no <code><em>fileId</em></code> is specified then it defaults to <code>stdout</code>.
5354 <a href="#_puts"><strong><code>puts</code></strong></a> normally outputs a newline character after <code><em>string</em></code>,
5355 but this feature may be suppressed by specifying the <code>-nonewline</code>
5356 switch.</p></div>
5357 <div class="paragraph"><p>Output to files is buffered internally by Tcl; the <a href="#_flush"><strong><code>flush</code></strong></a>
5358 command may be used to force buffered characters to be output.</p></div>
5359 </div>
5360 <div class="sect2">
5361 <h3 id="_pwd">pwd</h3>
5362 <div class="paragraph"><p><code><strong>pwd</strong></code></p></div>
5363 <div class="paragraph"><p>Returns the path name of the current working directory.</p></div>
5364 </div>
5365 <div class="sect2">
5366 <h3 id="_rand">rand</h3>
5367 <div class="paragraph"><p><code><strong>rand</strong> <em>?min? ?max?</em></code></p></div>
5368 <div class="paragraph"><p>Returns a random integer between <code><em>min</em></code> (defaults to 0) and <code><em>max</em></code>
5369 (defaults to the maximum integer).</p></div>
5370 <div class="paragraph"><p>If only one argument is given, it is interpreted as <code><em>max</em></code>.</p></div>
5371 </div>
5372 <div class="sect2">
5373 <h3 id="_range">range</h3>
5374 <div class="paragraph"><p><code><strong>range</strong> <em>?start? end ?step?</em></code></p></div>
5375 <div class="paragraph"><p>Returns a list of integers starting at <code><em>start</em></code> (defaults to 0)
5376 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>
5377 <div class="literalblock">
5378 <div class="content">
5379 <pre><code>jim&gt; range 5
5380 0 1 2 3 4
5381 jim&gt; range 2 5
5382 2 3 4
5383 jim&gt; range 2 10 4
5385 jim&gt; range 7 4 -2
5386 7 5</code></pre>
5387 </div></div>
5388 </div>
5389 <div class="sect2">
5390 <h3 id="_read">read</h3>
5391 <div class="paragraph"><p><code><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></code></p></div>
5392 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</code></p></div>
5393 <div class="paragraph"><p><code><strong>read</strong> <em>fileId numBytes</em></code></p></div>
5394 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> <em>numBytes</em></code></p></div>
5395 <div class="paragraph"><p>In the first form, all of the remaining bytes are read from the file
5396 given by <code><em>fileId</em></code>; they are returned as the result of the command.
5397 If the <code>-nonewline</code> switch is specified then the last
5398 character of the file is discarded if it is a newline.</p></div>
5399 <div class="paragraph"><p>In the second form, the extra argument specifies how many bytes to read;
5400 exactly this many bytes will be read and returned, unless there are fewer than
5401 <code><em>numBytes</em></code> bytes left in the file; in this case, all the remaining
5402 bytes are returned.</p></div>
5403 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous call
5404 to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened for reading.</p></div>
5405 </div>
5406 <div class="sect2">
5407 <h3 id="_regexp">regexp</h3>
5408 <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>
5409 <div class="paragraph"><p>Determines whether the regular expression <code><em>exp</em></code> matches part or
5410 all of <code><em>string</em></code> and returns 1 if it does, 0 if it doesn&#8217;t.</p></div>
5411 <div class="paragraph"><p>See REGULAR EXPRESSIONS above for complete information on the
5412 syntax of <code><em>exp</em></code> and how it is matched against <code><em>string</em></code>.</p></div>
5413 <div class="paragraph"><p>If additional arguments are specified after <code><em>string</em></code> then they
5414 are treated as the names of variables to use to return
5415 information about which part(s) of <code><em>string</em></code> matched <code><em>exp</em></code>.
5416 <code><em>matchVar</em></code> will be set to the range of <code><em>string</em></code> that
5417 matched all of <code><em>exp</em></code>. The first <code><em>subMatchVar</em></code> will contain
5418 the characters in <code><em>string</em></code> that matched the leftmost parenthesized
5419 subexpression within <code><em>exp</em></code>, the next <code><em>subMatchVar</em></code> will
5420 contain the characters that matched the next parenthesized
5421 subexpression to the right in <code><em>exp</em></code>, and so on.</p></div>
5422 <div class="paragraph"><p>Normally, <code><em>matchVar</em></code> and the each <code><em>subMatchVar</em></code> are set to hold the
5423 matching characters from <a href="#_string"><strong><code>string</code></strong></a>, however see <code>-indices</code> and
5424 <code>-inline</code> below.</p></div>
5425 <div class="paragraph"><p>If there are more values for <code><em>subMatchVar</em></code> than parenthesized subexpressions
5426 within <code><em>exp</em></code>, or if a particular subexpression in <code><em>exp</em></code> doesn&#8217;t
5427 match the string (e.g. because it was in a portion of the expression
5428 that wasn&#8217;t matched), then the corresponding <code><em>subMatchVar</em></code> will be
5429 set to <code>"-1 -1"</code> if <code>-indices</code> has been specified or to an empty
5430 string otherwise.</p></div>
5431 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regexp</em></code></p></div>
5432 <div class="dlist"><dl>
5433 <dt class="hdlist1">
5434 <code><strong>-nocase</strong></code>
5435 </dt>
5436 <dd>
5438 Causes upper-case and lower-case characters to be treated as
5439 identical during the matching process.
5440 </p>
5441 </dd>
5442 <dt class="hdlist1">
5443 <code><strong>-line</strong></code>
5444 </dt>
5445 <dd>
5447 Use newline-sensitive matching. By default, newline
5448 is a completely ordinary character with no special meaning in
5449 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5450 and <code>.</code> never match newline, a <code></sup></code> anchor matches the null
5451 string after any newline in the string in addition to its normal
5452 function, and the <code>$</code> anchor matches the null string before any
5453 newline in the string in addition to its normal function.
5454 </p>
5455 </dd>
5456 <dt class="hdlist1">
5457 <code><strong>-indices</strong></code>
5458 </dt>
5459 <dd>
5461 Changes what is stored in the subMatchVars. Instead of
5462 storing the matching characters from string, each variable
5463 will contain a list of two decimal strings giving the indices
5464 in string of the first and last characters in the matching
5465 range of characters.
5466 </p>
5467 </dd>
5468 <dt class="hdlist1">
5469 <code><strong>-start</strong> <em>offset</em></code>
5470 </dt>
5471 <dd>
5473 Specifies a character index offset into the string at which to start
5474 matching the regular expression. If <code>-indices</code> is
5475 specified, the indices will be indexed starting from the
5476 absolute beginning of the input string. <code><em>offset</em></code> will be
5477 constrained to the bounds of the input string.
5478 </p>
5479 </dd>
5480 <dt class="hdlist1">
5481 <code><strong>-all</strong></code>
5482 </dt>
5483 <dd>
5485 Causes the regular expression to be matched as many times as possible
5486 in the string, returning the total number of matches found. If this
5487 is specified with match variables, they will contain information
5488 for the last match only.
5489 </p>
5490 </dd>
5491 <dt class="hdlist1">
5492 <code><strong>-inline</strong></code>
5493 </dt>
5494 <dd>
5496 Causes the command to return, as a list, the data that would otherwise
5497 be placed in match variables. When using <code>-inline</code>, match variables
5498 may not be specified. If used with <code>-all</code>, the list will be concatenated
5499 at each iteration, such that a flat list is always returned. For
5500 each match iteration, the command will append the overall match
5501 data, plus one element for each subexpression in the regular
5502 expression.
5503 </p>
5504 </dd>
5505 <dt class="hdlist1">
5506 <code><strong>--</strong></code>
5507 </dt>
5508 <dd>
5510 Marks the end of switches. The argument following this one will be
5511 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5512 </p>
5513 </dd>
5514 </dl></div>
5515 </div>
5516 <div class="sect2">
5517 <h3 id="_regsub">regsub</h3>
5518 <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>
5519 <div class="paragraph"><p>This command matches the regular expression <code><em>exp</em></code> against
5520 <code><em>string</em></code> using the rules described in REGULAR EXPRESSIONS
5521 above.</p></div>
5522 <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>
5523 with the substitutions detailed below, and returns the number of
5524 substitutions made (normally 1 unless <code>-all</code> is specified).
5525 This is 0 if there were no matches.</p></div>
5526 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified, the substituted string will be returned
5527 instead.</p></div>
5528 <div class="paragraph"><p>When copying <code><em>string</em></code>, the portion of <code><em>string</em></code> that
5529 matched <code><em>exp</em></code> is replaced with <code><em>subSpec</em></code>.
5530 If <code><em>subSpec</em></code> contains a <code>&amp;</code> or <code>\0</code>, then it is replaced
5531 in the substitution with the portion of <code><em>string</em></code> that
5532 matched <code><em>exp</em></code>.</p></div>
5533 <div class="paragraph"><p>If <code><em>subSpec</em></code> contains a <code>\n</code>, where <code><em>n</em></code> is a digit
5534 between 1 and 9, then it is replaced in the substitution with
5535 the portion of <code><em>string</em></code> that matched the <code><em>n</em></code>'-th
5536 parenthesized subexpression of <code><em>exp</em></code>.
5537 Additional backslashes may be used in <code><em>subSpec</em></code> to prevent special
5538 interpretation of <code>&amp;</code> or <code>\0</code> or <code>\n</code> or
5539 backslash.</p></div>
5540 <div class="paragraph"><p>The use of backslashes in <code><em>subSpec</em></code> tends to interact badly
5541 with the Tcl parser&#8217;s use of backslashes, so it&#8217;s generally
5542 safest to enclose <code><em>subSpec</em></code> in braces if it includes
5543 backslashes.</p></div>
5544 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regsub</em></code></p></div>
5545 <div class="dlist"><dl>
5546 <dt class="hdlist1">
5547 <code><strong>-nocase</strong></code>
5548 </dt>
5549 <dd>
5551 Upper-case characters in <code><em>string</em></code> are converted to lower-case
5552 before matching against <code><em>exp</em></code>; however, substitutions
5553 specified by <code><em>subSpec</em></code> use the original unconverted form
5554 of <code><em>string</em></code>.
5555 </p>
5556 </dd>
5557 <dt class="hdlist1">
5558 <code><strong>-all</strong></code>
5559 </dt>
5560 <dd>
5562 All ranges in <code><em>string</em></code> that match <code><em>exp</em></code> are found and substitution
5563 is performed for each of these ranges, rather than only the
5564 first. The <code>&amp;</code> and <code>\n</code> sequences are handled for
5565 each substitution using the information from the corresponding
5566 match.
5567 </p>
5568 </dd>
5569 <dt class="hdlist1">
5570 <code><strong>-line</strong></code>
5571 </dt>
5572 <dd>
5574 Use newline-sensitive matching. By default, newline
5575 is a completely ordinary character with no special meaning in
5576 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5577 and <code>.</code> never match newline, a <code></sup></code> anchor matches the null
5578 string after any newline in the string in addition to its normal
5579 function, and the <code>$</code> anchor matches the null string before any
5580 newline in the string in addition to its normal function.
5581 </p>
5582 </dd>
5583 <dt class="hdlist1">
5584 <code><strong>-start</strong> <em>offset</em></code>
5585 </dt>
5586 <dd>
5588 Specifies a character index offset into the string at which to
5589 start matching the regular expression. <code><em>offset</em></code> will be
5590 constrained to the bounds of the input string.
5591 </p>
5592 </dd>
5593 <dt class="hdlist1">
5594 <code><strong>--</strong></code>
5595 </dt>
5596 <dd>
5598 Marks the end of switches. The argument following this one will be
5599 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5600 </p>
5601 </dd>
5602 </dl></div>
5603 </div>
5604 <div class="sect2">
5605 <h3 id="_ref">ref</h3>
5606 <div class="paragraph"><p><code><strong>ref</strong> <em>string tag ?finalizer?</em></code></p></div>
5607 <div class="paragraph"><p>Create a new reference containing <code><em>string</em></code> of type <code><em>tag</em></code>.
5608 If <code><em>finalizer</em></code> is specified, it is a command which will be invoked
5609 when the a garbage collection cycle runs and this reference is
5610 no longer accessible.</p></div>
5611 <div class="paragraph"><p>The finalizer is invoked as:</p></div>
5612 <div class="literalblock">
5613 <div class="content">
5614 <pre><code>finalizer reference string</code></pre>
5615 </div></div>
5616 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5617 </div>
5618 <div class="sect2">
5619 <h3 id="_rename">rename</h3>
5620 <div class="paragraph"><p><code><strong>rename</strong> <em>oldName newName</em></code></p></div>
5621 <div class="paragraph"><p>Rename the command that used to be called <code><em>oldName</em></code> so that it
5622 is now called <code><em>newName</em></code>. If <code><em>newName</em></code> is an empty string
5623 (e.g. {}) then <code><em>oldName</em></code> is deleted. The <a href="#_rename"><strong><code>rename</code></strong></a> command
5624 returns an empty string as result.</p></div>
5625 </div>
5626 <div class="sect2">
5627 <h3 id="_return">return</h3>
5628 <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>
5629 <div class="paragraph"><p>Return immediately from the current procedure (or top-level command
5630 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>
5631 is not specified, an empty string will be returned as result.</p></div>
5632 <div class="paragraph"><p>If <code>-code</code> is specified (as either a number or ok, error, break,
5633 continue, signal, return or exit), this code will be used instead
5634 of <code>JIM_OK</code>. This is generally useful when implementing flow of control
5635 commands.</p></div>
5636 <div class="paragraph"><p>If <code>-level</code> is specified and greater than 1, it has the effect of delaying
5637 the new return code from <code>-code</code>. This is useful when rethrowing an error
5638 from <a href="#_catch"><strong><code>catch</code></strong></a>. See the implementation of try/catch in tclcompat.tcl for
5639 an example of how this is done.</p></div>
5640 <div class="paragraph"><p>Note: The following options are only used when <code>-code</code> is JIM_ERR.</p></div>
5641 <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>)
5642 it is used to initialize the stacktrace.</p></div>
5643 <div class="paragraph"><p>If <code>-errorcode</code> is specified, it is used to set the global variable $::errorCode.</p></div>
5644 </div>
5645 <div class="sect2">
5646 <h3 id="_scan">scan</h3>
5647 <div class="paragraph"><p><code><strong>scan</strong> <em>string format varName1 ?varName2 ...?</em></code></p></div>
5648 <div class="paragraph"><p>This command parses fields from an input string in the same fashion
5649 as the C <em>sscanf</em> procedure. <code><em>string</em></code> gives the input to be parsed
5650 and <code><em>format</em></code> indicates how to parse it, using <em>%</em> fields as in
5651 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5652 man page for details. Each <code><em>varName</em></code> gives the name of a variable;
5653 when a field is scanned from <code><em>string</em></code>, the result is converted back
5654 into a string and assigned to the corresponding <code><em>varName</em></code>. The
5655 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5656 character value is converted to a decimal string, which is then
5657 assigned to the corresponding <code><em>varName</em></code>; no field width may be
5658 specified for this conversion.</p></div>
5659 </div>
5660 <div class="sect2">
5661 <h3 id="_seek">seek</h3>
5662 <div class="paragraph"><p><code><strong>seek</strong> <em>fileId offset ?origin?</em></code></p></div>
5663 <div class="paragraph"><p><code><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></code></p></div>
5664 <div class="paragraph"><p>Change the current access position for <code><em>fileId</em></code>.
5665 The <code><em>offset</em></code> and <code><em>origin</em></code> arguments specify the position at
5666 which the next read or write will occur for <code><em>fileId</em></code>.
5667 <code><em>offset</em></code> must be a number (which may be negative) and <code><em>origin</em></code>
5668 must be one of the following:</p></div>
5669 <div class="dlist"><dl>
5670 <dt class="hdlist1">
5671 <code><strong>start</strong></code>
5672 </dt>
5673 <dd>
5675 The new access position will be <code><em>offset</em></code> bytes from the start
5676 of the file.
5677 </p>
5678 </dd>
5679 <dt class="hdlist1">
5680 <code><strong>current</strong></code>
5681 </dt>
5682 <dd>
5684 The new access position will be <code><em>offset</em></code> bytes from the current
5685 access position; a negative <code><em>offset</em></code> moves the access position
5686 backwards in the file.
5687 </p>
5688 </dd>
5689 <dt class="hdlist1">
5690 <code><strong>end</strong></code>
5691 </dt>
5692 <dd>
5694 The new access position will be <code><em>offset</em></code> bytes from the end of
5695 the file. A negative <code><em>offset</em></code> places the access position before
5696 the end-of-file, and a positive <code><em>offset</em></code> places the access position
5697 after the end-of-file.
5698 </p>
5699 </dd>
5700 </dl></div>
5701 <div class="paragraph"><p>The <code><em>origin</em></code> argument defaults to <code>start</code>.</p></div>
5702 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
5703 <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
5704 of the standard I/O channels.</p></div>
5705 <div class="paragraph"><p>This command returns an empty string.</p></div>
5706 </div>
5707 <div class="sect2">
5708 <h3 id="_set">set</h3>
5709 <div class="paragraph"><p><code><strong>set</strong> <em>varName ?value?</em></code></p></div>
5710 <div class="paragraph"><p>Returns the value of variable <code><em>varName</em></code>.</p></div>
5711 <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>,
5712 creating a new variable if one doesn&#8217;t already exist, and return
5713 its value.</p></div>
5714 <div class="paragraph"><p>If <code><em>varName</em></code> contains an open parenthesis and ends with a
5715 close parenthesis, then it refers to an array element: the characters
5716 before the open parenthesis are the name of the array, and the characters
5717 between the parentheses are the index within the array.
5718 Otherwise <code><em>varName</em></code> refers to a scalar variable.</p></div>
5719 <div class="paragraph"><p>If no procedure is active, then <code><em>varName</em></code> refers to a global
5720 variable.</p></div>
5721 <div class="paragraph"><p>If a procedure is active, then <code><em>varName</em></code> refers to a parameter
5722 or local variable of the procedure, unless the <code><em>global</em></code> command
5723 has been invoked to declare <code><em>varName</em></code> to be global.</p></div>
5724 <div class="paragraph"><p>The <code>::</code> prefix may also be used to explicitly reference a variable
5725 in the global scope.</p></div>
5726 </div>
5727 <div class="sect2">
5728 <h3 id="_setref">setref</h3>
5729 <div class="paragraph"><p><code><strong>setref</strong> <em>reference string</em></code></p></div>
5730 <div class="paragraph"><p>Store a new string in <code><em>reference</em></code>, replacing the existing string.
5731 The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
5732 command.</p></div>
5733 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5734 </div>
5735 <div class="sect2">
5736 <h3 id="_signal">signal</h3>
5737 <div class="paragraph"><p>Command for signal handling.</p></div>
5738 <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>
5739 <div class="paragraph"><p>Commands which return a list of signal names do so using the canonical form:
5740 "<code>SIGINT SIGTERM</code>".</p></div>
5741 <div class="dlist"><dl>
5742 <dt class="hdlist1">
5743 <code><strong>signal handle</strong> ?<em>signals ...</em>?</code>
5744 </dt>
5745 <dd>
5747 If no signals are given, returns a list of all signals which are currently
5748 being handled.
5749 If signals are specified, these are added to the list of signals currently
5750 being handled.
5751 </p>
5752 </dd>
5753 <dt class="hdlist1">
5754 <code><strong>signal ignore</strong> ?<em>signals ...</em>?</code>
5755 </dt>
5756 <dd>
5758 If no signals are given, returns a lists all signals which are currently
5759 being ignored.
5760 If signals are specified, these are added to the list of signals
5761 currently being ignored. These signals are still delivered, but
5762 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
5763 <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to determine which signals have occurred but
5764 been ignored.
5765 </p>
5766 </dd>
5767 <dt class="hdlist1">
5768 <code><strong>signal default</strong> ?<em>signals ...</em>?</code>
5769 </dt>
5770 <dd>
5772 If no signals are given, returns a lists all signals which are currently have
5773 the default behaviour.
5774 If signals are specified, these are added to the list of signals which have
5775 the default behaviour.
5776 </p>
5777 </dd>
5778 <dt class="hdlist1">
5779 <code><strong>signal check ?-clear?</strong> ?<em>signals ...</em>?</code>
5780 </dt>
5781 <dd>
5783 Returns a list of signals which have been delivered to the process
5784 but are <em>ignored</em>. If signals are specified, only that set of signals will
5785 be checked, otherwise all signals will be checked.
5786 If <code>-clear</code> is specified, any signals returned are removed and will not be
5787 returned by subsequent calls to <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> unless delivered again.
5788 </p>
5789 </dd>
5790 <dt class="hdlist1">
5791 <code><strong>signal throw</strong> ?<em>signal</em>?</code>
5792 </dt>
5793 <dd>
5795 Raises the given signal, which defaults to <code>SIGINT</code> if not specified.
5796 The behaviour is identical to:
5797 </p>
5798 <div class="literalblock">
5799 <div class="content">
5800 <pre><code>kill signal [pid]</code></pre>
5801 </div></div>
5802 </dd>
5803 </dl></div>
5804 <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
5805 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>
5806 to immediately abort execution when the signal is delivered. Alternatively, <a href="#_signal"><strong><code>signal</code></strong></a> <code>ignore</code>
5807 is used in conjunction with <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to handle signal synchronously. Consider the
5808 two examples below.</p></div>
5809 <div class="paragraph"><p>Prevent a processing from taking too long</p></div>
5810 <div class="literalblock">
5811 <div class="content">
5812 <pre><code>signal handle SIGALRM
5813 alarm 20
5814 try -signal {
5815 .. possibly long running process ..
5816 alarm 0
5817 } on signal {sig} {
5818 puts stderr "Process took too long"
5819 }</code></pre>
5820 </div></div>
5821 <div class="paragraph"><p>Handle SIGHUP to reconfigure:</p></div>
5822 <div class="literalblock">
5823 <div class="content">
5824 <pre><code>signal ignore SIGHUP
5825 while {1} {
5826 ... handle configuration/reconfiguration ...
5827 while {[signal check -clear SIGHUP] eq ""} {
5828 ... do processing ..
5830 # Received SIGHUP, so reconfigure
5831 }</code></pre>
5832 </div></div>
5833 </div>
5834 <div class="sect2">
5835 <h3 id="_sleep">sleep</h3>
5836 <div class="paragraph"><p><code><strong>sleep</strong> <em>seconds</em></code></p></div>
5837 <div class="paragraph"><p>Pauses for the given number of seconds, which may be a floating
5838 point value less than one to sleep for less than a second, or an
5839 integer to sleep for one or more seconds.</p></div>
5840 </div>
5841 <div class="sect2">
5842 <h3 id="_source">source</h3>
5843 <div class="paragraph"><p><code><strong>source</strong> <em>fileName</em></code></p></div>
5844 <div class="paragraph"><p>Read file <code><em>fileName</em></code> and pass the contents to the Tcl interpreter
5845 as a sequence of commands to execute in the normal fashion. The return
5846 value of <a href="#_source"><strong><code>source</code></strong></a> is the return value of the last command executed
5847 from the file. If an error occurs in executing the contents of the
5848 file, then the <a href="#_source"><strong><code>source</code></strong></a> command will return that error.</p></div>
5849 <div class="paragraph"><p>If a <a href="#_return"><strong><code>return</code></strong></a> command is invoked from within the file, the remainder of
5850 the file will be skipped and the <a href="#_source"><strong><code>source</code></strong></a> command will return
5851 normally with the result from the <a href="#_return"><strong><code>return</code></strong></a> command.</p></div>
5852 </div>
5853 <div class="sect2">
5854 <h3 id="_split">split</h3>
5855 <div class="paragraph"><p><code><strong>split</strong> <em>string ?splitChars?</em></code></p></div>
5856 <div class="paragraph"><p>Returns a list created by splitting <code><em>string</em></code> at each character
5857 that is in the <code><em>splitChars</em></code> argument.</p></div>
5858 <div class="paragraph"><p>Each element of the result list will consist of the
5859 characters from <code><em>string</em></code> between instances of the
5860 characters in <code><em>splitChars</em></code>.</p></div>
5861 <div class="paragraph"><p>Empty list elements will be generated if <code><em>string</em></code> contains
5862 adjacent characters in <code><em>splitChars</em></code>, or if the first or last
5863 character of <code><em>string</em></code> is in <code><em>splitChars</em></code>.</p></div>
5864 <div class="paragraph"><p>If <code><em>splitChars</em></code> is an empty string then each character of
5865 <code><em>string</em></code> becomes a separate element of the result list.</p></div>
5866 <div class="paragraph"><p><code><em>splitChars</em></code> defaults to the standard white-space characters.
5867 For example,</p></div>
5868 <div class="literalblock">
5869 <div class="content">
5870 <pre><code>split "comp.unix.misc" .</code></pre>
5871 </div></div>
5872 <div class="paragraph"><p>returns <code><em>"comp unix misc"</em></code> and</p></div>
5873 <div class="literalblock">
5874 <div class="content">
5875 <pre><code>split "Hello world" {}</code></pre>
5876 </div></div>
5877 <div class="paragraph"><p>returns <code><em>"H e l l o { } w o r l d"</em></code>.</p></div>
5878 </div>
5879 <div class="sect2">
5880 <h3 id="_stackdump">stackdump</h3>
5881 <div class="paragraph"><p><code><strong>stackdump</strong> <em>stacktrace</em></code></p></div>
5882 <div class="paragraph"><p>Creates a human readable representation of a stack trace.</p></div>
5883 </div>
5884 <div class="sect2">
5885 <h3 id="_stacktrace">stacktrace</h3>
5886 <div class="paragraph"><p><code><strong>stacktrace</strong></code></p></div>
5887 <div class="paragraph"><p>Returns a live stack trace as a list of <code>proc file line proc file line ...</code>.
5888 Iteratively uses <a href="#_info"><strong><code>info</code></strong></a> <code>frame</code> to create the stack trace. This stack trace is in the
5889 same form as produced by <a href="#_catch"><strong><code>catch</code></strong></a> and <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code></p></div>
5890 <div class="paragraph"><p>See also <a href="#_stackdump"><strong><code>stackdump</code></strong></a>.</p></div>
5891 </div>
5892 <div class="sect2">
5893 <h3 id="_string">string</h3>
5894 <div class="paragraph"><p><code><strong>string</strong> <em>option arg ?arg ...?</em></code></p></div>
5895 <div class="paragraph"><p>Perform one of several string operations, depending on <code><em>option</em></code>.
5896 The legal options (which may be abbreviated) are:</p></div>
5897 <div class="dlist"><dl>
5898 <dt class="hdlist1">
5899 <code><strong>string bytelength</strong> <em>string</em></code>
5900 </dt>
5901 <dd>
5903 Returns the length of the string in bytes. This will return
5904 the same value as <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> if UTF-8 support is not enabled,
5905 or if the string is composed entirely of ASCII characters.
5906 See UTF-8 AND UNICODE.
5907 </p>
5908 </dd>
5909 <dt class="hdlist1">
5910 <code><strong>string byterange</strong> <em>string first last</em></code>
5911 </dt>
5912 <dd>
5914 Like <a href="#_string"><strong><code>string</code></strong></a> <code>range</code> except works on bytes rather than characters.
5915 These commands are identical if UTF-8 support is not enabled.
5916 </p>
5917 </dd>
5918 <dt class="hdlist1">
5919 <code><strong>string cat</strong> <em>?string1 string2 ...?</em></code>
5920 </dt>
5921 <dd>
5923 Concatenates the given strings into a single string.
5924 </p>
5925 </dd>
5926 <dt class="hdlist1">
5927 <code><strong>string compare ?-nocase?</strong> ?<strong>-length</strong> <em>len? string1 string2</em></code>
5928 </dt>
5929 <dd>
5931 Perform a character-by-character comparison of strings <code><em>string1</em></code> and
5932 <code><em>string2</em></code> in the same way as the C <em>strcmp</em> procedure. Return
5933 -1, 0, or 1, depending on whether <code><em>string1</em></code> is lexicographically
5934 less than, equal to, or greater than <code><em>string2</em></code>. If <code>-length</code>
5935 is specified, then only the first <code><em>len</em></code> characters are used
5936 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5937 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5938 </p>
5939 </dd>
5940 <dt class="hdlist1">
5941 <code><strong>string equal ?-nocase?</strong> <em>?<strong>-length</strong> len?</em> <em>string1 string2</em></code>
5942 </dt>
5943 <dd>
5945 Returns 1 if the strings are equal, or 0 otherwise. If <code>-length</code>
5946 is specified, then only the first <code><em>len</em></code> characters are used
5947 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5948 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5949 </p>
5950 </dd>
5951 <dt class="hdlist1">
5952 <code><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></code>
5953 </dt>
5954 <dd>
5956 Search <code><em>string2</em></code> for a sequence of characters that exactly match
5957 the characters in <code><em>string1</em></code>. If found, return the index of the
5958 first character in the first such match within <code><em>string2</em></code>. If not
5959 found, return -1. If <code><em>firstIndex</em></code> is specified, matching will start
5960 from <code><em>firstIndex</em></code> of <code><em>string1</em></code>.
5961 </p>
5962 </dd>
5963 <dt class="hdlist1">
5965 </dt>
5966 <dd>
5968 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>firstIndex</em></code>.
5969 </p>
5970 </dd>
5971 <dt class="hdlist1">
5972 <code><strong>string index</strong> <em>string charIndex</em></code>
5973 </dt>
5974 <dd>
5976 Returns the <code><em>charIndex</em></code><em>th character of the <code>'string</em></code>
5977 argument. A <code><em>charIndex</em></code> of 0 corresponds to the first
5978 character of the string.
5979 If <code><em>charIndex</em></code> is less than 0 or greater than
5980 or equal to the length of the string then an empty string is
5981 returned.
5982 </p>
5983 </dd>
5984 <dt class="hdlist1">
5986 </dt>
5987 <dd>
5989 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>charIndex</em></code>.
5990 </p>
5991 </dd>
5992 <dt class="hdlist1">
5993 <code><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></code>
5994 </dt>
5995 <dd>
5997 Returns 1 if <code><em>string</em></code> is a valid member of the specified character
5998 class, otherwise returns 0. If <code>-strict</code> is specified, then an
5999 empty string returns 0, otherwise an empty string will return 1
6000 on any class. The following character classes are recognized
6001 (the class name can be abbreviated):
6002 </p>
6003 </dd>
6004 <dt class="hdlist1">
6006 </dt>
6007 <dd>
6008 <div class="dlist"><dl>
6009 <dt class="hdlist1">
6010 <code>alnum</code>
6011 </dt>
6012 <dd>
6014 Any alphabet or digit character.
6015 </p>
6016 </dd>
6017 <dt class="hdlist1">
6018 <code>alpha</code>
6019 </dt>
6020 <dd>
6022 Any alphabet character.
6023 </p>
6024 </dd>
6025 <dt class="hdlist1">
6026 <code>ascii</code>
6027 </dt>
6028 <dd>
6030 Any character with a value less than 128 (those that are in the 7-bit ascii range).
6031 </p>
6032 </dd>
6033 <dt class="hdlist1">
6034 <code>control</code>
6035 </dt>
6036 <dd>
6038 Any control character.
6039 </p>
6040 </dd>
6041 <dt class="hdlist1">
6042 <code>digit</code>
6043 </dt>
6044 <dd>
6046 Any digit character.
6047 </p>
6048 </dd>
6049 <dt class="hdlist1">
6050 <code>double</code>
6051 </dt>
6052 <dd>
6054 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
6055 In case of under/overflow in the value, 0 is returned.
6056 </p>
6057 </dd>
6058 <dt class="hdlist1">
6059 <code>graph</code>
6060 </dt>
6061 <dd>
6063 Any printing character, except space.
6064 </p>
6065 </dd>
6066 <dt class="hdlist1">
6067 <code>integer</code>
6068 </dt>
6069 <dd>
6071 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
6072 </p>
6073 </dd>
6074 <dt class="hdlist1">
6075 <code>lower</code>
6076 </dt>
6077 <dd>
6079 Any lower case alphabet character.
6080 </p>
6081 </dd>
6082 <dt class="hdlist1">
6083 <code>print</code>
6084 </dt>
6085 <dd>
6087 Any printing character, including space.
6088 </p>
6089 </dd>
6090 <dt class="hdlist1">
6091 <code>punct</code>
6092 </dt>
6093 <dd>
6095 Any punctuation character.
6096 </p>
6097 </dd>
6098 <dt class="hdlist1">
6099 <code>space</code>
6100 </dt>
6101 <dd>
6103 Any space character.
6104 </p>
6105 </dd>
6106 <dt class="hdlist1">
6107 <code>upper</code>
6108 </dt>
6109 <dd>
6111 Any upper case alphabet character.
6112 </p>
6113 </dd>
6114 <dt class="hdlist1">
6115 <code>xdigit</code>
6116 </dt>
6117 <dd>
6119 Any hexadecimal digit character ([0-9A-Fa-f]).
6120 </p>
6121 </dd>
6122 </dl></div>
6123 </dd>
6124 <dt class="hdlist1">
6126 </dt>
6127 <dd>
6129 Note that string classification does <code><em>not</em></code> respect UTF-8. See UTF-8 AND UNICODE
6130 </p>
6131 </dd>
6132 <dt class="hdlist1">
6133 <code><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></code>
6134 </dt>
6135 <dd>
6137 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6138 the characters in <code><em>string1</em></code>. If found, return the index of the
6139 first character in the last such match within <code><em>string2</em></code>. If there
6140 is no match, then return -1. If <code><em>lastIndex</em></code> is specified, only characters
6141 up to <code><em>lastIndex</em></code> of <code><em>string2</em></code> will be considered in the match.
6142 </p>
6143 </dd>
6144 <dt class="hdlist1">
6146 </dt>
6147 <dd>
6149 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>lastIndex</em></code>.
6150 </p>
6151 </dd>
6152 <dt class="hdlist1">
6153 <code><strong>string length</strong> <em>string</em></code>
6154 </dt>
6155 <dd>
6157 Returns a decimal string giving the number of characters in <code><em>string</em></code>.
6158 If UTF-8 support is enabled, this may be different than the number of bytes.
6159 See UTF-8 AND UNICODE
6160 </p>
6161 </dd>
6162 <dt class="hdlist1">
6163 <code><strong>string map ?-nocase?</strong> <em>mapping string</em></code>
6164 </dt>
6165 <dd>
6167 Replaces substrings in <code><em>string</em></code> based on the key-value pairs in
6168 <code><em>mapping</em></code>, which is a list of <code>key value key value ...</code> as in the form
6169 returned by <a href="#_array"><strong><code>array</code></strong></a> <code>get</code>. Each instance of a key in the string will be
6170 replaced with its corresponding value. If <code>-nocase</code> is specified, then
6171 matching is done without regard to case differences. Both key and value may
6172 be multiple characters. Replacement is done in an ordered manner, so the
6173 key appearing first in the list will be checked first, and so on. <code><em>string</em></code> is
6174 only iterated over once, so earlier key replacements will have no affect for
6175 later key matches. For example,
6176 </p>
6177 <div class="literalblock">
6178 <div class="content">
6179 <pre><code>string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc</code></pre>
6180 </div></div>
6181 </dd>
6182 <dt class="hdlist1">
6184 </dt>
6185 <dd>
6187 will return the string <code>01321221</code>.
6188 </p>
6189 </dd>
6190 <dt class="hdlist1">
6192 </dt>
6193 <dd>
6195 Note that if an earlier key is a prefix of a later one, it will completely mask the later
6196 one. So if the previous example is reordered like this,
6197 </p>
6198 <div class="literalblock">
6199 <div class="content">
6200 <pre><code>string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc</code></pre>
6201 </div></div>
6202 </dd>
6203 <dt class="hdlist1">
6205 </dt>
6206 <dd>
6208 it will return the string <code>02c322c222c</code>.
6209 </p>
6210 </dd>
6211 <dt class="hdlist1">
6212 <code><strong>string match ?-nocase?</strong> <em>pattern string</em></code>
6213 </dt>
6214 <dd>
6216 See if <code><em>pattern</em></code> matches <code><em>string</em></code>; return 1 if it does, 0
6217 if it doesn&#8217;t. Matching is done in a fashion similar to that
6218 used by the C-shell. For the two strings to match, their contents
6219 must be identical except that the following special sequences
6220 may appear in <code><em>pattern</em></code>:
6221 </p>
6222 <div class="dlist"><dl>
6223 <dt class="hdlist1">
6224 <code>*</code>
6225 </dt>
6226 <dd>
6228 Matches any sequence of characters in <code><em>string</em></code>,
6229 including a null string.
6230 </p>
6231 </dd>
6232 <dt class="hdlist1">
6233 <code>?</code>
6234 </dt>
6235 <dd>
6237 Matches any single character in <code><em>string</em></code>.
6238 </p>
6239 </dd>
6240 <dt class="hdlist1">
6241 <code>[<em>chars</em>]</code>
6242 </dt>
6243 <dd>
6245 Matches any character in the set given by <code><em>chars</em></code>.
6246 If a sequence of the form <code><em>x-y</em></code> appears in <code><em>chars</em></code>,
6247 then any character between <code><em>x</em></code> and <code><em>y</em></code>, inclusive,
6248 will match.
6249 </p>
6250 </dd>
6251 <dt class="hdlist1">
6252 <code>\x</code>
6253 </dt>
6254 <dd>
6256 Matches the single character <code><em>x</em></code>. This provides a way of
6257 avoiding the special interpretation of the characters <code>\*?[]</code>
6258 in <code><em>pattern</em></code>.
6259 </p>
6260 </dd>
6261 </dl></div>
6262 </dd>
6263 <dt class="hdlist1">
6265 </dt>
6266 <dd>
6268 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6269 </p>
6270 </dd>
6271 <dt class="hdlist1">
6272 <code><strong>string range</strong> <em>string first last</em></code>
6273 </dt>
6274 <dd>
6276 Returns a range of consecutive characters from <code><em>string</em></code>, starting
6277 with the character whose index is <code><em>first</em></code> and ending with the
6278 character whose index is <code><em>last</em></code>. An index of 0 refers to the
6279 first character of the string.
6280 </p>
6281 </dd>
6282 <dt class="hdlist1">
6284 </dt>
6285 <dd>
6287 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.
6288 </p>
6289 </dd>
6290 <dt class="hdlist1">
6292 </dt>
6293 <dd>
6295 If <code><em>first</em></code> is less than zero then it is treated as if it were zero, and
6296 if <code><em>last</em></code> is greater than or equal to the length of the string then
6297 it is treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than
6298 <code><em>last</em></code> then an empty string is returned.
6299 </p>
6300 </dd>
6301 <dt class="hdlist1">
6302 <code><strong>string repeat</strong> <em>string count</em></code>
6303 </dt>
6304 <dd>
6306 Returns a new string consisting of <code><em>string</em></code> repeated <code><em>count</em></code> times.
6307 </p>
6308 </dd>
6309 <dt class="hdlist1">
6310 <code><strong>string replace</strong> <em>string first last ?newstring?</em></code>
6311 </dt>
6312 <dd>
6314 Removes a range of consecutive characters from <code><em>string</em></code>, starting
6315 with the character whose index is <code><em>first</em></code> and ending with the
6316 character whose index is <code><em>last</em></code>. If <code><em>newstring</em></code> is specified,
6317 then it is placed in the removed character range. If <code><em>first</em></code> is
6318 less than zero then it is treated as if it were zero, and if <code><em>last</em></code>
6319 is greater than or equal to the length of the string then it is
6320 treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than <code><em>last</em></code>
6321 or the length of the initial string, or <code><em>last</em></code> is less than 0,
6322 then the initial string is returned untouched.
6323 </p>
6324 </dd>
6325 <dt class="hdlist1">
6326 <code><strong>string reverse</strong> <em>string</em></code>
6327 </dt>
6328 <dd>
6330 Returns a string that is the same length as <code><em>string</em></code> but
6331 with its characters in the reverse order.
6332 </p>
6333 </dd>
6334 <dt class="hdlist1">
6335 <code><strong>string tolower</strong> <em>string</em></code>
6336 </dt>
6337 <dd>
6339 Returns a value equal to <code><em>string</em></code> except that all upper case
6340 letters have been converted to lower case.
6341 </p>
6342 </dd>
6343 <dt class="hdlist1">
6344 <code><strong>string totitle</strong> <em>string</em></code>
6345 </dt>
6346 <dd>
6348 Returns a value equal to <code><em>string</em></code> except that the first character
6349 is converted to title case (or upper case if there is no UTF-8 titlecase variant)
6350 and all remaining characters have been converted to lower case.
6351 </p>
6352 </dd>
6353 <dt class="hdlist1">
6354 <code><strong>string toupper</strong> <em>string</em></code>
6355 </dt>
6356 <dd>
6358 Returns a value equal to <code><em>string</em></code> except that all lower case
6359 letters have been converted to upper case.
6360 </p>
6361 </dd>
6362 <dt class="hdlist1">
6363 <code><strong>string trim</strong> <em>string ?chars?</em></code>
6364 </dt>
6365 <dd>
6367 Returns a value equal to <code><em>string</em></code> except that any leading
6368 or trailing characters from the set given by <code><em>chars</em></code> are
6369 removed.
6370 If <code><em>chars</em></code> is not specified then white space is removed
6371 (spaces, tabs, newlines, and carriage returns).
6372 </p>
6373 </dd>
6374 <dt class="hdlist1">
6375 <code><strong>string trimleft</strong> <em>string ?chars?</em></code>
6376 </dt>
6377 <dd>
6379 Returns a value equal to <code><em>string</em></code> except that any
6380 leading characters from the set given by <code><em>chars</em></code> are
6381 removed.
6382 If <code><em>chars</em></code> is not specified then white space is removed
6383 (spaces, tabs, newlines, and carriage returns).
6384 </p>
6385 </dd>
6386 <dt class="hdlist1">
6387 <code><strong>string trimright</strong> <em>string ?chars?</em></code>
6388 </dt>
6389 <dd>
6391 Returns a value equal to <code><em>string</em></code> except that any
6392 trailing characters from the set given by <code><em>chars</em></code> are
6393 removed.
6394 If <code><em>chars</em></code> is not specified then white space is removed
6395 (spaces, tabs, newlines, and carriage returns).
6396 Null characters are always removed.
6397 </p>
6398 </dd>
6399 </dl></div>
6400 </div>
6401 <div class="sect2">
6402 <h3 id="_subst">subst</h3>
6403 <div class="paragraph"><p><code><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></code></p></div>
6404 <div class="paragraph"><p>This command performs variable substitutions, command substitutions,
6405 and backslash substitutions on its string argument and returns the
6406 fully-substituted result. The substitutions are performed in exactly
6407 the same way as for Tcl commands. As a result, the string argument
6408 is actually substituted twice, once by the Tcl parser in the usual
6409 fashion for Tcl commands, and again by the subst command.</p></div>
6410 <div class="paragraph"><p>If any of the <code>-nobackslashes</code>, <code>-nocommands</code>, or <code>-novariables</code> are
6411 specified, then the corresponding substitutions are not performed.
6412 For example, if <code>-nocommands</code> is specified, no command substitution
6413 is performed: open and close brackets are treated as ordinary
6414 characters with no special interpretation.</p></div>
6415 <div class="paragraph"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
6416 special treatment to double quotes or curly braces. For example,
6417 the following script returns <code>xyz {44}</code>, not <code>xyz {$a}</code>.</p></div>
6418 <div class="literalblock">
6419 <div class="content">
6420 <pre><code>set a 44
6421 subst {xyz {$a}}</code></pre>
6422 </div></div>
6423 </div>
6424 <div class="sect2">
6425 <h3 id="_switch">switch</h3>
6426 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string pattern body ?pattern body ...?</em></code></p></div>
6427 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string {pattern body ?pattern body ...?}</em></code></p></div>
6428 <div class="paragraph"><p>The <a href="#_switch"><strong><code>switch</code></strong></a> command matches its string argument against each of
6429 the pattern arguments in order. As soon as it finds a pattern that
6430 matches string it evaluates the following body and returns the
6431 result of that evaluation. If the last pattern argument is default
6432 then it matches anything. If no pattern argument matches string and
6433 no default is given, then the <a href="#_switch"><strong><code>switch</code></strong></a> command returns an empty string.
6434 If the initial arguments to switch start with - then they are treated
6435 as options. The following options are currently supported:</p></div>
6436 <div class="dlist"><dl>
6437 <dt class="hdlist1">
6438 <code>-exact</code>
6439 </dt>
6440 <dd>
6442 Use exact matching when comparing string to a
6443 pattern. This is the default.
6444 </p>
6445 </dd>
6446 <dt class="hdlist1">
6447 <code>-glob</code>
6448 </dt>
6449 <dd>
6451 When matching string to the patterns, use glob-style
6452 matching (i.e. the same as implemented by the string
6453 match command).
6454 </p>
6455 </dd>
6456 <dt class="hdlist1">
6457 <code>-regexp</code>
6458 </dt>
6459 <dd>
6461 When matching string to the patterns, use regular
6462 expression matching (i.e. the same as implemented
6463 by the regexp command).
6464 </p>
6465 </dd>
6466 <dt class="hdlist1">
6467 <code>-command <em>commandname</em></code>
6468 </dt>
6469 <dd>
6471 When matching string to the patterns, use the given command, which
6472 must be a single word. The command is invoked as
6473 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
6474 and must return 1 if matched, or 0 if not.
6475 </p>
6476 </dd>
6477 <dt class="hdlist1">
6478 <code>--</code>
6479 </dt>
6480 <dd>
6482 Marks the end of options. The argument following
6483 this one will be treated as string even if it starts
6484 with a <code>-</code>.
6485 </p>
6486 </dd>
6487 </dl></div>
6488 <div class="paragraph"><p>Two syntaxes are provided for the pattern and body arguments. The
6489 first uses a separate argument for each of the patterns and commands;
6490 this form is convenient if substitutions are desired on some of the
6491 patterns or commands. The second form places all of the patterns
6492 and commands together into a single argument; the argument must
6493 have proper list structure, with the elements of the list being the
6494 patterns and commands. The second form makes it easy to construct
6495 multi-line <a href="#_switch"><strong><code>switch</code></strong></a> commands, since the braces around the whole list
6496 make it unnecessary to include a backslash at the end of each line.
6497 Since the pattern arguments are in braces in the second form, no
6498 command or variable substitutions are performed on them; this makes
6499 the behaviour of the second form different than the first form in
6500 some cases.</p></div>
6501 <div class="paragraph"><p>If a body is specified as <code>-</code> it means that the body for the next
6502 pattern should also be used as the body for this pattern (if the
6503 next pattern also has a body of <code>-</code> then the body after that is
6504 used, and so on). This feature makes it possible to share a single
6505 body among several patterns.</p></div>
6506 <div class="paragraph"><p>Below are some examples of <a href="#_switch"><strong><code>switch</code></strong></a> commands:</p></div>
6507 <div class="literalblock">
6508 <div class="content">
6509 <pre><code>switch abc a - b {format 1} abc {format 2} default {format 3}</code></pre>
6510 </div></div>
6511 <div class="paragraph"><p>will return 2,</p></div>
6512 <div class="literalblock">
6513 <div class="content">
6514 <pre><code>switch -regexp aaab {
6515 ^a.*b$ -
6516 b {format 1}
6517 a* {format 2}
6518 default {format 3}
6519 }</code></pre>
6520 </div></div>
6521 <div class="paragraph"><p>will return 1, and</p></div>
6522 <div class="literalblock">
6523 <div class="content">
6524 <pre><code>switch xyz {
6526 b {format 1}
6527 a* {format 2}
6528 default {format 3}
6529 }</code></pre>
6530 </div></div>
6531 <div class="paragraph"><p>will return 3.</p></div>
6532 </div>
6533 <div class="sect2">
6534 <h3 id="_tailcall">tailcall</h3>
6535 <div class="paragraph"><p><code><strong>tailcall</strong> <em>cmd ?arg...?</em></code></p></div>
6536 <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
6537 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
6538 <div class="paragraph"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
6539 <div class="literalblock">
6540 <div class="content">
6541 <pre><code>tailcall a b c</code></pre>
6542 </div></div>
6543 <div class="literalblock">
6544 <div class="content">
6545 <pre><code>return [uplevel 1 [list a b c]]</code></pre>
6546 </div></div>
6547 <div class="paragraph"><p><a href="#_tailcall"><strong><code>tailcall</code></strong></a> is useful as a dispatch mechanism:</p></div>
6548 <div class="literalblock">
6549 <div class="content">
6550 <pre><code>proc a {cmd args} {
6551 tailcall sub_$cmd {*}$args
6553 proc sub_cmd1 ...
6554 proc sub_cmd2 ...</code></pre>
6555 </div></div>
6556 </div>
6557 <div class="sect2">
6558 <h3 id="_tell">tell</h3>
6559 <div class="paragraph"><p><code><strong>tell</strong> <em>fileId</em></code></p></div>
6560 <div class="paragraph"><p><code><em>fileId</em> <strong>tell</strong></code></p></div>
6561 <div class="paragraph"><p>Returns a decimal string giving the current access position in
6562 <code><em>fileId</em></code>.</p></div>
6563 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
6564 <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
6565 of the standard I/O channels.</p></div>
6566 </div>
6567 <div class="sect2">
6568 <h3 id="_throw">throw</h3>
6569 <div class="paragraph"><p><code><strong>throw</strong> <em>code ?msg?</em></code></p></div>
6570 <div class="paragraph"><p>This command throws an exception (return) code along with an optional message.
6571 This command is mostly for convenient usage with <a href="#_try"><strong><code>try</code></strong></a>.</p></div>
6572 <div class="paragraph"><p>The command <code>throw break</code> is equivalent to <code>break</code>.
6573 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>
6574 </div>
6575 <div class="sect2">
6576 <h3 id="_time">time</h3>
6577 <div class="paragraph"><p><code><strong>time</strong> <em>command ?count?</em></code></p></div>
6578 <div class="paragraph"><p>This command will call the Tcl interpreter <code><em>count</em></code>
6579 times to execute <code><em>command</em></code> (or once if <code><em>count</em></code> isn&#8217;t
6580 specified). It will then return a string of the form</p></div>
6581 <div class="literalblock">
6582 <div class="content">
6583 <pre><code>503 microseconds per iteration</code></pre>
6584 </div></div>
6585 <div class="paragraph"><p>which indicates the average amount of time required per iteration,
6586 in microseconds.</p></div>
6587 <div class="paragraph"><p>Time is measured in elapsed time, not CPU time.</p></div>
6588 </div>
6589 <div class="sect2">
6590 <h3 id="_try">try</h3>
6591 <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>
6592 <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>
6593 <div class="paragraph"><p>This interpeter first evaluates <code><em>tryscript</em></code> under the effect of the catch
6594 options <code><em>catchopts</em></code> (e.g. <code>-signal -noexit --</code>, see <a href="#_catch"><strong><code>catch</code></strong></a>).</p></div>
6595 <div class="paragraph"><p>It then evaluates the script for the first matching <em>on</em> handler
6596 (there many be zero or more) based on the return code from the <a href="#_try"><strong><code>try</code></strong></a>
6597 section. For example a normal <code>JIM_ERR</code> error will be matched by
6598 an <em>on error</em> handler.</p></div>
6599 <div class="paragraph"><p>Finally, any <code><em>finalscript</em></code> is evaluated.</p></div>
6600 <div class="paragraph"><p>The result of this command is the result of <code><em>tryscript</em></code>, except in the
6601 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
6602 in which case the result is this new exception.</p></div>
6603 <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.)
6604 or as integers.</p></div>
6605 <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
6606 the matching handler.</p></div>
6607 <div class="paragraph"><p>For example:</p></div>
6608 <div class="literalblock">
6609 <div class="content">
6610 <pre><code>set f [open input]
6611 try -signal {
6612 process $f
6613 } on {continue break} {} {
6614 error "Unexpected break/continue"
6615 } on error {msg opts} {
6616 puts "Dealing with error"
6617 return {*}$opts $msg
6618 } on signal sig {
6619 puts "Got signal: $sig"
6620 } finally {
6621 $f close
6622 }</code></pre>
6623 </div></div>
6624 <div class="paragraph"><p>If break, continue or error are raised, they are dealt with by the matching
6625 handler.</p></div>
6626 <div class="paragraph"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6627 <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>
6628 </div>
6629 <div class="sect2">
6630 <h3 id="_unknown">unknown</h3>
6631 <div class="paragraph"><p><code><strong>unknown</strong> <em>cmdName ?arg arg &#8230;?</em></code></p></div>
6632 <div class="paragraph"><p>This command doesn&#8217;t actually exist as part of Tcl, but Tcl will
6633 invoke it if it does exist.</p></div>
6634 <div class="paragraph"><p>If the Tcl interpreter encounters a command name for which there
6635 is not a defined command, then Tcl checks for the existence of
6636 a command named <a href="#_unknown"><strong><code>unknown</code></strong></a>.</p></div>
6637 <div class="paragraph"><p>If there is no such command, then the interpreter returns an
6638 error.</p></div>
6639 <div class="paragraph"><p>If the <a href="#_unknown"><strong><code>unknown</code></strong></a> command exists, then it is invoked with
6640 arguments consisting of the fully-substituted name and arguments
6641 for the original non-existent command.</p></div>
6642 <div class="paragraph"><p>The <a href="#_unknown"><strong><code>unknown</code></strong></a> command typically does things like searching
6643 through library directories for a command procedure with the name
6644 <code><em>cmdName</em></code>, or expanding abbreviated command names to full-length,
6645 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6646 <div class="paragraph"><p>In some cases (such as expanding abbreviations) <a href="#_unknown"><strong><code>unknown</code></strong></a> will
6647 change the original command slightly and then (re-)execute it.
6648 The result of the <a href="#_unknown"><strong><code>unknown</code></strong></a> command is used as the result for
6649 the original non-existent command.</p></div>
6650 </div>
6651 <div class="sect2">
6652 <h3 id="_unset">unset</h3>
6653 <div class="paragraph"><p><code><strong>unset ?-nocomplain? ?--?</strong> <em>?name name &#8230;?</em></code></p></div>
6654 <div class="paragraph"><p>Remove variables.
6655 Each <code><em>name</em></code> is a variable name, specified in any of the
6656 ways acceptable to the <a href="#_set"><strong><code>set</code></strong></a> command.</p></div>
6657 <div class="paragraph"><p>If a <code><em>name</em></code> refers to an element of an array, then that
6658 element is removed without affecting the rest of the array.</p></div>
6659 <div class="paragraph"><p>If a <code><em>name</em></code> consists of an array name with no parenthesized
6660 index, then the entire array is deleted.</p></div>
6661 <div class="paragraph"><p>The <a href="#_unset"><strong><code>unset</code></strong></a> command returns an empty string as result.</p></div>
6662 <div class="paragraph"><p>An error occurs if any of the variables doesn&#8217;t exist, unless <em>-nocomplain</em>
6663 is specified. The <em>--</em> argument may be specified to stop option processing
6664 in case the variable name may be <em>-nocomplain</em>.</p></div>
6665 </div>
6666 <div class="sect2">
6667 <h3 id="_upcall">upcall</h3>
6668 <div class="paragraph"><p><code><strong>upcall</strong> <em>command ?args &#8230;?</em></code></p></div>
6669 <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
6670 the previous, hidden version of the same command.</p></div>
6671 <div class="paragraph"><p>If there is no previous definition of the command, an error is returned.</p></div>
6672 </div>
6673 <div class="sect2">
6674 <h3 id="_uplevel">uplevel</h3>
6675 <div class="paragraph"><p><code><strong>uplevel</strong> <em>?level? command ?command &#8230;?</em></code></p></div>
6676 <div class="paragraph"><p>All of the <code><em>command</em></code> arguments are concatenated as if they had
6677 been passed to <a href="#_concat"><strong><code>concat</code></strong></a>; the result is then evaluated in the
6678 variable context indicated by <code><em>level</em></code>. <a href="#_uplevel"><strong><code>uplevel</code></strong></a> returns
6679 the result of that evaluation. If <code><em>level</em></code> is an integer, then
6680 it gives a distance (up the procedure calling stack) to move before
6681 executing the command. If <code><em>level</em></code> consists of <code>#</code> followed by
6682 a number then the number gives an absolute level number. If <code><em>level</em></code>
6683 is omitted then it defaults to <code>1</code>. <code><em>level</em></code> cannot be
6684 defaulted if the first <code><em>command</em></code> argument starts with a digit or <code>#</code>.</p></div>
6685 <div class="paragraph"><p>For example, suppose that procedure <em>a</em> was invoked
6686 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6687 Suppose that <em>c</em> invokes the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command. If <code><em>level</em></code>
6688 is <code>1</code> or <code>#2</code> or omitted, then the command will be executed
6689 in the variable context of <em>b</em>. If <code><em>level</em></code> is <code>2</code> or <code>#1</code>
6690 then the command will be executed in the variable context of <em>a</em>.</p></div>
6691 <div class="paragraph"><p>If <code><em>level</em></code> is <em>3</em> or <code>#0</code> then the command will be executed
6692 at top-level (only global variables will be visible).
6693 The <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command causes the invoking procedure to disappear
6694 from the procedure calling stack while the command is being executed.
6695 In the above example, suppose <em>c</em> invokes the command</p></div>
6696 <div class="literalblock">
6697 <div class="content">
6698 <pre><code>uplevel 1 {set x 43; d}</code></pre>
6699 </div></div>
6700 <div class="paragraph"><p>where <em>d</em> is another Tcl procedure. The <a href="#_set"><strong><code>set</code></strong></a> command will
6701 modify the variable <em>x</em> in <em>b&#8217;s context, and 'd</em> will execute
6702 at level 3, as if called from <em>b</em>. If it in turn executes
6703 the command</p></div>
6704 <div class="literalblock">
6705 <div class="content">
6706 <pre><code>uplevel {set x 42}</code></pre>
6707 </div></div>
6708 <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
6709 context: the procedure 'c</em> does not appear to be on the call stack
6710 when <em>d</em> is executing. The command <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> may
6711 be used to obtain the level of the current procedure.</p></div>
6712 <div class="paragraph"><p><a href="#_uplevel"><strong><code>uplevel</code></strong></a> makes it possible to implement new control
6713 constructs as Tcl procedures (for example, <a href="#_uplevel"><strong><code>uplevel</code></strong></a> could
6714 be used to implement the <a href="#_while"><strong><code>while</code></strong></a> construct as a Tcl procedure).</p></div>
6715 </div>
6716 <div class="sect2">
6717 <h3 id="_upvar">upvar</h3>
6718 <div class="paragraph"><p><code><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar &#8230;?</em></code></p></div>
6719 <div class="paragraph"><p>This command arranges for one or more local variables in the current
6720 procedure to refer to variables in an enclosing procedure call or
6721 to global variables.</p></div>
6722 <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>
6723 command, and may be omitted if the first letter of the first <code><em>otherVar</em></code>
6724 isn&#8217;t <code>#</code> or a digit (it defaults to <em>1</em>).</p></div>
6725 <div class="paragraph"><p>For each <code><em>otherVar</em></code> argument, <a href="#_upvar"><strong><code>upvar</code></strong></a> makes the variable
6726 by that name in the procedure frame given by <code><em>level</em></code> (or at
6727 global level, if <code><em>level</em></code> is <code>#0</code>) accessible
6728 in the current procedure by the name given in the corresponding
6729 <code><em>myVar</em></code> argument.</p></div>
6730 <div class="paragraph"><p>The variable named by <code><em>otherVar</em></code> need not exist at the time of the
6731 call; it will be created the first time <code><em>myVar</em></code> is referenced, just like
6732 an ordinary variable.</p></div>
6733 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> may only be invoked from within procedures.</p></div>
6734 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> returns an empty string.</p></div>
6735 <div class="paragraph"><p>The <a href="#_upvar"><strong><code>upvar</code></strong></a> command simplifies the implementation of call-by-name
6736 procedure calling and also makes it easier to build new control constructs
6737 as Tcl procedures.
6738 For example, consider the following procedure:</p></div>
6739 <div class="literalblock">
6740 <div class="content">
6741 <pre><code>proc add2 name {
6742 upvar $name x
6743 set x [expr $x+2]
6744 }</code></pre>
6745 </div></div>
6746 <div class="paragraph"><p><em>add2</em> is invoked with an argument giving the name of a variable,
6747 and it adds two to the value of that variable.
6748 Although <em>add2</em> could have been implemented using <a href="#_uplevel"><strong><code>uplevel</code></strong></a>
6749 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>
6750 to access the variable in the caller&#8217;s procedure frame.</p></div>
6751 </div>
6752 <div class="sect2">
6753 <h3 id="_while">while</h3>
6754 <div class="paragraph"><p><code><strong>while</strong> <em>test body</em></code></p></div>
6755 <div class="paragraph"><p>The <code><em>while</em></code> command evaluates <code><em>test</em></code> as an expression
6756 (in the same way that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument).
6757 The value of the expression must be numeric; if it is non-zero
6758 then <code><em>body</em></code> is executed by passing it to the Tcl interpreter.</p></div>
6759 <div class="paragraph"><p>Once <code><em>body</em></code> has been executed then <code><em>test</em></code> is evaluated
6760 again, and the process repeats until eventually <code><em>test</em></code>
6761 evaluates to a zero numeric value. <a href="#_continue"><strong><code>continue</code></strong></a>
6762 commands may be executed inside <code><em>body</em></code> to terminate the current
6763 iteration of the loop, and <a href="#_break"><strong><code>break</code></strong></a>
6764 commands may be executed inside <code><em>body</em></code> to cause immediate
6765 termination of the <a href="#_while"><strong><code>while</code></strong></a> command.</p></div>
6766 <div class="paragraph"><p>The <a href="#_while"><strong><code>while</code></strong></a> command always returns an empty string.</p></div>
6767 </div>
6768 </div>
6769 </div>
6770 <div class="sect1">
6771 <h2 id="_optional_extensions">OPTIONAL-EXTENSIONS</h2>
6772 <div class="sectionbody">
6773 <div class="paragraph"><p>The following extensions may or may not be available depending upon
6774 what options were selected when Jim Tcl was built.</p></div>
6775 <div class="sect2">
6776 <h3 id="cmd_1">posix: os.fork, os.wait, os.gethostname, os.getids, os.uptime</h3>
6777 <div class="dlist"><dl>
6778 <dt class="hdlist1">
6779 <code><strong>os.fork</strong></code>
6780 </dt>
6781 <dd>
6783 Invokes <em>fork(2)</em> and returns the result.
6784 </p>
6785 </dd>
6786 <dt class="hdlist1">
6787 <code><strong>os.wait -nohang</strong> <em>pid</em></code>
6788 </dt>
6789 <dd>
6791 Invokes waitpid(2), with WNOHANG if <code>-nohang</code> is specified.
6792 Returns a list of 3 elements.
6793 </p>
6794 <div class="literalblock">
6795 <div class="content">
6796 <pre><code>{0 none 0} if -nohang is specified, and the process is still alive.</code></pre>
6797 </div></div>
6798 <div class="literalblock">
6799 <div class="content">
6800 <pre><code>{-1 error &lt;error-description&gt;} if the process does not exist or has already been waited for.</code></pre>
6801 </div></div>
6802 <div class="literalblock">
6803 <div class="content">
6804 <pre><code>{&lt;pid&gt; exit &lt;exit-status&gt;} if the process exited normally.</code></pre>
6805 </div></div>
6806 <div class="literalblock">
6807 <div class="content">
6808 <pre><code>{&lt;pid&gt; signal &lt;signal-number&gt;} if the process terminated on a signal.</code></pre>
6809 </div></div>
6810 <div class="literalblock">
6811 <div class="content">
6812 <pre><code>{&lt;pid&gt; other 0} otherwise (core dump, stopped, continued, etc.)</code></pre>
6813 </div></div>
6814 </dd>
6815 <dt class="hdlist1">
6816 <code><strong>os.gethostname</strong></code>
6817 </dt>
6818 <dd>
6820 Invokes <em>gethostname(3)</em> and returns the result.
6821 </p>
6822 </dd>
6823 <dt class="hdlist1">
6824 <code><strong>os.getids</strong></code>
6825 </dt>
6826 <dd>
6828 Returns the various user/group ids for the current process.
6829 </p>
6830 <div class="literalblock">
6831 <div class="content">
6832 <pre><code>jim&gt; os.getids
6833 uid 1000 euid 1000 gid 100 egid 100</code></pre>
6834 </div></div>
6835 </dd>
6836 <dt class="hdlist1">
6837 <code><strong>os.uptime</strong></code>
6838 </dt>
6839 <dd>
6841 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
6842 </p>
6843 </dd>
6844 </dl></div>
6845 </div>
6846 </div>
6847 </div>
6848 <div class="sect1">
6849 <h2 id="_ansi_i_o_aio_and_eventloop_api">ANSI I/O (aio) and EVENTLOOP API</h2>
6850 <div class="sectionbody">
6851 <div class="paragraph"><p>Jim provides an alternative object-based API for I/O.</p></div>
6852 <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>
6853 <div class="sect2">
6854 <h3 id="_aio">aio</h3>
6855 <div class="dlist"><dl>
6856 <dt class="hdlist1">
6857 <code>$handle <strong>accept</strong> ?addrvar?</code>
6858 </dt>
6859 <dd>
6861 Server socket only: Accept a connection and return stream.
6862 If <code><em>addrvar</em></code> is specified, the address of the connected client is stored
6863 in the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
6864 </p>
6865 </dd>
6866 <dt class="hdlist1">
6867 <code>$handle <strong>buffering none|line|full</strong></code>
6868 </dt>
6869 <dd>
6871 Sets the buffering mode of the stream.
6872 </p>
6873 </dd>
6874 <dt class="hdlist1">
6875 <code>$handle <strong>close</strong> ?r(ead)|w(rite)?</code>
6876 </dt>
6877 <dd>
6879 Closes the stream.
6880 The two-argument form is a "half-close" on a socket. See the <code>shutdown(2)</code> man page.
6881 </p>
6882 </dd>
6883 <dt class="hdlist1">
6884 <code>$handle <strong>copyto</strong> <em>tofd ?size?</em></code>
6885 </dt>
6886 <dd>
6888 Copy bytes to the file descriptor <code><em>tofd</em></code>. If <code><em>size</em></code> is specified, at most
6889 that many bytes will be copied. Otherwise copying continues until the end
6890 of the input file. Returns the number of bytes actually copied.
6891 </p>
6892 </dd>
6893 <dt class="hdlist1">
6894 <code>$handle <strong>eof</strong></code>
6895 </dt>
6896 <dd>
6898 Returns 1 if stream is at eof
6899 </p>
6900 </dd>
6901 <dt class="hdlist1">
6902 <code>$handle <strong>filename</strong></code>
6903 </dt>
6904 <dd>
6906 Returns the original filename associated with the handle.
6907 Handles returned by <a href="#_socket"><strong><code>socket</code></strong></a> give the socket type instead of a filename.
6908 </p>
6909 </dd>
6910 <dt class="hdlist1">
6911 <code>$handle <strong>flush</strong></code>
6912 </dt>
6913 <dd>
6915 Flush the stream
6916 </p>
6917 </dd>
6918 <dt class="hdlist1">
6919 <code>$handle <strong>gets</strong> <em>?var?</em></code>
6920 </dt>
6921 <dd>
6923 Read one line and return it or store it in the var
6924 </p>
6925 </dd>
6926 <dt class="hdlist1">
6927 <code>$handle <strong>isatty</strong></code>
6928 </dt>
6929 <dd>
6931 Returns 1 if the stream is a tty device.
6932 </p>
6933 </dd>
6934 <dt class="hdlist1">
6935 <code>$handle <strong>ndelay ?0|1?</strong></code>
6936 </dt>
6937 <dd>
6939 Set O_NDELAY (if arg). Returns current/new setting.
6940 Note that in general ANSI I/O interacts badly with non-blocking I/O.
6941 Use with care.
6942 </p>
6943 </dd>
6944 <dt class="hdlist1">
6945 <code>$handle <strong>puts ?-nonewline?</strong> <em>str</em></code>
6946 </dt>
6947 <dd>
6949 Write the string, with newline unless -nonewline
6950 </p>
6951 </dd>
6952 <dt class="hdlist1">
6953 <code>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></code>
6954 </dt>
6955 <dd>
6957 Read and return bytes from the stream. To eof if no len.
6958 </p>
6959 </dd>
6960 <dt class="hdlist1">
6961 <code>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></code>
6962 </dt>
6963 <dd>
6965 Receives a message from the handle via recvfrom(2) and returns it.
6966 At most <code><em>maxlen</em></code> bytes are read.
6967 If <code><em>addrvar</em></code> is specified, the sending address of the message is stored in
6968 the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
6969 </p>
6970 </dd>
6971 <dt class="hdlist1">
6972 <code>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></code>
6973 </dt>
6974 <dd>
6976 Seeks in the stream (default <em>current</em>)
6977 </p>
6978 </dd>
6979 <dt class="hdlist1">
6980 <code>$handle <strong>sendto</strong> <em>str ?addr:?port</em></code>
6981 </dt>
6982 <dd>
6984 Sends the string, <code><em>str</em></code>, to the given address via the socket using sendto(2).
6985 This is intended for udp/dgram sockets and may give an error or behave in unintended
6986 ways for other handle types.
6987 Returns the number of bytes written.
6988 </p>
6989 </dd>
6990 <dt class="hdlist1">
6991 <code>$handle <strong>tell</strong></code>
6992 </dt>
6993 <dd>
6995 Returns the current seek position
6996 </p>
6997 </dd>
6998 </dl></div>
6999 </div>
7000 <div class="sect2">
7001 <h3 id="_fconfigure">fconfigure</h3>
7002 <div class="dlist"><dl>
7003 <dt class="hdlist1">
7004 <code><strong>fconfigure</strong> <em>handle</em> <strong>?-blocking 0|1? ?-buffering noneline|full? ?-translation</strong> <em>mode</em>?</code>
7005 </dt>
7006 <dd>
7008 For compatibility with Tcl, a limited form of the <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a>
7009 command is supported.
7010 </p>
7011 <div class="ulist"><ul>
7012 <li>
7014 <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>
7015 </p>
7016 </li>
7017 <li>
7019 <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>
7020 </p>
7021 </li>
7022 <li>
7024 <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a> <code>... -translation</code> is accepted but ignored
7025 </p>
7026 </li>
7027 </ul></div>
7028 </dd>
7029 </dl></div>
7030 </div>
7031 <div class="sect2">
7032 <h3 id="cmd_2">eventloop: after, vwait, update</h3>
7033 <div class="paragraph"><p>The following commands allow a script to be invoked when the given condition occurs.
7034 If no script is given, returns the current script. If the given script is the empty, the
7035 handler is removed.</p></div>
7036 <div class="dlist"><dl>
7037 <dt class="hdlist1">
7038 <code>$handle <strong>readable</strong> <em>?readable-script?</em></code>
7039 </dt>
7040 <dd>
7042 Sets or returns the script for when the socket is readable.
7043 </p>
7044 </dd>
7045 <dt class="hdlist1">
7046 <code>$handle <strong>writable</strong> <em>?writable-script?</em></code>
7047 </dt>
7048 <dd>
7050 Sets or returns the script for when the socket is writable.
7051 </p>
7052 </dd>
7053 <dt class="hdlist1">
7054 <code>$handle <strong>onexception</strong> <em>?exception-script?</em></code>
7055 </dt>
7056 <dd>
7058 Sets or returns the script for when when oob data received.
7059 </p>
7060 </dd>
7061 </dl></div>
7062 <div class="paragraph"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <code>fileevent</code>. e.g.</p></div>
7063 <div class="dlist"><dl>
7064 <dt class="hdlist1">
7066 </dt>
7067 <dd>
7069 <code>fileevent $handle <strong>readable</strong> <em>...</em></code>
7070 </p>
7071 </dd>
7072 </dl></div>
7073 <div class="paragraph"><p>Time-based execution is also available via the eventloop API.</p></div>
7074 <div class="dlist"><dl>
7075 <dt class="hdlist1">
7076 <code><strong>after</strong> <em>ms</em></code>
7077 </dt>
7078 <dd>
7080 Sleeps for the given number of milliseconds. No events are
7081 processed during this time.
7082 </p>
7083 </dd>
7084 <dt class="hdlist1">
7085 <code><strong>after</strong> <em>ms</em>|<strong>idle</strong> script ?script ...?'</code>
7086 </dt>
7087 <dd>
7089 The scripts are concatenated and executed after the given
7090 number of milliseconds have elapsed. If <em>idle</em> is specified,
7091 the script will run the next time the event loop is processed
7092 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
7093 then removed. Returns an event id.
7094 </p>
7095 </dd>
7096 <dt class="hdlist1">
7097 <code><strong>after cancel</strong> <em>id|command</em></code>
7098 </dt>
7099 <dd>
7101 Cancels an <a href="#cmd_2"><strong><code>after</code></strong></a> event with the given event id or matching
7102 command (script). Returns the number of milliseconds
7103 remaining until the event would have fired. Returns the
7104 empty string if no matching event is found.
7105 </p>
7106 </dd>
7107 <dt class="hdlist1">
7108 <code><strong>after info</strong> <em>?id?</em></code>
7109 </dt>
7110 <dd>
7112 If <code><em>id</em></code> is not given, returns a list of current <a href="#cmd_2"><strong><code>after</code></strong></a>
7113 events. If <code><em>id</em></code> is given, returns a list containing the
7114 associated script and either <em>timer</em> or <em>idle</em> to indicated
7115 the type of the event. An error occurs if <code><em>id</em></code> does not
7116 match an event.
7117 </p>
7118 </dd>
7119 <dt class="hdlist1">
7120 <code><strong>vwait</strong> <em>variable</em></code>
7121 </dt>
7122 <dd>
7124 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
7125 events until the named (global) variable changes or all
7126 event handlers are removed. The variable need not exist
7127 beforehand. If there are no event handlers defined, <a href="#cmd_2"><strong><code>vwait</code></strong></a>
7128 returns immediately.
7129 </p>
7130 </dd>
7131 <dt class="hdlist1">
7132 <code><strong>update ?idletasks?</strong></code>
7133 </dt>
7134 <dd>
7136 A call to <a href="#cmd_2"><strong><code>update</code></strong></a> enters the eventloop to process expired events, but
7137 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
7138 not file events.
7139 Returns once handlers have been run for all expired events.
7140 </p>
7141 </dd>
7142 </dl></div>
7143 <div class="paragraph"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
7144 an attempt is made to call (the user-defined command) <code>bgerror</code> with the details of the error.
7145 If the <code>bgerror</code> command does not exist, the error message details are printed to stderr instead.</p></div>
7146 <div class="paragraph"><p>If a file event handler script generates an error, the handler is automatically removed
7147 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
7148 <div class="dlist"><dl>
7149 <dt class="hdlist1">
7150 <code><strong>bgerror</strong> <em>msg</em></code>
7151 </dt>
7152 <dd>
7154 Called when an event handler script generates an error. Note that the normal command resolution
7155 rules are used for bgerror. First the name is resolved in the current namespace, then in the
7156 global scope.
7157 </p>
7158 </dd>
7159 </dl></div>
7160 </div>
7161 <div class="sect2">
7162 <h3 id="_socket">socket</h3>
7163 <div class="paragraph"><p>Various socket types may be created.</p></div>
7164 <div class="dlist"><dl>
7165 <dt class="hdlist1">
7166 <code><strong>socket unix</strong> <em>path</em></code>
7167 </dt>
7168 <dd>
7170 A unix domain socket client.
7171 </p>
7172 </dd>
7173 <dt class="hdlist1">
7174 <code><strong>socket unix.server</strong> <em>path</em></code>
7175 </dt>
7176 <dd>
7178 A unix domain socket server.
7179 </p>
7180 </dd>
7181 <dt class="hdlist1">
7182 <code><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></code>
7183 </dt>
7184 <dd>
7186 A TCP socket client. (See the forms for <code><em>addr</em></code> below)
7187 </p>
7188 </dd>
7189 <dt class="hdlist1">
7190 <code><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></code>
7191 </dt>
7192 <dd>
7194 A TCP socket server (<code><em>addr</em></code> defaults to <code>0.0.0.0</code> for IPv4 or <code>[::]</code> for IPv6).
7195 </p>
7196 </dd>
7197 <dt class="hdlist1">
7198 <code><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</code>
7199 </dt>
7200 <dd>
7202 A UDP socket client. If the address is not specified,
7203 the client socket will be unbound and <em>sendto</em> must be used
7204 to indicated the destination.
7205 </p>
7206 </dd>
7207 <dt class="hdlist1">
7208 <code><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></code>
7209 </dt>
7210 <dd>
7212 A UDP socket server.
7213 </p>
7214 </dd>
7215 <dt class="hdlist1">
7216 <code><strong>socket pipe</strong></code>
7217 </dt>
7218 <dd>
7220 A pipe. Note that unlike all other socket types, this command returns
7221 a list of two channels: {read write}
7222 </p>
7223 </dd>
7224 <dt class="hdlist1">
7225 <code><strong>socket pair</strong></code>
7226 </dt>
7227 <dd>
7229 A socketpair (see socketpair(2)). Like <a href="#_socket"><strong><code>socket</code></strong></a> <code>pipe</code>, this command returns
7230 a list of two channels: {s1 s2}. These channels are both readable and writable.
7231 </p>
7232 </dd>
7233 </dl></div>
7234 <div class="paragraph"><p>This command creates a socket connected (client) or bound (server) to the given
7235 address.</p></div>
7236 <div class="paragraph"><p>The returned value is channel and may generally be used with the various file I/O
7237 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
7238 <div class="literalblock">
7239 <div class="content">
7240 <pre><code>set f [socket stream www.google.com:80]
7241 aio.sockstream1
7242 $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
7243 $f gets
7244 HTTP/1.0 302 Found
7245 $f close</code></pre>
7246 </div></div>
7247 <div class="paragraph"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
7248 the EVENTLOOP API.</p></div>
7249 <div class="literalblock">
7250 <div class="content">
7251 <pre><code>set f [socket stream.server 80]
7252 $f readable {
7253 set client [$f accept]
7254 $client gets $buf
7256 $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
7257 $client close
7259 vwait done</code></pre>
7260 </div></div>
7261 <div class="paragraph"><p>The address, <code><em>addr</em></code>, can be given in one of the following forms:</p></div>
7262 <div class="olist arabic"><ol class="arabic">
7263 <li>
7265 For IPv4 socket types, an IPv4 address such as 192.168.1.1
7266 </p>
7267 </li>
7268 <li>
7270 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
7271 </p>
7272 </li>
7273 <li>
7275 A hostname
7276 </p>
7277 </li>
7278 </ol></div>
7279 <div class="paragraph"><p>Note that on many systems, listening on an IPv6 address such as [::] will
7280 also accept requests via IPv4.</p></div>
7281 <div class="paragraph"><p>Where a hostname is specified, the <code><em>first</em></code> returned address is used
7282 which matches the socket type is used.</p></div>
7283 <div class="paragraph"><p>The special type <em>pipe</em> isn&#8217;t really a socket.</p></div>
7284 <div class="literalblock">
7285 <div class="content">
7286 <pre><code>lassign [socket pipe] r w</code></pre>
7287 </div></div>
7288 <div class="literalblock">
7289 <div class="content">
7290 <pre><code># Must close $w after exec
7291 exec ps &gt;@$w &amp;
7292 $w close</code></pre>
7293 </div></div>
7294 <div class="literalblock">
7295 <div class="content">
7296 <pre><code>$r readable ...</code></pre>
7297 </div></div>
7298 </div>
7299 <div class="sect2">
7300 <h3 id="_syslog">syslog</h3>
7301 <div class="paragraph"><p><code><strong>syslog</strong> <em>?options? ?priority? message</em></code></p></div>
7302 <div class="paragraph"><p>This command sends message to system syslog facility with given
7303 priority. Valid priorities are:</p></div>
7304 <div class="literalblock">
7305 <div class="content">
7306 <pre><code>emerg, alert, crit, err, error, warning, notice, info, debug</code></pre>
7307 </div></div>
7308 <div class="paragraph"><p>If a message is specified, but no priority is specified, then a
7309 priority of info is used.</p></div>
7310 <div class="paragraph"><p>By default, facility user is used and the value of global tcl variable
7311 argv0 is used as ident string. However, any of the following options
7312 may be specified before priority to control these parameters:</p></div>
7313 <div class="dlist"><dl>
7314 <dt class="hdlist1">
7315 <code><strong>-facility</strong> <em>value</em></code>
7316 </dt>
7317 <dd>
7319 Use specified facility instead of user. The following
7320 values for facility are recognized:
7321 </p>
7322 <div class="literalblock">
7323 <div class="content">
7324 <pre><code>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
7325 uucp, local0-local7</code></pre>
7326 </div></div>
7327 </dd>
7328 <dt class="hdlist1">
7329 <code><strong>-ident</strong> <em>string</em></code>
7330 </dt>
7331 <dd>
7333 Use given string instead of argv0 variable for ident string.
7334 </p>
7335 </dd>
7336 <dt class="hdlist1">
7337 <code><strong>-options</strong> <em>integer</em></code>
7338 </dt>
7339 <dd>
7341 Set syslog options such as <code>LOG_CONS</code>, <code>LOG_NDELAY</code>. You should
7342 use numeric values of those from your system syslog.h file,
7343 because I haven&#8217;t got time to implement yet another hash
7344 table.
7345 </p>
7346 </dd>
7347 </dl></div>
7348 </div>
7349 <div class="sect2">
7350 <h3 id="cmd_3">pack: pack, unpack</h3>
7351 <div class="paragraph"><p>The optional <em>pack</em> extension provides commands to encode and decode binary strings.</p></div>
7352 <div class="dlist"><dl>
7353 <dt class="hdlist1">
7354 <code><strong>pack</strong> <em>varName value</em> <strong>-intle|-intbe|-floatle|-floatbe|-str</strong> <em>bitwidth ?bitoffset?</em></code>
7355 </dt>
7356 <dd>
7358 Packs the binary representation of <code><em>value</em></code> into the variable
7359 <code><em>varName</em></code>. The value is packed according to the given type
7360 (integer/floating point/string, big-endian/little-endian), width and bit offset.
7361 The variable is created if necessary (like <a href="#_append"><strong><code>append</code></strong></a>).
7362 Ihe variable is expanded if necessary.
7363 </p>
7364 </dd>
7365 <dt class="hdlist1">
7366 <code><strong>unpack</strong> <em>binvalue</em> <strong>-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str</strong> <em>bitpos bitwidth</em></code>
7367 </dt>
7368 <dd>
7370 Unpacks bits from <code><em>binvalue</em></code> at bit position <code><em>bitpos</em></code> and with <code><em>bitwidth</em></code>.
7371 Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
7372 and signed/unsigned) and returns it. For integer types, <code><em>bitwidth</em></code>
7373 may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
7374 <code><em>bitwidth</em></code> may be 32 bits (for single precision numbers) or 64 bits (for double precision).
7375 For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
7376 access outside the length of the value will return 0 for integer types, 0.0 for floating point types
7377 or the empty string for the string type.
7378 </p>
7379 </dd>
7380 </dl></div>
7381 </div>
7382 <div class="sect2">
7383 <h3 id="_binary">binary</h3>
7384 <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>
7385 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>
7386 <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>
7387 <div class="paragraph"><p>Note that <em>binary format</em> with f/r/R specifiers (single-precision float) uses the value of Infinity
7388 in case of overflow.</p></div>
7389 </div>
7390 <div class="sect2">
7391 <h3 id="cmd_4">oo: class, super</h3>
7392 <div class="paragraph"><p>The optional, pure-Tcl <em>oo</em> extension provides object-oriented (OO) support for Jim Tcl.</p></div>
7393 <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>
7394 <div class="dlist"><dl>
7395 <dt class="hdlist1">
7396 <code><strong>class</strong> <em>classname ?baseclasses? classvars</em></code>
7397 </dt>
7398 <dd>
7400 Create a new class, <code><em>classname</em></code>, with the given dictionary
7401 (<code><em>classvars</em></code>) as class variables. These are the initial variables
7402 which all newly created objects of this class are initialised with.
7403 If a list of baseclasses is given, methods and instance variables
7404 are inherited.
7405 </p>
7406 </dd>
7407 <dt class="hdlist1">
7408 <code><strong>super</strong> <em>method ?args ...?</em></code>
7409 </dt>
7410 <dd>
7412 From within a method, invokes the given method on the base class.
7413 Note that this will only call the last baseclass given.
7414 </p>
7415 </dd>
7416 </dl></div>
7417 </div>
7418 <div class="sect2">
7419 <h3 id="_tree">tree</h3>
7420 <div class="paragraph"><p>The optional, pure-Tcl <em>tree</em> extension implements an OO, general purpose tree structure
7421 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>
7422 <div class="paragraph"><p>A tree is a collection of nodes, where each node (except the root node) has a single parent
7423 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.</p></div>
7424 <div class="dlist"><dl>
7425 <dt class="hdlist1">
7426 <code><strong>tree</strong></code>
7427 </dt>
7428 <dd>
7430 Creates and returns a new tree object with a single node named "root".
7431 All operations on the tree are invoked through this object.
7432 </p>
7433 </dd>
7434 <dt class="hdlist1">
7435 <code>$tree <strong>destroy</strong></code>
7436 </dt>
7437 <dd>
7439 Destroy the tree and all it&#8217;s nodes. (Note that the the tree will also
7440 be automatically garbage collected once it goes out of scope).
7441 </p>
7442 </dd>
7443 <dt class="hdlist1">
7444 <code>$tree <strong>set</strong> <em>nodename key value</em></code>
7445 </dt>
7446 <dd>
7448 Set the value for the given attribute key.
7449 </p>
7450 </dd>
7451 <dt class="hdlist1">
7452 <code>$tree <strong>lappend</strong> <em>nodename key value ...</em></code>
7453 </dt>
7454 <dd>
7456 Append to the (list) value(s) for the given attribute key, or set if not yet set.
7457 </p>
7458 </dd>
7459 <dt class="hdlist1">
7460 <code>$tree <strong>keyexists</strong> <em>nodename key</em></code>
7461 </dt>
7462 <dd>
7464 Returns 1 if the given attribute key exists.
7465 </p>
7466 </dd>
7467 <dt class="hdlist1">
7468 <code>$tree <strong>get</strong> <em>nodename key</em></code>
7469 </dt>
7470 <dd>
7472 Returns the value associated with the given attribute key.
7473 </p>
7474 </dd>
7475 <dt class="hdlist1">
7476 <code>$tree <strong>getall</strong> <em>nodename</em></code>
7477 </dt>
7478 <dd>
7480 Returns the entire attribute dictionary associated with the given key.
7481 </p>
7482 </dd>
7483 <dt class="hdlist1">
7484 <code>$tree <strong>depth</strong> <em>nodename</em></code>
7485 </dt>
7486 <dd>
7488 Returns the depth of the given node. The depth of "root" is 0.
7489 </p>
7490 </dd>
7491 <dt class="hdlist1">
7492 <code>$tree <strong>parent</strong> <em>nodename</em></code>
7493 </dt>
7494 <dd>
7496 Returns the node name of the parent node, or "" for the root node.
7497 </p>
7498 </dd>
7499 <dt class="hdlist1">
7500 <code>$tree <strong>numchildren</strong> <em>nodename</em></code>
7501 </dt>
7502 <dd>
7504 Returns the number of child nodes.
7505 </p>
7506 </dd>
7507 <dt class="hdlist1">
7508 <code>$tree <strong>children</strong> <em>nodename</em></code>
7509 </dt>
7510 <dd>
7512 Returns a list of the child nodes.
7513 </p>
7514 </dd>
7515 <dt class="hdlist1">
7516 <code>$tree <strong>next</strong> <em>nodename</em></code>
7517 </dt>
7518 <dd>
7520 Returns the next sibling node, or "" if none.
7521 </p>
7522 </dd>
7523 <dt class="hdlist1">
7524 <code>$tree <strong>insert</strong> <em>nodename ?index?</em></code>
7525 </dt>
7526 <dd>
7528 Add a new child node to the given node. The index is a list index
7529 such as <code>3</code> or <code>end-2</code>. The default index is <code>end</code>.
7530 Returns the name of the newly added node.
7531 </p>
7532 </dd>
7533 <dt class="hdlist1">
7534 <code>$tree <strong>walk</strong> <em>nodename</em> <strong>dfs|bfs</strong> {<em>actionvar nodevar</em>} <em>script</em></code>
7535 </dt>
7536 <dd>
7538 Walks the tree starting from the given node, either breadth first (<code>bfs</code>)
7539 depth first (<code>dfs</code>).
7540 The value <code>"enter"</code> or <code>"exit"</code> is stored in variable <code><em>actionvar</em></code>.
7541 The name of each node is stored in <code><em>nodevar</em></code>.
7542 The script is evaluated twice for each node, on entry and exit.
7543 </p>
7544 </dd>
7545 <dt class="hdlist1">
7546 <code>$tree <strong>dump</strong></code>
7547 </dt>
7548 <dd>
7550 Dumps the tree contents to stdout
7551 </p>
7552 </dd>
7553 </dl></div>
7554 </div>
7555 <div class="sect2">
7556 <h3 id="_tcl_prefix">tcl::prefix</h3>
7557 <div class="paragraph"><p>The optional tclprefix extension provides the Tcl8.6-compatible <em>tcl::prefix</em> command
7558 (<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
7559 of possible values (typically commands or options).</p></div>
7560 <div class="dlist"><dl>
7561 <dt class="hdlist1">
7562 <code><strong>tcl::prefix all</strong> <em>table string</em></code>
7563 </dt>
7564 <dd>
7566 Returns a list of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7567 </p>
7568 </dd>
7569 <dt class="hdlist1">
7570 <code><strong>tcl::prefix longest</strong> <em>table string</em></code>
7571 </dt>
7572 <dd>
7574 Returns the longest common prefix of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7575 </p>
7576 </dd>
7577 <dt class="hdlist1">
7578 <code><strong>tcl::prefix match</strong> <em>?options? table string</em></code>
7579 </dt>
7580 <dd>
7582 If <code><em>string</em></code> equals one element in <code><em>table</em></code> or is a prefix to
7583 exactly one element, the matched element is returned. If not, the
7584 result depends on the <code>-error</code> option.
7585 </p>
7586 <div class="ulist"><ul>
7587 <li>
7589 <code><strong>-exact</strong></code> Accept only exact matches.
7590 </p>
7591 </li>
7592 <li>
7594 <code><strong>-message</strong> <em>string</em></code> Use <code><em>string</em></code> in the error message at a mismatch. Default is "option".
7595 </p>
7596 </li>
7597 <li>
7599 <code><strong>-error</strong> <em>options</em></code> The options are used when no match is found. If <code><em>options</em></code> is
7600 empty, no error is generated and an empty string is returned.
7601 Otherwise the options are used as return options when
7602 generating the error message. The default corresponds to
7603 setting <code>-level 0</code>.
7604 </p>
7605 </li>
7606 </ul></div>
7607 </dd>
7608 </dl></div>
7609 </div>
7610 <div class="sect2">
7611 <h3 id="_history">history</h3>
7612 <div class="paragraph"><p>The optional history extension provides script access to the command line editing
7613 and history support available in <em>jimsh</em>. See <em>examples/jtclsh.tcl</em> for an example.
7614 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
7615 the remaining subcommands do nothing.</p></div>
7616 <div class="dlist"><dl>
7617 <dt class="hdlist1">
7618 <code><strong>history load</strong> <em>filename</em></code>
7619 </dt>
7620 <dd>
7622 Load history from a (text) file. If the file does not exist or is not readable,
7623 it is ignored.
7624 </p>
7625 </dd>
7626 <dt class="hdlist1">
7627 <code><strong>history getline</strong> <em>prompt ?varname?</em></code>
7628 </dt>
7629 <dd>
7631 Displays the given prompt and allows a line to be entered. Similarly to <a href="#_gets"><strong><code>gets</code></strong></a>,
7632 if <code><em>varname</em></code> is given, it receives the line and the length of the line is returned,
7633 or -1 on EOF. If <code><em>varname</em></code> is not given, the line is returned directly.
7634 </p>
7635 </dd>
7636 <dt class="hdlist1">
7637 <code><strong>history add</strong> <em>line</em></code>
7638 </dt>
7639 <dd>
7641 Adds the given line to the history buffer.
7642 </p>
7643 </dd>
7644 <dt class="hdlist1">
7645 <code><strong>history save</strong> <em>filename</em></code>
7646 </dt>
7647 <dd>
7649 Saves the current history buffer to the given file.
7650 </p>
7651 </dd>
7652 <dt class="hdlist1">
7653 <code><strong>history show</strong></code>
7654 </dt>
7655 <dd>
7657 Displays the current history buffer to standard output.
7658 </p>
7659 </dd>
7660 </dl></div>
7661 </div>
7662 <div class="sect2">
7663 <h3 id="_namespace">namespace</h3>
7664 <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>
7665 <div class="dlist"><dl>
7666 <dt class="hdlist1">
7667 <code><strong>namespace code</strong> <em>script</em></code>
7668 </dt>
7669 <dd>
7671 Captures the current namespace context for later execution of
7672 the script <code><em>script</em></code>. It returns a new script in which script has
7673 been wrapped in a <code><strong>namespace inscope</strong></code> command.
7674 </p>
7675 </dd>
7676 <dt class="hdlist1">
7677 <code><strong>namespace current</strong></code>
7678 </dt>
7679 <dd>
7681 Returns the fully-qualified name for the current namespace.
7682 </p>
7683 </dd>
7684 <dt class="hdlist1">
7685 <code><strong>namespace delete</strong> <em>?namespace &#8230;?</em></code>
7686 </dt>
7687 <dd>
7689 Deletes all commands and variables with the given namespace prefixes.
7690 </p>
7691 </dd>
7692 <dt class="hdlist1">
7693 <code><strong>namespace eval</strong> <em>namespace arg ?arg&#8230;?</em></code>
7694 </dt>
7695 <dd>
7697 Activates a namespace called <code><em>namespace</em></code> and evaluates some code in that context.
7698 </p>
7699 </dd>
7700 <dt class="hdlist1">
7701 <code><strong>namespace origin</strong> <em>command</em></code>
7702 </dt>
7703 <dd>
7705 Returns the fully-qualified name of the original command to which the imported command <code><em>command</em></code> refers.
7706 </p>
7707 </dd>
7708 <dt class="hdlist1">
7709 <code><strong>namespace parent</strong> ?namespace?</code>
7710 </dt>
7711 <dd>
7713 Returns the fully-qualified name of the parent namespace for namespace <code><em>namespace</em></code>, if given, otherwise
7714 for the current namespace.
7715 </p>
7716 </dd>
7717 <dt class="hdlist1">
7718 <code><strong>namespace qualifiers</strong> <em>string</em></code>
7719 </dt>
7720 <dd>
7722 Returns any leading namespace qualifiers for <code><em>string</em></code>
7723 </p>
7724 </dd>
7725 <dt class="hdlist1">
7726 <code><strong>namespace tail</strong> <em>string</em></code>
7727 </dt>
7728 <dd>
7730 Returns the simple name at the end of a qualified string.
7731 </p>
7732 </dd>
7733 <dt class="hdlist1">
7734 <code><strong>namespace upvar</strong> <em>namespace ?arg&#8230;?</em></code>
7735 </dt>
7736 <dd>
7738 This command arranges for zero or more local variables in the current procedure to refer to variables in <code><em>namespace</em></code>
7739 </p>
7740 </dd>
7741 <dt class="hdlist1">
7742 <code><strong>namespace which</strong> <em>?-command|-variable? name</em></code>
7743 </dt>
7744 <dd>
7746 Looks up <code><em>name</em></code> as either a command (the default) or variable and returns its fully-qualified name.
7747 </p>
7748 </dd>
7749 </dl></div>
7750 </div>
7751 </div>
7752 </div>
7753 <div class="sect1">
7754 <h2 id="BuiltinVariables">BUILT-IN VARIABLES</h2>
7755 <div class="sectionbody">
7756 <div class="paragraph"><p>The following global variables are created automatically
7757 by the Tcl library.</p></div>
7758 <div class="dlist"><dl>
7759 <dt class="hdlist1">
7760 <code><strong>env</strong></code>
7761 </dt>
7762 <dd>
7764 This variable is set by Jim as an array
7765 whose elements are the environment variables for the process.
7766 Reading an element will return the value of the corresponding
7767 environment variable.
7768 This array is initialised at startup from the <a href="#_env"><strong><code>env</code></strong></a> command.
7769 It may be modified and will affect the environment passed to
7770 commands invoked with <a href="#_exec"><strong><code>exec</code></strong></a>.
7771 </p>
7772 </dd>
7773 <dt class="hdlist1">
7774 <code><strong>platform_tcl</strong></code>
7775 </dt>
7776 <dd>
7778 This variable is set by Jim as an array containing information
7779 about the platform on which Jim was built. Currently this includes
7780 <em>os</em> and <em>platform</em>.
7781 </p>
7782 </dd>
7783 <dt class="hdlist1">
7784 <code><strong>auto_path</strong></code>
7785 </dt>
7786 <dd>
7788 This variable contains a list of paths to search for packages.
7789 It defaults to a location based on where jim is installed
7790 (e.g. <code>/usr/local/lib/jim</code>), but may be changed by <code>jimsh</code>
7791 or the embedding application. Note that <code>jimsh</code> will consider
7792 the environment variable <code>$JIMLIB</code> to be a list of colon-separated
7793 list of paths to add to <code><strong>auto_path</strong></code>.
7794 </p>
7795 </dd>
7796 <dt class="hdlist1">
7797 <code><strong>errorCode</strong></code>
7798 </dt>
7799 <dd>
7801 This variable holds the value of the -errorcode return
7802 option set by the most recent error that occurred in this
7803 interpreter. This list value represents additional information
7804 about the error in a form that is easy to process with
7805 programs. The first element of the list identifies a general
7806 class of errors, and determines the format of the rest of
7807 the list. The following formats for -errorcode return options
7808 are used by the Tcl core; individual applications may define
7809 additional formats. Currently only <a href="#_exec"><strong><code>exec</code></strong></a> sets this variable.
7810 Otherwise it will be <code>NONE</code>.
7811 </p>
7812 </dd>
7813 </dl></div>
7814 <div class="paragraph"><p>The following global variables are set by jimsh.</p></div>
7815 <div class="dlist"><dl>
7816 <dt class="hdlist1">
7817 <code><strong>tcl_interactive</strong></code>
7818 </dt>
7819 <dd>
7821 This variable is set to 1 if jimsh is started in interactive mode
7822 or 0 otherwise.
7823 </p>
7824 </dd>
7825 <dt class="hdlist1">
7826 <code><strong>tcl_platform</strong></code>
7827 </dt>
7828 <dd>
7830 This variable is set by Jim as an array containing information
7831 about the platform upon which Jim was built. The following is an
7832 example of the contents of this array.
7833 </p>
7834 <div class="literalblock">
7835 <div class="content">
7836 <pre><code>tcl_platform(byteOrder) = littleEndian
7837 tcl_platform(os) = Darwin
7838 tcl_platform(platform) = unix
7839 tcl_platform(pointerSize) = 8
7840 tcl_platform(threaded) = 0
7841 tcl_platform(wordSize) = 8
7842 tcl_platform(pathSeparator) = :</code></pre>
7843 </div></div>
7844 </dd>
7845 <dt class="hdlist1">
7846 <code><strong>argv0</strong></code>
7847 </dt>
7848 <dd>
7850 If jimsh is invoked to run a script, this variable contains the name
7851 of the script.
7852 </p>
7853 </dd>
7854 <dt class="hdlist1">
7855 <code><strong>argv</strong></code>
7856 </dt>
7857 <dd>
7859 If jimsh is invoked to run a script, this variable contains a list
7860 of any arguments supplied to the script.
7861 </p>
7862 </dd>
7863 <dt class="hdlist1">
7864 <code><strong>argc</strong></code>
7865 </dt>
7866 <dd>
7868 If jimsh is invoked to run a script, this variable contains the number
7869 of arguments supplied to the script.
7870 </p>
7871 </dd>
7872 <dt class="hdlist1">
7873 <code><strong>jim::argv0</strong></code>
7874 </dt>
7875 <dd>
7877 The value of argv[0] when jimsh was invoked.
7878 </p>
7879 </dd>
7880 </dl></div>
7881 </div>
7882 </div>
7883 <div class="sect1">
7884 <h2 id="_changes_in_previous_releases">CHANGES IN PREVIOUS RELEASES</h2>
7885 <div class="sectionbody">
7886 <div class="sect2">
7887 <h3 id="_in_v0_70">In v0.70</h3>
7888 <div class="olist arabic"><ol class="arabic">
7889 <li>
7891 <code>platform_tcl()</code> settings are now automatically determined
7892 </p>
7893 </li>
7894 <li>
7896 Add aio <code>$handle filename</code>
7897 </p>
7898 </li>
7899 <li>
7901 Add <a href="#_info"><strong><code>info</code></strong></a> <code>channels</code>
7902 </p>
7903 </li>
7904 <li>
7906 The <em>bio</em> extension is gone. Now <a href="#_aio"><strong><code>aio</code></strong></a> supports <em>copyto</em>.
7907 </p>
7908 </li>
7909 <li>
7911 Add <a href="#_exists"><strong><code>exists</code></strong></a> command
7912 </p>
7913 </li>
7914 <li>
7916 Add the pure-Tcl <em>oo</em> extension
7917 </p>
7918 </li>
7919 <li>
7921 The <a href="#_exec"><strong><code>exec</code></strong></a> command now only uses vfork(), not fork()
7922 </p>
7923 </li>
7924 <li>
7926 Unit test framework is less verbose and more Tcl-compatible
7927 </p>
7928 </li>
7929 <li>
7931 Optional UTF-8 support
7932 </p>
7933 </li>
7934 <li>
7936 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
7937 </p>
7938 </li>
7939 <li>
7941 Command line editing in interactive mode, e.g. <em>jimsh</em>
7942 </p>
7943 </li>
7944 </ol></div>
7945 </div>
7946 <div class="sect2">
7947 <h3 id="_in_v0_63">In v0.63</h3>
7948 <div class="olist arabic"><ol class="arabic">
7949 <li>
7951 <a href="#_source"><strong><code>source</code></strong></a> now checks that a script is complete (.i.e. not missing a brace)
7952 </p>
7953 </li>
7954 <li>
7956 <em>info complete</em> now uses the real parser and so is 100% accurate
7957 </p>
7958 </li>
7959 <li>
7961 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>
7962 </p>
7963 </li>
7964 <li>
7966 <a href="#_tailcall"><strong><code>tailcall</code></strong></a> no longer loses stack trace information
7967 </p>
7968 </li>
7969 <li>
7971 Add <a href="#_alias"><strong><code>alias</code></strong></a> and <a href="#_curry"><strong><code>curry</code></strong></a>
7972 </p>
7973 </li>
7974 <li>
7976 <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
7977 </p>
7978 </li>
7979 <li>
7981 <a href="#_local"><strong><code>local</code></strong></a> allows procedures to be deleted automatically at the end of the current procedure
7982 </p>
7983 </li>
7984 <li>
7986 udp sockets are now supported for both clients and servers.
7987 </p>
7988 </li>
7989 <li>
7991 vfork-based exec is now working correctly
7992 </p>
7993 </li>
7994 <li>
7996 Add <em>file tempfile</em>
7997 </p>
7998 </li>
7999 <li>
8001 Add <em>socket pipe</em>
8002 </p>
8003 </li>
8004 <li>
8006 Enhance <em>try &#8230; on &#8230; finally</em> to be more Tcl 8.6 compatible
8007 </p>
8008 </li>
8009 <li>
8011 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>
8012 </p>
8013 </li>
8014 <li>
8016 IPv6 support is now included
8017 </p>
8018 </li>
8019 <li>
8021 Add <em>string is</em>
8022 </p>
8023 </li>
8024 <li>
8026 Event handlers works better if an error occurs. eof handler has been removed.
8027 </p>
8028 </li>
8029 <li>
8031 <a href="#_exec"><strong><code>exec</code></strong></a> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
8032 </p>
8033 </li>
8034 <li>
8036 Command pipelines via open "|&#8230;" are now supported
8037 </p>
8038 </li>
8039 <li>
8041 <a href="#_pid"><strong><code>pid</code></strong></a> can now return pids of a command pipeline
8042 </p>
8043 </li>
8044 <li>
8046 Add <em>info references</em>
8047 </p>
8048 </li>
8049 <li>
8051 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>
8052 </p>
8053 </li>
8054 <li>
8056 <a href="#_exec"><strong><code>exec</code></strong></a> now sets environment based on $::env
8057 </p>
8058 </li>
8059 <li>
8061 Add <em>dict keys</em>
8062 </p>
8063 </li>
8064 <li>
8066 Add support for <em>lsort -index</em>
8067 </p>
8068 </li>
8069 </ol></div>
8070 </div>
8071 <div class="sect2">
8072 <h3 id="_in_v0_62">In v0.62</h3>
8073 <div class="olist arabic"><ol class="arabic">
8074 <li>
8076 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>
8077 </p>
8078 </li>
8079 <li>
8081 Fix <a href="#_exec"><strong><code>exec</code></strong></a> error messages when special token (e.g. <em>&gt;</em>) is the last token
8082 </p>
8083 </li>
8084 <li>
8086 Fix <a href="#_subst"><strong><code>subst</code></strong></a> handling of backslash escapes.
8087 </p>
8088 </li>
8089 <li>
8091 Allow abbreviated options for <a href="#_subst"><strong><code>subst</code></strong></a>
8092 </p>
8093 </li>
8094 <li>
8096 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
8097 </p>
8098 </li>
8099 <li>
8101 Many <a href="#_expr"><strong><code>expr</code></strong></a> bug fixes
8102 </p>
8103 </li>
8104 <li>
8106 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
8107 </p>
8108 </li>
8109 <li>
8111 The variable name argument to <a href="#_regsub"><strong><code>regsub</code></strong></a> is now optional
8112 </p>
8113 </li>
8114 <li>
8116 Add support for <em>unset -nocomplain</em>
8117 </p>
8118 </li>
8119 <li>
8121 Add support for list commands: <a href="#_lassign"><strong><code>lassign</code></strong></a>, <a href="#_lrepeat"><strong><code>lrepeat</code></strong></a>
8122 </p>
8123 </li>
8124 <li>
8126 Fully-functional <a href="#_lsearch"><strong><code>lsearch</code></strong></a> is now implemented
8127 </p>
8128 </li>
8129 <li>
8131 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
8132 </p>
8133 </li>
8134 <li>
8136 Allow <a href="#_catch"><strong><code>catch</code></strong></a> to determine what return codes are caught
8137 </p>
8138 </li>
8139 <li>
8141 Allow <a href="#_incr"><strong><code>incr</code></strong></a> to increment an unset variable by first setting to 0
8142 </p>
8143 </li>
8144 <li>
8146 Allow <em>args</em> and optional arguments to the left or required arguments in <a href="#_proc"><strong><code>proc</code></strong></a>
8147 </p>
8148 </li>
8149 <li>
8151 Add <em>file copy</em>
8152 </p>
8153 </li>
8154 <li>
8156 Add <em>try &#8230; finally</em> command
8157 </p>
8158 </li>
8159 </ol></div>
8160 </div>
8161 </div>
8162 </div>
8163 <div class="sect1">
8164 <h2 id="_licence">LICENCE</h2>
8165 <div class="sectionbody">
8166 <div class="literalblock">
8167 <div class="content">
8168 <pre><code>Copyright 2005 Salvatore Sanfilippo &lt;antirez@invece.org&gt;
8169 Copyright 2005 Clemens Hintze &lt;c.hintze@gmx.net&gt;
8170 Copyright 2005 patthoyts - Pat Thoyts &lt;patthoyts@users.sf.net&gt;
8171 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
8172 Copyright 2008 Andrew Lunn &lt;andrew@lunn.ch&gt;
8173 Copyright 2008 Duane Ellis &lt;openocd@duaneellis.com&gt;
8174 Copyright 2008 Uwe Klein &lt;uklein@klein-messgeraete.de&gt;
8175 Copyright 2009 Steve Bennett &lt;steveb@workware.net.au&gt;</code></pre>
8176 </div></div>
8177 <div class="literalblock">
8178 <div class="content">
8179 <pre><code>Redistribution and use in source and binary forms, with or without
8180 modification, are permitted provided that the following conditions
8181 are met:
8182 1. Redistributions of source code must retain the above copyright
8183 notice, this list of conditions and the following disclaimer.
8184 2. Redistributions in binary form must reproduce the above
8185 copyright notice, this list of conditions and the following
8186 disclaimer in the documentation and/or other materials
8187 provided with the distribution.</code></pre>
8188 </div></div>
8189 <div class="literalblock">
8190 <div class="content">
8191 <pre><code>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
8192 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8193 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
8194 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
8195 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8196 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8197 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8198 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8199 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8200 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8201 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
8202 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</code></pre>
8203 </div></div>
8204 <div class="literalblock">
8205 <div class="content">
8206 <pre><code>The views and conclusions contained in the software and documentation
8207 are those of the authors and should not be interpreted as representing
8208 official policies, either expressed or implied, of the Jim Tcl Project.</code></pre>
8209 </div></div>
8210 </div>
8211 </div>
8212 </div>
8213 <div id="footnotes"><hr /></div>
8214 <div id="footer">
8215 <div id="footer-text">
8216 Last updated 2014-12-09 12:46:16 AEST
8217 </div>
8218 </div>
8219 </body>
8220 </html>