Document [string map]
[jimtcl.git] / Tcl_shipped.html
blobe85ebb0ac6b7c5cf46994fcde20614cd955a8d75
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.5" />
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 pre {
91 padding: 0;
92 margin: 0;
95 #author {
96 color: #527bbd;
97 font-weight: bold;
98 font-size: 1.1em;
100 #email {
102 #revnumber, #revdate, #revremark {
105 #footer {
106 font-size: small;
107 border-top: 2px solid silver;
108 padding-top: 0.5em;
109 margin-top: 4.0em;
111 #footer-text {
112 float: left;
113 padding-bottom: 0.5em;
115 #footer-badges {
116 float: right;
117 padding-bottom: 0.5em;
120 #preamble {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
124 div.imageblock, div.exampleblock, div.verseblock,
125 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
126 div.admonitionblock {
127 margin-top: 1.0em;
128 margin-bottom: 1.5em;
130 div.admonitionblock {
131 margin-top: 2.0em;
132 margin-bottom: 2.0em;
133 margin-right: 10%;
134 color: #606060;
137 div.content { /* Block element content. */
138 padding: 0;
141 /* Block element titles. */
142 div.title, caption.title {
143 color: #527bbd;
144 font-weight: bold;
145 text-align: left;
146 margin-top: 1.0em;
147 margin-bottom: 0.5em;
149 div.title + * {
150 margin-top: 0;
153 td div.title:first-child {
154 margin-top: 0.0em;
156 div.content div.title:first-child {
157 margin-top: 0.0em;
159 div.content + div.title {
160 margin-top: 0.0em;
163 div.sidebarblock > div.content {
164 background: #ffffee;
165 border: 1px solid #dddddd;
166 border-left: 4px solid #f0f0f0;
167 padding: 0.5em;
170 div.listingblock > div.content {
171 border: 1px solid #dddddd;
172 border-left: 5px solid #f0f0f0;
173 background: #f8f8f8;
174 padding: 0.5em;
177 div.quoteblock, div.verseblock {
178 padding-left: 1.0em;
179 margin-left: 1.0em;
180 margin-right: 10%;
181 border-left: 5px solid #f0f0f0;
182 color: #777777;
185 div.quoteblock > div.attribution {
186 padding-top: 0.5em;
187 text-align: right;
190 div.verseblock > pre.content {
191 font-family: inherit;
192 font-size: inherit;
194 div.verseblock > div.attribution {
195 padding-top: 0.75em;
196 text-align: left;
198 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
199 div.verseblock + div.attribution {
200 text-align: left;
203 div.admonitionblock .icon {
204 vertical-align: top;
205 font-size: 1.1em;
206 font-weight: bold;
207 text-decoration: underline;
208 color: #527bbd;
209 padding-right: 0.5em;
211 div.admonitionblock td.content {
212 padding-left: 0.5em;
213 border-left: 3px solid #dddddd;
216 div.exampleblock > div.content {
217 border-left: 3px solid #dddddd;
218 padding-left: 0.5em;
221 div.imageblock div.content { padding-left: 0; }
222 span.image img { border-style: none; }
223 a.image:visited { color: white; }
225 dl {
226 margin-top: 0.8em;
227 margin-bottom: 0.8em;
229 dt {
230 margin-top: 0.5em;
231 margin-bottom: 0;
232 font-style: normal;
233 color: navy;
235 dd > *:first-child {
236 margin-top: 0.1em;
239 ul, ol {
240 list-style-position: outside;
242 ol.arabic {
243 list-style-type: decimal;
245 ol.loweralpha {
246 list-style-type: lower-alpha;
248 ol.upperalpha {
249 list-style-type: upper-alpha;
251 ol.lowerroman {
252 list-style-type: lower-roman;
254 ol.upperroman {
255 list-style-type: upper-roman;
258 div.compact ul, div.compact ol,
259 div.compact p, div.compact p,
260 div.compact div, div.compact div {
261 margin-top: 0.1em;
262 margin-bottom: 0.1em;
265 tfoot {
266 font-weight: bold;
268 td > div.verse {
269 white-space: pre;
272 div.hdlist {
273 margin-top: 0.8em;
274 margin-bottom: 0.8em;
276 div.hdlist tr {
277 padding-bottom: 15px;
279 dt.hdlist1.strong, td.hdlist1.strong {
280 font-weight: bold;
282 td.hdlist1 {
283 vertical-align: top;
284 font-style: normal;
285 padding-right: 0.8em;
286 color: navy;
288 td.hdlist2 {
289 vertical-align: top;
291 div.hdlist.compact tr {
292 margin: 0;
293 padding-bottom: 0;
296 .comment {
297 background: yellow;
300 .footnote, .footnoteref {
301 font-size: 0.8em;
304 span.footnote, span.footnoteref {
305 vertical-align: super;
308 #footnotes {
309 margin: 20px 0 20px 0;
310 padding: 7px 0 0 0;
313 #footnotes div.footnote {
314 margin: 0 0 5px 0;
317 #footnotes hr {
318 border: none;
319 border-top: 1px solid silver;
320 height: 1px;
321 text-align: left;
322 margin-left: 0;
323 width: 20%;
324 min-width: 100px;
327 div.colist td {
328 padding-right: 0.5em;
329 padding-bottom: 0.3em;
330 vertical-align: top;
332 div.colist td img {
333 margin-top: 0.3em;
336 @media print {
337 #footer-badges { display: none; }
340 #toc {
341 margin-bottom: 2.5em;
344 #toctitle {
345 color: #527bbd;
346 font-size: 1.1em;
347 font-weight: bold;
348 margin-top: 1.0em;
349 margin-bottom: 0.1em;
352 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
353 margin-top: 0;
354 margin-bottom: 0;
356 div.toclevel2 {
357 margin-left: 2em;
358 font-size: 0.9em;
360 div.toclevel3 {
361 margin-left: 4em;
362 font-size: 0.9em;
364 div.toclevel4 {
365 margin-left: 6em;
366 font-size: 0.9em;
369 span.aqua { color: aqua; }
370 span.black { color: black; }
371 span.blue { color: blue; }
372 span.fuchsia { color: fuchsia; }
373 span.gray { color: gray; }
374 span.green { color: green; }
375 span.lime { color: lime; }
376 span.maroon { color: maroon; }
377 span.navy { color: navy; }
378 span.olive { color: olive; }
379 span.purple { color: purple; }
380 span.red { color: red; }
381 span.silver { color: silver; }
382 span.teal { color: teal; }
383 span.white { color: white; }
384 span.yellow { color: yellow; }
386 span.aqua-background { background: aqua; }
387 span.black-background { background: black; }
388 span.blue-background { background: blue; }
389 span.fuchsia-background { background: fuchsia; }
390 span.gray-background { background: gray; }
391 span.green-background { background: green; }
392 span.lime-background { background: lime; }
393 span.maroon-background { background: maroon; }
394 span.navy-background { background: navy; }
395 span.olive-background { background: olive; }
396 span.purple-background { background: purple; }
397 span.red-background { background: red; }
398 span.silver-background { background: silver; }
399 span.teal-background { background: teal; }
400 span.white-background { background: white; }
401 span.yellow-background { background: yellow; }
403 span.big { font-size: 2em; }
404 span.small { font-size: 0.6em; }
406 span.underline { text-decoration: underline; }
407 span.overline { text-decoration: overline; }
408 span.line-through { text-decoration: line-through; }
412 * xhtml11 specific
414 * */
416 tt {
417 font-family: monospace;
418 font-size: inherit;
419 color: navy;
422 div.tableblock {
423 margin-top: 1.0em;
424 margin-bottom: 1.5em;
426 div.tableblock > table {
427 border: 3px solid #527bbd;
429 thead, p.table.header {
430 font-weight: bold;
431 color: #527bbd;
433 p.table {
434 margin-top: 0;
436 /* Because the table frame attribute is overriden by CSS in most browsers. */
437 div.tableblock > table[frame="void"] {
438 border-style: none;
440 div.tableblock > table[frame="hsides"] {
441 border-left-style: none;
442 border-right-style: none;
444 div.tableblock > table[frame="vsides"] {
445 border-top-style: none;
446 border-bottom-style: none;
451 * html5 specific
453 * */
455 .monospaced {
456 font-family: monospace;
457 font-size: inherit;
458 color: navy;
461 table.tableblock {
462 margin-top: 1.0em;
463 margin-bottom: 1.5em;
465 thead, p.tableblock.header {
466 font-weight: bold;
467 color: #527bbd;
469 p.tableblock {
470 margin-top: 0;
472 table.tableblock {
473 border-width: 3px;
474 border-spacing: 0px;
475 border-style: solid;
476 border-color: #527bbd;
477 border-collapse: collapse;
479 th.tableblock, td.tableblock {
480 border-width: 1px;
481 padding: 4px;
482 border-style: solid;
483 border-color: #527bbd;
486 table.tableblock.frame-topbot {
487 border-left-style: hidden;
488 border-right-style: hidden;
490 table.tableblock.frame-sides {
491 border-top-style: hidden;
492 border-bottom-style: hidden;
494 table.tableblock.frame-none {
495 border-style: hidden;
498 th.tableblock.halign-left, td.tableblock.halign-left {
499 text-align: left;
501 th.tableblock.halign-center, td.tableblock.halign-center {
502 text-align: center;
504 th.tableblock.halign-right, td.tableblock.halign-right {
505 text-align: right;
508 th.tableblock.valign-top, td.tableblock.valign-top {
509 vertical-align: top;
511 th.tableblock.valign-middle, td.tableblock.valign-middle {
512 vertical-align: middle;
514 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
515 vertical-align: bottom;
517 /* Overrides for manpage documents */
518 h1 {
519 padding-top: 0.5em;
520 padding-bottom: 0.5em;
521 border-top: 2px solid silver;
522 border-bottom: 2px solid silver;
524 h2 {
525 border-style: none;
527 div.sectionbody {
528 margin-left: 3em;
531 @media print {
532 div#toc { display: none; }
535 </style>
536 <script type="text/javascript">
537 /*<![CDATA[*/
538 var asciidoc = { // Namespace.
540 /////////////////////////////////////////////////////////////////////
541 // Table Of Contents generator
542 /////////////////////////////////////////////////////////////////////
544 /* Author: Mihai Bazon, September 2002
545 * http://students.infoiasi.ro/~mishoo
547 * Table Of Content generator
548 * Version: 0.4
550 * Feel free to use this script under the terms of the GNU General Public
551 * License, as long as you do not remove or alter this notice.
554 /* modified by Troy D. Hanson, September 2006. License: GPL */
555 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
557 // toclevels = 1..4.
558 toc: function (toclevels) {
560 function getText(el) {
561 var text = "";
562 for (var i = el.firstChild; i != null; i = i.nextSibling) {
563 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
564 text += i.data;
565 else if (i.firstChild != null)
566 text += getText(i);
568 return text;
571 function TocEntry(el, text, toclevel) {
572 this.element = el;
573 this.text = text;
574 this.toclevel = toclevel;
577 function tocEntries(el, toclevels) {
578 var result = new Array;
579 var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
580 // Function that scans the DOM tree for header elements (the DOM2
581 // nodeIterator API would be a better technique but not supported by all
582 // browsers).
583 var iterate = function (el) {
584 for (var i = el.firstChild; i != null; i = i.nextSibling) {
585 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
586 var mo = re.exec(i.tagName);
587 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
588 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
590 iterate(i);
594 iterate(el);
595 return result;
598 var toc = document.getElementById("toc");
599 if (!toc) {
600 return;
603 // Delete existing TOC entries in case we're reloading the TOC.
604 var tocEntriesToRemove = [];
605 var i;
606 for (i = 0; i < toc.childNodes.length; i++) {
607 var entry = toc.childNodes[i];
608 if (entry.nodeName == 'DIV'
609 && entry.getAttribute("class")
610 && entry.getAttribute("class").match(/^toclevel/))
611 tocEntriesToRemove.push(entry);
613 for (i = 0; i < tocEntriesToRemove.length; i++) {
614 toc.removeChild(tocEntriesToRemove[i]);
617 // Rebuild TOC entries.
618 var entries = tocEntries(document.getElementById("content"), toclevels);
619 for (var i = 0; i < entries.length; ++i) {
620 var entry = entries[i];
621 if (entry.element.id == "")
622 entry.element.id = "_toc_" + i;
623 var a = document.createElement("a");
624 a.href = "#" + entry.element.id;
625 a.appendChild(document.createTextNode(entry.text));
626 var div = document.createElement("div");
627 div.appendChild(a);
628 div.className = "toclevel" + entry.toclevel;
629 toc.appendChild(div);
631 if (entries.length == 0)
632 toc.parentNode.removeChild(toc);
636 /////////////////////////////////////////////////////////////////////
637 // Footnotes generator
638 /////////////////////////////////////////////////////////////////////
640 /* Based on footnote generation code from:
641 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
644 footnotes: function () {
645 // Delete existing footnote entries in case we're reloading the footnodes.
646 var i;
647 var noteholder = document.getElementById("footnotes");
648 if (!noteholder) {
649 return;
651 var entriesToRemove = [];
652 for (i = 0; i < noteholder.childNodes.length; i++) {
653 var entry = noteholder.childNodes[i];
654 if (entry.nodeName == 'DIV' && entry.getAttribute("class") == "footnote")
655 entriesToRemove.push(entry);
657 for (i = 0; i < entriesToRemove.length; i++) {
658 noteholder.removeChild(entriesToRemove[i]);
661 // Rebuild footnote entries.
662 var cont = document.getElementById("content");
663 var spans = cont.getElementsByTagName("span");
664 var refs = {};
665 var n = 0;
666 for (i=0; i<spans.length; i++) {
667 if (spans[i].className == "footnote") {
668 n++;
669 var note = spans[i].getAttribute("data-note");
670 if (!note) {
671 // Use [\s\S] in place of . so multi-line matches work.
672 // Because JavaScript has no s (dotall) regex flag.
673 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
674 spans[i].innerHTML =
675 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
676 "' title='View footnote' class='footnote'>" + n + "</a>]";
677 spans[i].setAttribute("data-note", note);
679 noteholder.innerHTML +=
680 "<div class='footnote' id='_footnote_" + n + "'>" +
681 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
682 n + "</a>. " + note + "</div>";
683 var id =spans[i].getAttribute("id");
684 if (id != null) refs["#"+id] = n;
687 if (n == 0)
688 noteholder.parentNode.removeChild(noteholder);
689 else {
690 // Process footnoterefs.
691 for (i=0; i<spans.length; i++) {
692 if (spans[i].className == "footnoteref") {
693 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
694 href = href.match(/#.*/)[0]; // Because IE return full URL.
695 n = refs[href];
696 spans[i].innerHTML =
697 "[<a href='#_footnote_" + n +
698 "' title='View footnote' class='footnote'>" + n + "</a>]";
704 install: function(toclevels) {
705 var timerId;
707 function reinstall() {
708 asciidoc.footnotes();
709 if (toclevels) {
710 asciidoc.toc(toclevels);
714 function reinstallAndRemoveTimer() {
715 clearInterval(timerId);
716 reinstall();
719 timerId = setInterval(reinstall, 500);
720 if (document.addEventListener)
721 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
722 else
723 window.onload = reinstallAndRemoveTimer;
727 asciidoc.install();
728 /*]]>*/
729 </script>
730 </head>
731 <body class="manpage">
732 <div id="header">
733 <h1>
734 Jim Tcl(n) Manual Page
735 </h1>
736 <h2>NAME</h2>
737 <div class="sectionbody">
738 <p>Jim Tcl v0.72 -
739 overview of the Jim tool command language facilities
740 </p>
741 </div>
742 </div>
743 <div id="content">
744 <div class="sect1">
745 <h2 id="_synopsis">SYNOPSIS</h2>
746 <div class="sectionbody">
747 <div class="literalblock">
748 <div class="content">
749 <pre><tt>cc &lt;source&gt; -ljim</tt></pre>
750 </div></div>
751 <div class="paragraph"><p>or</p></div>
752 <div class="literalblock">
753 <div class="content">
754 <pre><tt>jimsh [&lt;scriptfile&gt;]
755 jimsh -e '&lt;immediate-script&gt;'
756 jimsh --version</tt></pre>
757 </div></div>
758 <div class="ulist"><div class="title">Quick Index</div><ul>
759 <li>
761 <a href="#CommandIndex">Command Reference</a>
762 </p>
763 </li>
764 <li>
766 <a href="#OperatorPrecedence">Operator Precedence</a>
767 </p>
768 </li>
769 <li>
771 <a href="#BuiltinVariables">Builtin Variables</a>
772 </p>
773 </li>
774 <li>
776 <a href="#BackslashSequences">Backslash Sequences</a>
777 </p>
778 </li>
779 </ul></div>
780 </div>
781 </div>
782 <div class="sect1">
783 <h2 id="_introduction">INTRODUCTION</h2>
784 <div class="sectionbody">
785 <div class="paragraph"><p>Jim is a reimplementation of Tcl, combining some features from
786 earlier, smaller versions of Tcl (6.x) as well as more modern
787 features from later versions of Tcl (7.x, 8.x). It also has some some
788 entirely new features not available in any version of Tcl.</p></div>
789 <div class="paragraph"><p>This version is about double the size of "tinytcl" (6.8), depending upon
790 the features selected, but is significantly faster and has many new features.</p></div>
791 <div class="paragraph"><p>Note that most of this man page is the original 6.8 Tcl man page, with
792 changes made for differences with Jim.</p></div>
793 <div class="paragraph"><p>The major differences with Tcl 8.5/8.6 are:</p></div>
794 <div class="olist arabic"><ol class="arabic">
795 <li>
797 Object-based I/O (aio), but with a Tcl-compatibility layer
798 </p>
799 </li>
800 <li>
802 I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
803 </p>
804 </li>
805 <li>
807 Integers are 64bit
808 </p>
809 </li>
810 <li>
812 Support for references (<a href="#_ref"><strong><tt>ref</tt></strong></a>/<a href="#_getref"><strong><tt>getref</tt></strong></a>/<a href="#_setref"><strong><tt>setref</tt></strong></a>) and garbage collection
813 </p>
814 </li>
815 <li>
817 Builtin dictionary type (<a href="#_dict"><strong><tt>dict</tt></strong></a>) with some limitations compared to Tcl 8.6
818 </p>
819 </li>
820 <li>
822 <a href="#_env"><strong><tt>env</tt></strong></a> command to access environment variables
823 </p>
824 </li>
825 <li>
827 <a href="#cmd_1"><strong><tt>os.fork</tt></strong></a>, <a href="#cmd_1"><strong><tt>os.wait</tt></strong></a>, <a href="#cmd_1"><strong><tt>os.uptime</tt></strong></a>, <a href="#_rand"><strong><tt>rand</tt></strong></a>
828 </p>
829 </li>
830 <li>
832 Much better error reporting. <a href="#_info"><strong><tt>info</tt></strong></a> <tt>stacktrace</tt> as a replacement for <em>$errorInfo</em>, <em>$errorCode</em>
833 </p>
834 </li>
835 <li>
837 Support for "static" variables in procedures
838 </p>
839 </li>
840 <li>
842 Namespaces, threads and coroutines are not support
843 </p>
844 </li>
845 <li>
847 Command and variable traces are not supported
848 </p>
849 </li>
850 <li>
852 Direct command line editing rather than the <tt>history</tt> command
853 </p>
854 </li>
855 <li>
857 Expression shorthand syntax: <tt>$(&#8230;)</tt>
858 </p>
859 </li>
860 </ol></div>
861 </div>
862 </div>
863 <div class="sect1">
864 <h2 id="_recent_changes">RECENT CHANGES</h2>
865 <div class="sectionbody">
866 <div class="sect2">
867 <h3 id="_changes_between_0_71_and_0_72">Changes between 0.71 and 0.72</h3>
868 <div class="olist arabic"><ol class="arabic">
869 <li>
871 procs now allow <em>args</em> and optional parameters in any position
872 </p>
873 </li>
874 <li>
876 Add Tcl-compatible expr functions, <tt>rand()</tt>, <tt>srand()</tt> and <tt>pow()</tt>
877 </p>
878 </li>
879 <li>
881 Add support for the <em>-force</em> option to <a href="#_file"><strong><tt>file</tt></strong></a> <tt>delete</tt>
882 </p>
883 </li>
884 <li>
886 Better diagnostics when <a href="#_source"><strong><tt>source</tt></strong></a> fails to load a script with a missing quote or bracket
887 </p>
888 </li>
889 <li>
891 New <tt>tcl_platform(pathSeparator)</tt>
892 </p>
893 </li>
894 <li>
896 Add support settings the modification time with <a href="#_file"><strong><tt>file</tt></strong></a> <tt>mtime</tt>
897 </p>
898 </li>
899 <li>
901 <a href="#_exec"><strong><tt>exec</tt></strong></a> is now fully supported on win32 (mingw32)
902 </p>
903 </li>
904 <li>
906 <a href="#_file"><strong><tt>file</tt></strong></a> <tt>join</tt>, <a href="#_pwd"><strong><tt>pwd</tt></strong></a>, <a href="#_glob"><strong><tt>glob</tt></strong></a> etc. now work for mingw32
907 </p>
908 </li>
909 <li>
911 Line editing is now supported for the win32 console (mingw32)
912 </p>
913 </li>
914 <li>
916 Add <a href="#_aio"><strong><tt>aio</tt></strong></a> <tt>listen</tt> command
917 </p>
918 </li>
919 </ol></div>
920 </div>
921 <div class="sect2">
922 <h3 id="_changes_between_0_70_and_0_71">Changes between 0.70 and 0.71</h3>
923 <div class="olist arabic"><ol class="arabic">
924 <li>
926 Allow <em>args</em> to be renamed in procs
927 </p>
928 </li>
929 <li>
931 Add <tt>$(&#8230;)</tt> shorthand syntax for expressions
932 </p>
933 </li>
934 <li>
936 Add automatic reference variables in procs with <tt>&amp;var</tt> syntax
937 </p>
938 </li>
939 <li>
941 Support <tt>jimsh --version</tt>
942 </p>
943 </li>
944 <li>
946 Additional variables in <tt>tcl_platform()</tt>
947 </p>
948 </li>
949 <li>
951 <a href="#_local"><strong><tt>local</tt></strong></a> procs now push existing commands and <a href="#_upcall"><strong><tt>upcall</tt></strong></a> can call them
952 </p>
953 </li>
954 <li>
956 Add <a href="#_loop"><strong><tt>loop</tt></strong></a> command (TclX compatible)
957 </p>
958 </li>
959 <li>
961 Add <a href="#_aio"><strong><tt>aio</tt></strong></a> <tt>buffering</tt> command
962 </p>
963 </li>
964 <li>
966 <a href="#_info"><strong><tt>info</tt></strong></a> <tt>complete</tt> can now return the missing character
967 </p>
968 </li>
969 <li>
971 <a href="#_binary"><strong><tt>binary</tt></strong></a> <tt>format</tt> and <a href="#_binary"><strong><tt>binary</tt></strong></a> <tt>scan</tt> are now (optionally) supported
972 </p>
973 </li>
974 <li>
976 Add <a href="#_string"><strong><tt>string</tt></strong></a> <tt>byterange</tt>
977 </p>
978 </li>
979 <li>
981 Built-in regexp now support non-greedy repetition (*?, +?, ??)
982 </p>
983 </li>
984 </ol></div>
985 </div>
986 <div class="sect2">
987 <h3 id="_changes_between_0_63_and_0_70">Changes between 0.63 and 0.70</h3>
988 <div class="olist arabic"><ol class="arabic">
989 <li>
991 <tt>platform_tcl()</tt> settings are now automatically determined
992 </p>
993 </li>
994 <li>
996 Add aio <tt>$handle filename</tt>
997 </p>
998 </li>
999 <li>
1001 Add <a href="#_info"><strong><tt>info</tt></strong></a> <tt>channels</tt>
1002 </p>
1003 </li>
1004 <li>
1006 The <em>bio</em> extension is gone. Now <a href="#_aio"><strong><tt>aio</tt></strong></a> supports <em>copyto</em>.
1007 </p>
1008 </li>
1009 <li>
1011 Add <a href="#_exists"><strong><tt>exists</tt></strong></a> command
1012 </p>
1013 </li>
1014 <li>
1016 Add the pure-Tcl <em>oo</em> extension
1017 </p>
1018 </li>
1019 <li>
1021 The <a href="#_exec"><strong><tt>exec</tt></strong></a> command now only uses vfork(), not fork()
1022 </p>
1023 </li>
1024 <li>
1026 Unit test framework is less verbose and more Tcl-compatible
1027 </p>
1028 </li>
1029 <li>
1031 Optional UTF-8 support
1032 </p>
1033 </li>
1034 <li>
1036 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
1037 </p>
1038 </li>
1039 <li>
1041 Command line editing in interactive mode, e.g. <em>jimsh</em>
1042 </p>
1043 </li>
1044 </ol></div>
1045 </div>
1046 </div>
1047 </div>
1048 <div class="sect1">
1049 <h2 id="_tcl_introduction">TCL INTRODUCTION</h2>
1050 <div class="sectionbody">
1051 <div class="paragraph"><p>Tcl stands for <em>tool command language</em> and is pronounced <em>tickle.</em>
1052 It is actually two things: a language and a library.</p></div>
1053 <div class="paragraph"><p>First, Tcl is a simple textual language, intended primarily for
1054 issuing commands to interactive programs such as text editors,
1055 debuggers, illustrators, and shells. It has a simple syntax and is also
1056 programmable, so Tcl users can write command procedures to provide more
1057 powerful commands than those in the built-in set.</p></div>
1058 <div class="paragraph"><p>Second, Tcl is a library package that can be embedded in application
1059 programs. The Tcl library consists of a parser for the Tcl language,
1060 routines to implement the Tcl built-in commands, and procedures that
1061 allow each application to extend Tcl with additional commands specific
1062 to that application. The application program generates Tcl commands and
1063 passes them to the Tcl parser for execution. Commands may be generated
1064 by reading characters from an input source, or by associating command
1065 strings with elements of the application&#8217;s user interface, such as menu
1066 entries, buttons, or keystrokes.</p></div>
1067 <div class="paragraph"><p>When the Tcl library receives commands it parses them into component
1068 fields and executes built-in commands directly. For commands implemented
1069 by the application, Tcl calls back to the application to execute the
1070 commands. In many cases commands will invoke recursive invocations of the
1071 Tcl interpreter by passing in additional strings to execute (procedures,
1072 looping commands, and conditional commands all work in this way).</p></div>
1073 <div class="paragraph"><p>An application program gains three advantages by using Tcl for its command
1074 language. First, Tcl provides a standard syntax: once users know Tcl,
1075 they will be able to issue commands easily to any Tcl-based application.
1076 Second, Tcl provides programmability. All a Tcl application needs
1077 to do is to implement a few application-specific low-level commands.
1078 Tcl provides many utility commands plus a general programming interface
1079 for building up complex command procedures. By using Tcl, applications
1080 need not re-implement these features.</p></div>
1081 <div class="paragraph"><p>Third, Tcl can be used as a common language for communicating between
1082 applications. Inter-application communication is not built into the
1083 Tcl core described here, but various add-on libraries, such as the Tk
1084 toolkit, allow applications to issue commands to each other. This makes
1085 it possible for applications to work together in much more powerful ways
1086 than was previously possible.</p></div>
1087 <div class="paragraph"><p>Fourth, Jim Tcl includes a command processor, <tt>jimsh</tt>, which can be
1088 used to run standalone Tcl scripts, or to run Tcl commands interactively.</p></div>
1089 <div class="paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
1090 the language syntax and the built-in commands that will be available
1091 in any application based on Tcl. The individual library procedures are
1092 described in more detail in separate manual pages, one per procedure.</p></div>
1093 </div>
1094 </div>
1095 <div class="sect1">
1096 <h2 id="_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER</h2>
1097 <div class="sectionbody">
1098 <div class="paragraph"><p>A simple, but powerful command processor, <tt>jimsh</tt>, is part of Jim Tcl.
1099 It may be invoked in interactive mode as:</p></div>
1100 <div class="literalblock">
1101 <div class="content">
1102 <pre><tt>jimsh</tt></pre>
1103 </div></div>
1104 <div class="paragraph"><p>or to process the Tcl script in a file with:</p></div>
1105 <div class="literalblock">
1106 <div class="content">
1107 <pre><tt>jimsh filename</tt></pre>
1108 </div></div>
1109 <div class="paragraph"><p>It may also be invoked to execute an immediate script with:</p></div>
1110 <div class="literalblock">
1111 <div class="content">
1112 <pre><tt>jimsh -e "script"</tt></pre>
1113 </div></div>
1114 <div class="sect2">
1115 <h3 id="_interactive_mode">Interactive Mode</h3>
1116 <div class="paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
1117 those commands and prints the results.</p></div>
1118 <div class="literalblock">
1119 <div class="content">
1120 <pre><tt>$ jimsh
1121 Welcome to Jim version 0.71, Copyright (c) 2005-8 Salvatore Sanfilippo
1122 . info version
1123 0.71
1124 . lsort [info commands p*]
1125 package parray pid popen proc puts pwd
1126 . foreach i {a b c} {
1127 {&gt; puts $i
1128 {&gt; }
1132 . bad
1133 invalid command name "bad"
1134 [error] . exit
1135 $</tt></pre>
1136 </div></div>
1137 <div class="paragraph"><p>If <tt>jimsh</tt> is configured with line editing (it is by default) and a VT-100-compatible
1138 terminal is detected, Emacs-style line editing commands are available, including:
1139 arrow keys, <tt>^W</tt> to erase a word, <tt>^U</tt> to erase the line, <tt>^R</tt> for reverse incremental search
1140 in history. Additionally, the <tt>h</tt> command may be used to display the command history.</p></div>
1141 <div class="paragraph"><p>Command line history is automatically saved and loaded from <tt>~/.jim_history</tt></p></div>
1142 <div class="paragraph"><p>In interactive mode, <tt>jimsh</tt> automatically runs the script <tt>~/.jimrc</tt> at startup
1143 if it exists.</p></div>
1144 </div>
1145 </div>
1146 </div>
1147 <div class="sect1">
1148 <h2 id="_interpreters">INTERPRETERS</h2>
1149 <div class="sectionbody">
1150 <div class="paragraph"><p>The central data structure in Tcl is an interpreter (C type <em>Jim_Interp</em>).
1151 An interpreter consists of a set of command bindings, a set of variable
1152 values, and a few other miscellaneous pieces of state. Each Tcl command
1153 is interpreted in the context of a particular interpreter.</p></div>
1154 <div class="paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
1155 simultaneously, each associated with a different widget or portion of
1156 the application. Interpreters are relatively lightweight structures.
1157 They can be created and deleted quickly, so application programmers should
1158 feel free to use multiple interpreters if that simplifies the application.</p></div>
1159 </div>
1160 </div>
1161 <div class="sect1">
1162 <h2 id="_data_types">DATA TYPES</h2>
1163 <div class="sectionbody">
1164 <div class="paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
1165 to commands, all command results, and all variable values are strings.</p></div>
1166 <div class="paragraph"><p>Where commands require numeric arguments or return numeric results,
1167 the arguments and results are passed as strings. Many commands expect
1168 their string arguments to have certain formats, but this interpretation
1169 is up to the individual commands. For example, arguments often contain
1170 Tcl command strings, which may get executed as part of the commands.
1171 The easiest way to understand the Tcl interpreter is to remember that
1172 everything is just an operation on a string. In many cases Tcl constructs
1173 will look similar to more structured constructs from other languages.
1174 However, the Tcl constructs are not structured at all; they are just
1175 strings of characters, and this gives them a different behaviour than
1176 the structures they may look like.</p></div>
1177 <div class="paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
1178 the interpretation, there are three common forms that strings take:
1179 commands, expressions, and lists. The major sections below discuss
1180 these three forms in more detail.</p></div>
1181 </div>
1182 </div>
1183 <div class="sect1">
1184 <h2 id="_basic_command_syntax">BASIC COMMAND SYNTAX</h2>
1185 <div class="sectionbody">
1186 <div class="paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
1187 and Lisp. However, the interpretation of commands is different
1188 in Tcl than in either of those other two systems.
1189 A Tcl command string consists of one or more commands separated
1190 by newline characters or semi-colons.
1191 Each command consists of a collection of fields separated by
1192 white space (spaces or tabs).
1193 The first field must be the name of a command, and the
1194 additional fields, if any, are arguments that will be passed to
1195 that command. For example, the command:</p></div>
1196 <div class="literalblock">
1197 <div class="content">
1198 <pre><tt>set a 22</tt></pre>
1199 </div></div>
1200 <div class="paragraph"><p>has three fields: the first, <a href="#_set"><strong><tt>set</tt></strong></a>, is the name of a Tcl command, and
1201 the last two, <em>a</em> and <em>22</em>, will be passed as arguments to
1202 the <a href="#_set"><strong><tt>set</tt></strong></a> command. The command name may refer either to a built-in
1203 Tcl command, an application-specific command bound in with the library
1204 procedure <em>Jim_CreateCommand</em>, or a command procedure defined with the
1205 <a href="#_proc"><strong><tt>proc</tt></strong></a> built-in command.</p></div>
1206 <div class="paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1207 interpret those strings in any fashion they wish. The <a href="#_set"><strong><tt>set</tt></strong></a> command,
1208 for example, will treat its first argument as the name of a variable
1209 and its second argument as a string value to assign to that variable.
1210 For other commands arguments may be interpreted as integers, lists,
1211 file names, or Tcl commands.</p></div>
1212 <div class="paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1213 However, if the Tcl interpreter cannot locate a command it invokes a
1214 special command named <a href="#_unknown"><strong><tt>unknown</tt></strong></a> which attempts to find or create the
1215 command.</p></div>
1216 <div class="paragraph"><p>For example, at many sites <a href="#_unknown"><strong><tt>unknown</tt></strong></a> will search through library
1217 directories for the desired command and create it as a Tcl procedure if
1218 it is found. The <a href="#_unknown"><strong><tt>unknown</tt></strong></a> command often provides automatic completion
1219 of abbreviated commands, but usually only for commands that were typed
1220 interactively.</p></div>
1221 <div class="paragraph"><p>It&#8217;s probably a bad idea to use abbreviations in command scripts and
1222 other forms that will be re-used over time: changes to the command set
1223 may cause abbreviations to become ambiguous, resulting in scripts that
1224 no longer work.</p></div>
1225 </div>
1226 </div>
1227 <div class="sect1">
1228 <h2 id="_comments">COMMENTS</h2>
1229 <div class="sectionbody">
1230 <div class="paragraph"><p>If the first non-blank character in a command is <tt>#</tt>, then everything
1231 from the <tt>#</tt> up through the next newline character is treated as
1232 a comment and ignored. When comments are embedded inside nested
1233 commands (e.g. fields enclosed in braces) they must have properly-matched
1234 braces (this is necessary because when Tcl parses the top-level command
1235 it doesn&#8217;t yet know that the nested field will be used as a command so
1236 it cannot process the nested comment character as a comment).</p></div>
1237 </div>
1238 </div>
1239 <div class="sect1">
1240 <h2 id="_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES</h2>
1241 <div class="sectionbody">
1242 <div class="paragraph"><p>Normally each argument field ends at the next white space, but
1243 double-quotes may be used to create arguments with embedded space.</p></div>
1244 <div class="paragraph"><p>If an argument field begins with a double-quote, then the argument isn&#8217;t
1245 terminated by white space (including newlines) or a semi-colon (see below
1246 for information on semi-colons); instead it ends at the next double-quote
1247 character. The double-quotes are not included in the resulting argument.
1248 For example, the command</p></div>
1249 <div class="literalblock">
1250 <div class="content">
1251 <pre><tt>set a "This is a single argument"</tt></pre>
1252 </div></div>
1253 <div class="paragraph"><p>will pass two arguments to <a href="#_set"><strong><tt>set</tt></strong></a>: <em>a</em> and <em>This is a single argument</em>.</p></div>
1254 <div class="paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1255 and backslash substitutions still occur, as described below. If the
1256 first character of a command field is not a quote, then quotes receive
1257 no special interpretation in the parsing of that field.</p></div>
1258 </div>
1259 </div>
1260 <div class="sect1">
1261 <h2 id="_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES</h2>
1262 <div class="sectionbody">
1263 <div class="paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1264 to quotes except for two differences. First, they nest; this makes them
1265 easier to use for complicated arguments like nested Tcl command strings.
1266 Second, the substitutions described below for commands, variables, and
1267 backslashes do <strong>not</strong> occur in arguments enclosed in braces, so braces
1268 can be used to prevent substitutions where they are undesirable.</p></div>
1269 <div class="paragraph"><p>If an argument field begins with a left brace, then the argument ends
1270 at the matching right brace. Tcl will strip off the outermost layer
1271 of braces and pass the information between the braces to the command
1272 without any further modification. For example, in the command</p></div>
1273 <div class="literalblock">
1274 <div class="content">
1275 <pre><tt>set a {xyz a {b c d}}</tt></pre>
1276 </div></div>
1277 <div class="paragraph"><p>the <a href="#_set"><strong><tt>set</tt></strong></a> command will receive two arguments: <em>a</em>
1278 and <em>xyz a {b c d}</em>.</p></div>
1279 <div class="paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1280 not be on the same line as the starting quote or brace; in this case
1281 the newline will be included in the argument field along with any other
1282 characters up to the matching brace or quote. For example, the <a href="#_eval"><strong><tt>eval</tt></strong></a>
1283 command takes one argument, which is a command string; <a href="#_eval"><strong><tt>eval</tt></strong></a> invokes
1284 the Tcl interpreter to execute the command string. The command</p></div>
1285 <div class="literalblock">
1286 <div class="content">
1287 <pre><tt>eval {
1288 set a 22
1289 set b 33
1290 }</tt></pre>
1291 </div></div>
1292 <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>
1293 <div class="paragraph"><p>If the first character of a command field is not a left
1294 brace, then neither left nor right
1295 braces in the field will be treated specially (except as part of
1296 variable substitution; see below).</p></div>
1297 </div>
1298 </div>
1299 <div class="sect1">
1300 <h2 id="_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS</h2>
1301 <div class="sectionbody">
1302 <div class="paragraph"><p>If an open bracket occurs in a field of a command, then command
1303 substitution occurs (except for fields enclosed in braces). All of the
1304 text up to the matching close bracket is treated as a Tcl command and
1305 executed immediately. Then the result of that command is substituted
1306 for the bracketed text. For example, consider the command</p></div>
1307 <div class="literalblock">
1308 <div class="content">
1309 <pre><tt>set a [set b]</tt></pre>
1310 </div></div>
1311 <div class="paragraph"><p>When the <a href="#_set"><strong><tt>set</tt></strong></a> command has only a single argument, it is the name of a
1312 variable and <a href="#_set"><strong><tt>set</tt></strong></a> returns the contents of that variable. In this case,
1313 if variable <em>b</em> has the value <em>foo</em>, then the command above is equivalent
1314 to the command</p></div>
1315 <div class="literalblock">
1316 <div class="content">
1317 <pre><tt>set a foo</tt></pre>
1318 </div></div>
1319 <div class="paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1320 <em>b</em> has the value <em>foo</em> and the variable <em>c</em> has the value <em>gorp</em>,
1321 then the command</p></div>
1322 <div class="literalblock">
1323 <div class="content">
1324 <pre><tt>set a xyz[set b].[set c]</tt></pre>
1325 </div></div>
1326 <div class="paragraph"><p>is equivalent to the command</p></div>
1327 <div class="literalblock">
1328 <div class="content">
1329 <pre><tt>set a xyzfoo.gorp</tt></pre>
1330 </div></div>
1331 <div class="paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1332 or semi-colons in the usual fashion. In this case the value of the last
1333 command is used for substitution. For example, the command</p></div>
1334 <div class="literalblock">
1335 <div class="content">
1336 <pre><tt>set a x[set b 22
1337 expr $b+2]x</tt></pre>
1338 </div></div>
1339 <div class="paragraph"><p>is equivalent to the command</p></div>
1340 <div class="literalblock">
1341 <div class="content">
1342 <pre><tt>set a x24x</tt></pre>
1343 </div></div>
1344 <div class="paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1345 between them are not interpreted specially; they are passed through to
1346 the argument verbatim.</p></div>
1347 </div>
1348 </div>
1349 <div class="sect1">
1350 <h2 id="_variable_substitution_with">VARIABLE SUBSTITUTION WITH $</h2>
1351 <div class="sectionbody">
1352 <div class="paragraph"><p>The dollar sign (<tt>$</tt>) may be used as a special shorthand form for
1353 substituting variable values. If <tt>$</tt> appears in an argument that isn&#8217;t
1354 enclosed in braces then variable substitution will occur. The characters
1355 after the <tt>$</tt>, up to the first character that isn&#8217;t a number, letter,
1356 or underscore, are taken as a variable name and the string value of that
1357 variable is substituted for the name.</p></div>
1358 <div class="paragraph"><p>For example, if variable <em>foo</em> has the value <em>test</em>, then the command</p></div>
1359 <div class="literalblock">
1360 <div class="content">
1361 <pre><tt>set a $foo.c</tt></pre>
1362 </div></div>
1363 <div class="paragraph"><p>is equivalent to the command</p></div>
1364 <div class="literalblock">
1365 <div class="content">
1366 <pre><tt>set a test.c</tt></pre>
1367 </div></div>
1368 <div class="paragraph"><p>There are two special forms for variable substitution. If the next
1369 character after the name of the variable is an open parenthesis, then
1370 the variable is assumed to be an array name, and all of the characters
1371 between the open parenthesis and the next close parenthesis are taken as
1372 an index into the array. Command substitutions and variable substitutions
1373 are performed on the information between the parentheses before it is
1374 used as an index.</p></div>
1375 <div class="paragraph"><p>For example, if the variable <em>x</em> is an array with one element named
1376 <em>first</em> and value <em>87</em> and another element named <em>14</em> and value <em>more</em>,
1377 then the command</p></div>
1378 <div class="literalblock">
1379 <div class="content">
1380 <pre><tt>set a xyz$x(first)zyx</tt></pre>
1381 </div></div>
1382 <div class="paragraph"><p>is equivalent to the command</p></div>
1383 <div class="literalblock">
1384 <div class="content">
1385 <pre><tt>set a xyz87zyx</tt></pre>
1386 </div></div>
1387 <div class="paragraph"><p>If the variable <em>index</em> has the value <em>14</em>, then the command</p></div>
1388 <div class="literalblock">
1389 <div class="content">
1390 <pre><tt>set a xyz$x($index)zyx</tt></pre>
1391 </div></div>
1392 <div class="paragraph"><p>is equivalent to the command</p></div>
1393 <div class="literalblock">
1394 <div class="content">
1395 <pre><tt>set a xyzmorezyx</tt></pre>
1396 </div></div>
1397 <div class="paragraph"><p>For more information on arrays, see VARIABLES AND ARRAYS below.</p></div>
1398 <div class="paragraph"><p>The second special form for variables occurs when the dollar sign is
1399 followed by an open curly brace. In this case the variable name consists
1400 of all the characters up to the next curly brace.</p></div>
1401 <div class="paragraph"><p>Array references are not possible in this form: the name between braces
1402 is assumed to refer to a scalar variable. For example, if variable
1403 <em>foo</em> has the value <em>test</em>, then the command</p></div>
1404 <div class="literalblock">
1405 <div class="content">
1406 <pre><tt>set a abc${foo}bar</tt></pre>
1407 </div></div>
1408 <div class="paragraph"><p>is equivalent to the command</p></div>
1409 <div class="literalblock">
1410 <div class="content">
1411 <pre><tt>set a abctestbar</tt></pre>
1412 </div></div>
1413 <div class="paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1414 braces: the dollar sign and variable name are passed through to the
1415 argument verbatim.</p></div>
1416 <div class="paragraph"><p>The dollar sign abbreviation is simply a shorthand form. <tt>$a</tt> is
1417 completely equivalent to <tt>[set a]</tt>; it is provided as a convenience
1418 to reduce typing.</p></div>
1419 </div>
1420 </div>
1421 <div class="sect1">
1422 <h2 id="_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS</h2>
1423 <div class="sectionbody">
1424 <div class="paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1425 newline character). However, semi-colon (<tt>;</tt>) is treated as a command
1426 separator character; multiple commands may be placed on one line by
1427 separating them with a semi-colon. Semi-colons are not treated as
1428 command separators if they appear within curly braces or double-quotes.</p></div>
1429 </div>
1430 </div>
1431 <div class="sect1">
1432 <h2 id="_backslash_substitution">BACKSLASH SUBSTITUTION</h2>
1433 <div class="sectionbody">
1434 <div class="paragraph"><p>Backslashes may be used to insert non-printing characters into command
1435 fields and also to insert special characters like braces and brackets
1436 into fields without them being interpreted specially as described above.</p></div>
1437 <div class="paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1438 listed below. In each case, the backslash
1439 sequence is replaced by the given character:</p></div>
1440 <div class="dlist" id="BackslashSequences"><dl>
1441 <dt class="hdlist1">
1442 <tt>\b</tt>
1443 </dt>
1444 <dd>
1446 Backspace (0x8)
1447 </p>
1448 </dd>
1449 <dt class="hdlist1">
1450 <tt>\f</tt>
1451 </dt>
1452 <dd>
1454 Form feed (0xc)
1455 </p>
1456 </dd>
1457 <dt class="hdlist1">
1458 <tt>\n</tt>
1459 </dt>
1460 <dd>
1462 Newline (0xa)
1463 </p>
1464 </dd>
1465 <dt class="hdlist1">
1466 <tt>\r</tt>
1467 </dt>
1468 <dd>
1470 Carriage-return (0xd).
1471 </p>
1472 </dd>
1473 <dt class="hdlist1">
1474 <tt>\t</tt>
1475 </dt>
1476 <dd>
1478 Tab (0x9).
1479 </p>
1480 </dd>
1481 <dt class="hdlist1">
1482 <tt>\v</tt>
1483 </dt>
1484 <dd>
1486 Vertical tab (0xb).
1487 </p>
1488 </dd>
1489 <dt class="hdlist1">
1490 <tt>\{</tt>
1491 </dt>
1492 <dd>
1494 Left brace ({).
1495 </p>
1496 </dd>
1497 <dt class="hdlist1">
1498 <tt>\}</tt>
1499 </dt>
1500 <dd>
1502 Right brace (}).
1503 </p>
1504 </dd>
1505 <dt class="hdlist1">
1506 <tt>\[</tt>
1507 </dt>
1508 <dd>
1510 Open bracket ([).
1511 </p>
1512 </dd>
1513 <dt class="hdlist1">
1514 <tt>\]</tt>
1515 </dt>
1516 <dd>
1518 Close bracket (]).
1519 </p>
1520 </dd>
1521 <dt class="hdlist1">
1522 <tt>\$</tt>
1523 </dt>
1524 <dd>
1526 Dollar sign ($).
1527 </p>
1528 </dd>
1529 <dt class="hdlist1">
1530 <tt>\&lt;space&gt;</tt>
1531 </dt>
1532 <dd>
1534 Space ( ): doesn&#8217;t terminate argument.
1535 </p>
1536 </dd>
1537 <dt class="hdlist1">
1538 <tt>\;</tt>
1539 </dt>
1540 <dd>
1542 Semi-colon: doesn&#8217;t terminate command.
1543 </p>
1544 </dd>
1545 <dt class="hdlist1">
1546 <tt>\"</tt>
1547 </dt>
1548 <dd>
1550 Double-quote.
1551 </p>
1552 </dd>
1553 <dt class="hdlist1">
1554 <tt>\&lt;newline&gt;</tt>
1555 </dt>
1556 <dd>
1558 Nothing: this joins two lines together
1559 into a single line. This backslash feature is unique in that
1560 it will be applied even when the sequence occurs within braces.
1561 </p>
1562 </dd>
1563 <dt class="hdlist1">
1564 <tt>\\</tt>
1565 </dt>
1566 <dd>
1568 Backslash (<em>\</em>).
1569 </p>
1570 </dd>
1571 <dt class="hdlist1">
1572 <tt>\'ddd'</tt>
1573 </dt>
1574 <dd>
1576 The digits <tt><em>ddd</em></tt> (one, two, or three of them) give the octal value of
1577 the character. Note that Jim supports null characters in strings.
1578 </p>
1579 </dd>
1580 <dt class="hdlist1">
1581 <tt>\'unnnn'</tt>
1582 </dt>
1583 <dd>
1585 The hex digits <tt><em>nnnn</em></tt> (between one and four of them) give a unicode codepoint.
1586 The UTF-8 encoding of the codepoint is inserted.
1587 </p>
1588 </dd>
1589 </dl></div>
1590 <div class="paragraph"><p>For example, in the command</p></div>
1591 <div class="literalblock">
1592 <div class="content">
1593 <pre><tt>set a \{x\[\ yz\141</tt></pre>
1594 </div></div>
1595 <div class="paragraph"><p>the second argument to <a href="#_set"><strong><tt>set</tt></strong></a> will be <tt>{x[ yza</tt>.</p></div>
1596 <div class="paragraph"><p>If a backslash is followed by something other than one of the options
1597 described above, then the backslash is transmitted to the argument
1598 field without any special processing, and the Tcl scanner continues
1599 normal processing with the next character. For example, in the
1600 command</p></div>
1601 <div class="literalblock">
1602 <div class="content">
1603 <pre><tt>set \*a \\\{foo</tt></pre>
1604 </div></div>
1605 <div class="paragraph"><p>The first argument to <a href="#_set"><strong><tt>set</tt></strong></a> will be <tt>\*a</tt> and the second
1606 argument will be <tt>\{foo</tt>.</p></div>
1607 <div class="paragraph"><p>If an argument is enclosed in braces, then backslash sequences inside
1608 the argument are parsed but no substitution occurs (except for
1609 backslash-newline): the backslash
1610 sequence is passed through to the argument as is, without making
1611 any special interpretation of the characters in the backslash sequence.
1612 In particular, backslashed braces are not counted in locating the
1613 matching right brace that terminates the argument.
1614 For example, in the
1615 command</p></div>
1616 <div class="literalblock">
1617 <div class="content">
1618 <pre><tt>set a {\{abc}</tt></pre>
1619 </div></div>
1620 <div class="paragraph"><p>the second argument to <a href="#_set"><strong><tt>set</tt></strong></a> will be <tt>\{abc</tt>.</p></div>
1621 <div class="paragraph"><p>This backslash mechanism is not sufficient to generate absolutely
1622 any argument structure; it only covers the
1623 most common cases. To produce particularly complicated arguments
1624 it is probably easiest to use the <a href="#_format"><strong><tt>format</tt></strong></a> command along with
1625 command substitution.</p></div>
1626 </div>
1627 </div>
1628 <div class="sect1">
1629 <h2 id="_string_and_list_index_specifications">STRING AND LIST INDEX SPECIFICATIONS</h2>
1630 <div class="sectionbody">
1631 <div class="paragraph"><p>Many string and list commands take one or more <em>index</em> parameters which
1632 specify a position in the string relative to the start or end of the string/list.</p></div>
1633 <div class="paragraph"><p>The index may be one of the following forms:</p></div>
1634 <div class="dlist"><dl>
1635 <dt class="hdlist1">
1636 <tt>integer</tt>
1637 </dt>
1638 <dd>
1640 A simple integer, where <em>0</em> refers to the first element of the string
1641 or list.
1642 </p>
1643 </dd>
1644 <dt class="hdlist1">
1645 <tt>integer+integer</tt> or
1646 </dt>
1647 <dt class="hdlist1">
1648 <tt>integer-integer</tt>
1649 </dt>
1650 <dd>
1652 The sum or difference of the two integers. e.g. <tt>2+3</tt> refers to the 5th element.
1653 This is useful when used with (e.g.) <tt>$i+1</tt> rather than the more verbose
1654 <tt>[expr {$i+1}]</tt>
1655 </p>
1656 </dd>
1657 <dt class="hdlist1">
1658 <tt>end</tt>
1659 </dt>
1660 <dd>
1662 The last element of the string or list.
1663 </p>
1664 </dd>
1665 <dt class="hdlist1">
1666 <tt>end-integer</tt>
1667 </dt>
1668 <dd>
1670 The <em>nth-from-last</em> element of the string or list.
1671 </p>
1672 </dd>
1673 </dl></div>
1674 </div>
1675 </div>
1676 <div class="sect1">
1677 <h2 id="_command_summary">COMMAND SUMMARY</h2>
1678 <div class="sectionbody">
1679 <div class="olist arabic"><ol class="arabic">
1680 <li>
1682 A command is just a string.
1683 </p>
1684 </li>
1685 <li>
1687 Within a string commands are separated by newlines or semi-colons
1688 (unless the newline or semi-colon is within braces or brackets
1689 or is backslashed).
1690 </p>
1691 </li>
1692 <li>
1694 A command consists of fields. The first field is the name of the command.
1695 The other fields are strings that are passed to that command as arguments.
1696 </p>
1697 </li>
1698 <li>
1700 Fields are normally separated by white space.
1701 </p>
1702 </li>
1703 <li>
1705 Double-quotes allow white space and semi-colons to appear within
1706 a single argument.
1707 Command substitution, variable substitution, and backslash substitution
1708 still occur inside quotes.
1709 </p>
1710 </li>
1711 <li>
1713 Braces defer interpretation of special characters.
1714 If a field begins with a left brace, then it consists of everything
1715 between the left brace and the matching right brace. The
1716 braces themselves are not included in the argument.
1717 No further processing is done on the information between the braces
1718 except that backslash-newline sequences are eliminated.
1719 </p>
1720 </li>
1721 <li>
1723 If a field doesn&#8217;t begin with a brace then backslash,
1724 variable, and command substitution are done on the field. Only a
1725 single level of processing is done: the results of one substitution
1726 are not scanned again for further substitutions or any other
1727 special treatment. Substitution can
1728 occur on any field of a command, including the command name
1729 as well as the arguments.
1730 </p>
1731 </li>
1732 <li>
1734 If the first non-blank character of a command is a <tt>#</tt>, everything
1735 from the <tt>#</tt> up through the next newline is treated as a comment
1736 and ignored.
1737 </p>
1738 </li>
1739 </ol></div>
1740 </div>
1741 </div>
1742 <div class="sect1">
1743 <h2 id="_expressions">EXPRESSIONS</h2>
1744 <div class="sectionbody">
1745 <div class="paragraph"><p>The second major interpretation applied to strings in Tcl is
1746 as expressions. Several commands, such as <a href="#_expr"><strong><tt>expr</tt></strong></a>, <a href="#_for"><strong><tt>for</tt></strong></a>,
1747 and <a href="#_if"><strong><tt>if</tt></strong></a>, treat one or more of their arguments as expressions
1748 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
1749 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
1750 <div class="paragraph"><p>The operators permitted in Tcl expressions are a subset of
1751 the operators permitted in C expressions, and they have the
1752 same meaning and precedence as the corresponding C operators.
1753 Expressions almost always yield numeric results
1754 (integer or floating-point values).
1755 For example, the expression</p></div>
1756 <div class="literalblock">
1757 <div class="content">
1758 <pre><tt>8.2 + 6</tt></pre>
1759 </div></div>
1760 <div class="paragraph"><p>evaluates to 14.2.</p></div>
1761 <div class="paragraph"><p>Tcl expressions differ from C expressions in the way that
1762 operands are specified, and in that Tcl expressions support
1763 non-numeric operands and string comparisons.</p></div>
1764 <div class="paragraph"><p>A Tcl expression consists of a combination of operands, operators,
1765 and parentheses.</p></div>
1766 <div class="paragraph"><p>White space may be used between the operands and operators and
1767 parentheses; it is ignored by the expression processor.
1768 Where possible, operands are interpreted as integer values.</p></div>
1769 <div class="paragraph"><p>Integer values may be specified in decimal (the normal case), in octal (if the
1770 first character of the operand is <em>0</em>), or in hexadecimal (if the first
1771 two characters of the operand are <em>0x</em>).</p></div>
1772 <div class="paragraph"><p>If an operand does not have one of the integer formats given
1773 above, then it is treated as a floating-point number if that is
1774 possible. Floating-point numbers may be specified in any of the
1775 ways accepted by an ANSI-compliant C compiler (except that the
1776 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
1777 most installations). For example, all of the
1778 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
1779 <div class="paragraph"><p>If no numeric interpretation is possible, then an operand is left
1780 as a string (and only a limited set of operators may be applied to
1781 it).</p></div>
1782 <div class="olist arabic"><ol class="arabic">
1783 <li>
1785 Operands may be specified in any of the following ways:
1786 </p>
1787 </li>
1788 <li>
1790 As a numeric value, either integer or floating-point.
1791 </p>
1792 </li>
1793 <li>
1795 As a Tcl variable, using standard <em>$</em> notation.
1796 The variable&#8217;s value will be used as the operand.
1797 </p>
1798 </li>
1799 <li>
1801 As a string enclosed in double-quotes.
1802 The expression parser will perform backslash, variable, and
1803 command substitutions on the information between the quotes,
1804 and use the resulting value as the operand
1805 </p>
1806 </li>
1807 <li>
1809 As a string enclosed in braces.
1810 The characters between the open brace and matching close brace
1811 will be used as the operand without any substitutions.
1812 </p>
1813 </li>
1814 <li>
1816 As a Tcl command enclosed in brackets.
1817 The command will be executed and its result will be used as
1818 the operand.
1819 </p>
1820 </li>
1821 </ol></div>
1822 <div class="paragraph"><p>Where substitutions occur above (e.g. inside quoted strings), they
1823 are performed by the expression processor.
1824 However, an additional layer of substitution may already have
1825 been performed by the command parser before the expression
1826 processor was called.</p></div>
1827 <div class="paragraph"><p>As discussed below, it is usually best to enclose expressions
1828 in braces to prevent the command parser from performing substitutions
1829 on the contents.</p></div>
1830 <div class="paragraph"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
1831 the value 3 and the variable <em>b</em> has the value 6. Then the expression
1832 on the left side of each of the lines below will evaluate to the value
1833 on the right side of the line:</p></div>
1834 <div class="literalblock">
1835 <div class="content">
1836 <pre><tt>$a + 3.1 6.1
1837 2 + "$a.$b" 5.6
1838 4*[llength "6 2"] 8
1839 {word one} &lt; "word $a" 0</tt></pre>
1840 </div></div>
1841 <div class="paragraph"><p>The valid operators are listed below, grouped in decreasing order
1842 of precedence:</p></div>
1843 <div class="dlist" id="OperatorPrecedence"><dl>
1844 <dt class="hdlist1">
1845 <tt>int() double() round() abs(), rand(), srand()</tt>
1846 </dt>
1847 <dd>
1849 Unary functions (except rand() which takes no arguments)
1850 </p>
1851 <div class="ulist"><ul>
1852 <li>
1854 <tt><em>int()</em></tt> converts the numeric argument to an integer by truncating down.
1855 </p>
1856 </li>
1857 <li>
1859 <tt><em>double()</em></tt> converts the numeric argument to floating point.
1860 </p>
1861 </li>
1862 <li>
1864 <tt><em>round()</em></tt> converts the numeric argument to the closest integer value.
1865 </p>
1866 </li>
1867 <li>
1869 <tt><em>abs()</em></tt> takes the absolute value of the numeric argument.
1870 </p>
1871 </li>
1872 <li>
1874 <tt><em>rand()</em></tt> takes the absolute value of the numeric argument.
1875 </p>
1876 </li>
1877 <li>
1879 <tt><em>rand()</em></tt> returns a pseudo-random floating-point value in the range (0,1).
1880 </p>
1881 </li>
1882 <li>
1884 <tt><em>srand()</em></tt> takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
1885 </p>
1886 </li>
1887 </ul></div>
1888 </dd>
1889 <dt class="hdlist1">
1890 <tt>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</tt>
1891 </dt>
1892 <dd>
1894 Unary math functions.
1895 If Jim is compiled with math support, these functions are available.
1896 </p>
1897 </dd>
1898 <dt class="hdlist1">
1899 <tt>- + ~ !</tt>
1900 </dt>
1901 <dd>
1903 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
1904 may be applied to string operands, and bit-wise NOT may be
1905 applied only to integers.
1906 </p>
1907 </dd>
1908 <dt class="hdlist1">
1909 <tt>** pow(x,y)</tt>
1910 </dt>
1911 <dd>
1913 Power. e.g. <em>x<sup>y</sup></em>. If Jim is compiled with math support, supports doubles and
1914 integers. Otherwise supports integers only. (Note that the math-function form
1915 has the same highest precedence)
1916 </p>
1917 </dd>
1918 <dt class="hdlist1">
1919 <tt>* / %</tt>
1920 </dt>
1921 <dd>
1923 Multiply, divide, remainder. None of these operands may be
1924 applied to string operands, and remainder may be applied only
1925 to integers.
1926 </p>
1927 </dd>
1928 <dt class="hdlist1">
1929 <tt>+ -</tt>
1930 </dt>
1931 <dd>
1933 Add and subtract. Valid for any numeric operands.
1934 </p>
1935 </dd>
1936 <dt class="hdlist1">
1937 <tt>&lt;&lt; &gt;&gt; &lt;&lt;&lt; &gt;&gt;&gt;</tt>
1938 </dt>
1939 <dd>
1941 Left and right shift, left and right rotate. Valid for integer operands only.
1942 </p>
1943 </dd>
1944 <dt class="hdlist1">
1945 <tt>&lt; &gt; &lt;= &gt;=</tt>
1946 </dt>
1947 <dd>
1949 Boolean less, greater, less than or equal, and greater than or equal.
1950 Each operator produces 1 if the condition is true, 0 otherwise.
1951 These operators may be applied to strings as well as numeric operands,
1952 in which case string comparison is used.
1953 </p>
1954 </dd>
1955 <dt class="hdlist1">
1956 <tt>== !=</tt>
1957 </dt>
1958 <dd>
1960 Boolean equal and not equal. Each operator produces a zero/one result.
1961 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
1962 if possible, then floating point types, and finally strings will be compared.
1963 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
1964 </p>
1965 </dd>
1966 <dt class="hdlist1">
1967 <tt>eq ne</tt>
1968 </dt>
1969 <dd>
1971 String equal and not equal. Uses the string value directly without
1972 attempting to convert to a number first.
1973 </p>
1974 </dd>
1975 <dt class="hdlist1">
1976 <tt>in ni</tt>
1977 </dt>
1978 <dd>
1980 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
1981 is contained in the right operand (as a list), or 0 otherwise. The result for
1982 <tt>{$a ni $list}</tt> is equivalent to <tt>{!($a in $list)}</tt>.
1983 </p>
1984 </dd>
1985 <dt class="hdlist1">
1986 <tt>&amp;</tt>
1987 </dt>
1988 <dd>
1990 Bit-wise AND. Valid for integer operands only.
1991 </p>
1992 </dd>
1993 <dt class="hdlist1">
1994 <tt>|</tt>
1995 </dt>
1996 <dd>
1998 Bit-wise OR. Valid for integer operands only.
1999 </p>
2000 </dd>
2001 <dt class="hdlist1">
2002 <tt>^</tt>
2003 </dt>
2004 <dd>
2006 Bit-wise exclusive OR. Valid for integer operands only.
2007 </p>
2008 </dd>
2009 <dt class="hdlist1">
2010 <tt>&amp;&amp;</tt>
2011 </dt>
2012 <dd>
2014 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
2015 Valid for numeric operands only (integers or floating-point).
2016 </p>
2017 </dd>
2018 <dt class="hdlist1">
2019 <tt>||</tt>
2020 </dt>
2021 <dd>
2023 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
2024 Valid for numeric operands only (integers or floating-point).
2025 </p>
2026 </dd>
2027 <dt class="hdlist1">
2028 <tt>x ? y : z</tt>
2029 </dt>
2030 <dd>
2032 If-then-else, as in C. If <tt><em>x</em></tt>
2033 evaluates to non-zero, then the result is the value of <tt><em>y</em></tt>.
2034 Otherwise the result is the value of <tt><em>z</em></tt>.
2035 The <tt><em>x</em></tt> operand must have a numeric value, while <tt><em>y</em></tt> and <tt><em>z</em></tt> can
2036 be of any type.
2037 </p>
2038 </dd>
2039 </dl></div>
2040 <div class="paragraph"><p>See the C manual for more details on the results
2041 produced by each operator.
2042 All of the binary operators group left-to-right within the same
2043 precedence level. For example, the expression</p></div>
2044 <div class="literalblock">
2045 <div class="content">
2046 <pre><tt>4*2 &lt; 7</tt></pre>
2047 </div></div>
2048 <div class="paragraph"><p>evaluates to 0.</p></div>
2049 <div class="paragraph"><p>The <tt>&amp;&amp;</tt>, <tt>||</tt>, and <tt>?:</tt> operators have <em>lazy evaluation</em>, just as
2050 in C, which means that operands are not evaluated if they are not
2051 needed to determine the outcome. For example, in</p></div>
2052 <div class="literalblock">
2053 <div class="content">
2054 <pre><tt>$v ? [a] : [b]</tt></pre>
2055 </div></div>
2056 <div class="paragraph"><p>only one of <tt>[a]</tt> or <tt>[b]</tt> will actually be evaluated,
2057 depending on the value of <tt>$v</tt>.</p></div>
2058 <div class="paragraph"><p>All internal computations involving integers are done with the C
2059 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
2060 computations involving floating-point are done with the C type
2061 <em>double</em>.</p></div>
2062 <div class="paragraph"><p>When converting a string to floating-point, exponent overflow is
2063 detected and results in a Tcl error.
2064 For conversion to integer from string, detection of overflow depends
2065 on the behaviour of some routines in the local C library, so it should
2066 be regarded as unreliable.
2067 In any case, overflow and underflow are generally not detected
2068 reliably for intermediate results.</p></div>
2069 <div class="paragraph"><p>Conversion among internal representations for integer, floating-point,
2070 and string operands is done automatically as needed.
2071 For arithmetic computations, integers are used until some
2072 floating-point number is introduced, after which floating-point is used.
2073 For example,</p></div>
2074 <div class="literalblock">
2075 <div class="content">
2076 <pre><tt>5 / 4</tt></pre>
2077 </div></div>
2078 <div class="paragraph"><p>yields the result 1, while</p></div>
2079 <div class="literalblock">
2080 <div class="content">
2081 <pre><tt>5 / 4.0
2082 5 / ( [string length "abcd"] + 0.0 )</tt></pre>
2083 </div></div>
2084 <div class="paragraph"><p>both yield the result 1.25.</p></div>
2085 <div class="paragraph"><p>String values may be used as operands of the comparison operators,
2086 although the expression evaluator tries to do comparisons as integer
2087 or floating-point when it can.
2088 If one of the operands of a comparison is a string and the other
2089 has a numeric value, the numeric operand is converted back to
2090 a string using the C <em>sprintf</em> format specifier
2091 <em>%d</em> for integers and <em>%g</em> for floating-point values.
2092 For example, the expressions</p></div>
2093 <div class="literalblock">
2094 <div class="content">
2095 <pre><tt>"0x03" &gt; "2"
2096 "0y" &lt; "0x12"</tt></pre>
2097 </div></div>
2098 <div class="paragraph"><p>both evaluate to 1. The first comparison is done using integer
2099 comparison, and the second is done using string comparison after
2100 the second operand is converted to the string <em>18</em>.</p></div>
2101 <div class="paragraph"><p>In general it is safest to enclose an expression in braces when
2102 entering it in a command: otherwise, if the expression contains
2103 any white space then the Tcl interpreter will split it
2104 among several arguments. For example, the command</p></div>
2105 <div class="literalblock">
2106 <div class="content">
2107 <pre><tt>expr $a + $b</tt></pre>
2108 </div></div>
2109 <div class="paragraph"><p>results in three arguments being passed to <a href="#_expr"><strong><tt>expr</tt></strong></a>: <tt>$a</tt>,
2110 <tt>\</tt>+, and <tt>$b</tt>. In addition, if the expression isn&#8217;t in braces
2111 then the Tcl interpreter will perform variable and command substitution
2112 immediately (it will happen in the command parser rather than in
2113 the expression parser). In many cases the expression is being
2114 passed to a command that will evaluate the expression later (or
2115 even many times if, for example, the expression is to be used to
2116 decide when to exit a loop). Usually the desired goal is to re-do
2117 the variable or command substitutions each time the expression is
2118 evaluated, rather than once and for all at the beginning. For example,
2119 the command</p></div>
2120 <div class="literalblock">
2121 <div class="content">
2122 <pre><tt>for {set i 1} $i&lt;=10 {incr i} {...} +** WRONG **+</tt></pre>
2123 </div></div>
2124 <div class="paragraph"><p>is probably intended to iterate over all values of <tt>i</tt> from 1 to 10.
2125 After each iteration of the body of the loop, <a href="#_for"><strong><tt>for</tt></strong></a> will pass
2126 its second argument to the expression evaluator to see whether or not
2127 to continue processing. Unfortunately, in this case the value of <tt>i</tt>
2128 in the second argument will be substituted once and for all when the
2129 <a href="#_for"><strong><tt>for</tt></strong></a> command is parsed. If <tt>i</tt> was 0 before the <a href="#_for"><strong><tt>for</tt></strong></a>
2130 command was invoked then the second argument of <a href="#_for"><strong><tt>for</tt></strong></a> will be <tt>0&lt;=10</tt>
2131 which will always evaluate to 1, even though <tt>i</tt> eventually
2132 becomes greater than 10. In the above case the loop will never
2133 terminate. Instead, the expression should be placed in braces:</p></div>
2134 <div class="literalblock">
2135 <div class="content">
2136 <pre><tt>for {set i 1} {$i&lt;=10} {incr i} {...} +** RIGHT **+</tt></pre>
2137 </div></div>
2138 <div class="paragraph"><p>This causes the substitution of <em>i</em>
2139 to be delayed; it will be re-done each time the expression is
2140 evaluated, which is the desired result.</p></div>
2141 </div>
2142 </div>
2143 <div class="sect1">
2144 <h2 id="_lists">LISTS</h2>
2145 <div class="sectionbody">
2146 <div class="paragraph"><p>The third major way that strings are interpreted in Tcl is as lists.
2147 A list is just a string with a list-like structure
2148 consisting of fields separated by white space. For example, the
2149 string</p></div>
2150 <div class="literalblock">
2151 <div class="content">
2152 <pre><tt>Al Sue Anne John</tt></pre>
2153 </div></div>
2154 <div class="paragraph"><p>is a list with four elements or fields.
2155 Lists have the same basic structure as command strings, except
2156 that a newline character in a list is treated as a field separator
2157 just like space or tab. Conventions for braces and quotes
2158 and backslashes are the same for lists as for commands. For example,
2159 the string</p></div>
2160 <div class="literalblock">
2161 <div class="content">
2162 <pre><tt>a b\ c {d e {f g h}}</tt></pre>
2163 </div></div>
2164 <div class="paragraph"><p>is a list with three elements: <tt>a</tt>, <tt>b c</tt>, and <tt>d e {f g h}</tt>.</p></div>
2165 <div class="paragraph"><p>Whenever an element is extracted from a list, the same rules about
2166 braces and quotes and backslashes are applied as for commands. Thus in
2167 the example above when the third element is extracted from the list,
2168 the result is</p></div>
2169 <div class="literalblock">
2170 <div class="content">
2171 <pre><tt>d e {f g h}</tt></pre>
2172 </div></div>
2173 <div class="paragraph"><p>(when the field was extracted, all that happened was to strip off
2174 the outermost layer of braces). Command substitution and
2175 variable substitution are never
2176 made on a list (at least, not by the list-processing commands; the
2177 list can always be passed to the Tcl interpreter for evaluation).</p></div>
2178 <div class="paragraph"><p>The Tcl commands <a href="#_concat"><strong><tt>concat</tt></strong></a>, <a href="#_foreach"><strong><tt>foreach</tt></strong></a>, <a href="#_lappend"><strong><tt>lappend</tt></strong></a>, <a href="#_lindex"><strong><tt>lindex</tt></strong></a>, <a href="#_linsert"><strong><tt>linsert</tt></strong></a>,
2179 <a href="#_list"><strong><tt>list</tt></strong></a>, <a href="#_llength"><strong><tt>llength</tt></strong></a>, <a href="#_lrange"><strong><tt>lrange</tt></strong></a>, <a href="#_lreplace"><strong><tt>lreplace</tt></strong></a>, <a href="#_lsearch"><strong><tt>lsearch</tt></strong></a>, and <a href="#_lsort"><strong><tt>lsort</tt></strong></a> allow
2180 you to build lists, extract elements from them, search them, and perform
2181 other list-related functions.</p></div>
2182 <div class="paragraph"><p>Advanced list commands include <a href="#_lrepeat"><strong><tt>lrepeat</tt></strong></a>, <a href="#_lreverse"><strong><tt>lreverse</tt></strong></a>, <a href="#_lmap"><strong><tt>lmap</tt></strong></a>, <a href="#_lassign"><strong><tt>lassign</tt></strong></a>, <a href="#_lset"><strong><tt>lset</tt></strong></a>.</p></div>
2183 </div>
2184 </div>
2185 <div class="sect1">
2186 <h2 id="_list_expansion">LIST EXPANSION</h2>
2187 <div class="sectionbody">
2188 <div class="paragraph"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
2189 arguments. Support for this feature is also available in Jim.</p></div>
2190 <div class="paragraph"><p>Consider the following attempt to exec a list:</p></div>
2191 <div class="literalblock">
2192 <div class="content">
2193 <pre><tt>set cmd {ls -l}
2194 exec $cmd</tt></pre>
2195 </div></div>
2196 <div class="paragraph"><p>This will attempt to exec the a command named "ls -l", which will clearly not
2197 work. Typically eval and concat are required to solve this problem, however
2198 it can be solved much more easily with <tt>{*}</tt>.</p></div>
2199 <div class="literalblock">
2200 <div class="content">
2201 <pre><tt>exec {*}$cmd</tt></pre>
2202 </div></div>
2203 <div class="paragraph"><p>This will expand the following argument into individual elements and then evaluate
2204 the resulting command.</p></div>
2205 <div class="paragraph"><p>Note that the official Tcl syntax is <tt>{*}</tt>, however <tt>{expand}</tt> is retained
2206 for backward compatibility with experimental versions of this feature.</p></div>
2207 </div>
2208 </div>
2209 <div class="sect1">
2210 <h2 id="_regular_expressions">REGULAR EXPRESSIONS</h2>
2211 <div class="sectionbody">
2212 <div class="paragraph"><p>Tcl provides two commands that support string matching using regular
2213 expressions, <a href="#_regexp"><strong><tt>regexp</tt></strong></a> and <a href="#_regsub"><strong><tt>regsub</tt></strong></a>, as well as <a href="#_switch"><strong><tt>switch</tt></strong></a> <tt>-regexp</tt> and
2214 <a href="#_lsearch"><strong><tt>lsearch</tt></strong></a> <tt>-regexp</tt>.</p></div>
2215 <div class="paragraph"><p>Regular expressions may be implemented one of two ways. Either using the system&#8217;s C library
2216 POSIX regular expression support, or using the built-in regular expression engine.
2217 The differences between these are described below.</p></div>
2218 <div class="paragraph"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<tt>ARE</tt>).</p></div>
2219 <div class="sect2">
2220 <h3 id="_posix_regular_expressions">POSIX Regular Expressions</h3>
2221 <div class="paragraph"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
2222 this support will be used by default. The type of regular expressions supported are
2223 Extended Regular Expressions (<tt>ERE</tt>) rather than Basic Regular Expressions (<tt>BRE</tt>).
2224 See REG_EXTENDED in the documentation.</p></div>
2225 <div class="paragraph"><p>Using the system-supported POSIX regular expressions will typically
2226 make for the smallest code size, but some features such as UTF-8
2227 and <tt>\w</tt>, <tt>\d</tt>, <tt>\s</tt> are not supported.</p></div>
2228 <div class="paragraph"><p>See regex(3) and regex(7) for full details.</p></div>
2229 </div>
2230 <div class="sect2">
2231 <h3 id="_jim_built_in_regular_expressions">Jim built-in Regular Expressions</h3>
2232 <div class="paragraph"><p>The Jim built-in regulare expression engine may be selected with <tt>./configure --with-jim-regexp</tt>
2233 or it will be selected automatically if UTF-8 support is enabled.</p></div>
2234 <div class="paragraph"><p>This engine supports UTF-8 as well as some <tt>ARE</tt> features. The differences with both Tcl 7.x/8.x
2235 and POSIX are highlighted below.</p></div>
2236 <div class="olist arabic"><ol class="arabic">
2237 <li>
2239 UTF-8 strings and patterns are both supported
2240 </p>
2241 </li>
2242 <li>
2244 Supported character classes: <tt>[:alnum:]</tt>, <tt>[:digit:]</tt> and <tt>[:space:]</tt>
2245 </p>
2246 </li>
2247 <li>
2249 Supported shorthand character classes: <tt>\w = +[:alnum:]</tt>, <tt>\d</tt> = <tt>[:digit:],</tt> <tt>\s</tt> = <tt>[:space:]</tt>
2250 </p>
2251 </li>
2252 <li>
2254 Character classes apply to ASCII characters only
2255 </p>
2256 </li>
2257 <li>
2259 Supported constraint escapes: <tt>\m</tt> = <tt>\&lt;</tt> = start of word, <tt>\M</tt> = <tt>\&gt;</tt> = end of word
2260 </p>
2261 </li>
2262 <li>
2264 Backslash escapes may be used within regular expressions, such as <tt>\n</tt> = newline, <tt>\uNNNN</tt> = unicode
2265 </p>
2266 </li>
2267 <li>
2269 No support for the <tt>?</tt> non-greedy quantifier. e.g. <tt>*?</tt>
2270 </p>
2271 </li>
2272 </ol></div>
2273 </div>
2274 </div>
2275 </div>
2276 <div class="sect1">
2277 <h2 id="_command_results">COMMAND RESULTS</h2>
2278 <div class="sectionbody">
2279 <div class="paragraph"><p>Each command produces two results: a code and a string. The
2280 code indicates whether the command completed successfully or not,
2281 and the string gives additional information. The valid codes are
2282 defined in jim.h, and are:</p></div>
2283 <div class="dlist"><dl>
2284 <dt class="hdlist1">
2285 <tt>JIM_OK(0)</tt>
2286 </dt>
2287 <dd>
2289 This is the normal return code, and indicates that the command completed
2290 successfully. The string gives the command&#8217;s return value.
2291 </p>
2292 </dd>
2293 <dt class="hdlist1">
2294 <tt>JIM_ERR(1)</tt>
2295 </dt>
2296 <dd>
2298 Indicates that an error occurred; the string gives a message describing
2299 the error.
2300 </p>
2301 </dd>
2302 <dt class="hdlist1">
2303 <tt>JIM_RETURN(2)</tt>
2304 </dt>
2305 <dd>
2307 Indicates that the <a href="#_return"><strong><tt>return</tt></strong></a> command has been invoked, and that the
2308 current procedure (or top-level command or <a href="#_source"><strong><tt>source</tt></strong></a> command)
2309 should return immediately. The
2310 string gives the return value for the procedure or command.
2311 </p>
2312 </dd>
2313 <dt class="hdlist1">
2314 <tt>JIM_BREAK(3)</tt>
2315 </dt>
2316 <dd>
2318 Indicates that the <a href="#_break"><strong><tt>break</tt></strong></a> command has been invoked, so the
2319 innermost loop should abort immediately. The string should always
2320 be empty.
2321 </p>
2322 </dd>
2323 <dt class="hdlist1">
2324 <tt>JIM_CONTINUE(4)</tt>
2325 </dt>
2326 <dd>
2328 Indicates that the <a href="#_continue"><strong><tt>continue</tt></strong></a> command has been invoked, so the
2329 innermost loop should go on to the next iteration. The string
2330 should always be empty.
2331 </p>
2332 </dd>
2333 <dt class="hdlist1">
2334 <tt>JIM_SIGNAL(5)</tt>
2335 </dt>
2336 <dd>
2338 Indicates that a signal was caught while executing a commands.
2339 The string contains the name of the signal caught.
2340 See the <a href="#_signal"><strong><tt>signal</tt></strong></a> and <a href="#_catch"><strong><tt>catch</tt></strong></a> commands.
2341 </p>
2342 </dd>
2343 <dt class="hdlist1">
2344 <tt>JIM_EXIT(6)</tt>
2345 </dt>
2346 <dd>
2348 Indicates that the command called the <a href="#_exit"><strong><tt>exit</tt></strong></a> command.
2349 The string contains the exit code.
2350 </p>
2351 </dd>
2352 </dl></div>
2353 <div class="paragraph"><p>Tcl programmers do not normally need to think about return codes,
2354 since <tt>JIM_OK</tt> is almost always returned. If anything else is returned
2355 by a command, then the Tcl interpreter immediately stops processing
2356 commands and returns to its caller. If there are several nested
2357 invocations of the Tcl interpreter in progress, then each nested
2358 command will usually return the error to its caller, until eventually
2359 the error is reported to the top-level application code. The
2360 application will then display the error message for the user.</p></div>
2361 <div class="paragraph"><p>In a few cases, some commands will handle certain <a href="#_error"><strong><tt>error</tt></strong></a> conditions
2362 themselves and not return them upwards. For example, the <a href="#_for"><strong><tt>for</tt></strong></a>
2363 command checks for the <tt>JIM_BREAK</tt> code; if it occurs, then <a href="#_for"><strong><tt>for</tt></strong></a>
2364 stops executing the body of the loop and returns <tt>JIM_OK</tt> to its
2365 caller. The <a href="#_for"><strong><tt>for</tt></strong></a> command also handles <tt>JIM_CONTINUE</tt> codes and the
2366 procedure interpreter handles <tt>JIM_RETURN</tt> codes. The <a href="#_catch"><strong><tt>catch</tt></strong></a>
2367 command allows Tcl programs to catch errors and handle them without
2368 aborting command interpretation any further.</p></div>
2369 <div class="paragraph"><p>The <a href="#_info"><strong><tt>info</tt></strong></a> <tt>returncodes</tt> command may be used to programmatically map between
2370 return codes and names.</p></div>
2371 </div>
2372 </div>
2373 <div class="sect1">
2374 <h2 id="_procedures">PROCEDURES</h2>
2375 <div class="sectionbody">
2376 <div class="paragraph"><p>Tcl allows you to extend the command interface by defining
2377 procedures. A Tcl procedure can be invoked just like any other Tcl
2378 command (it has a name and it receives one or more arguments).
2379 The only difference is that its body isn&#8217;t a piece of C code linked
2380 into the program; it is a string containing one or more other
2381 Tcl commands.</p></div>
2382 <div class="paragraph"><p>The <a href="#_proc"><strong><tt>proc</tt></strong></a> command is used to create a new Tcl command procedure:</p></div>
2383 <div class="paragraph"><p><tt><strong>proc</strong> <em>name arglist ?statics? body</em></tt></p></div>
2384 <div class="paragraph"><p>The new command is named <tt><em>name</em></tt>, and it replaces any existing command
2385 there may have been by that name. Whenever the new command is
2386 invoked, the contents of <tt><em>body</em></tt> will be executed by the Tcl
2387 interpreter.</p></div>
2388 <div class="paragraph"><p><tt><em>arglist</em></tt> specifies the formal arguments to the procedure.
2389 It consists of a list, possibly empty, of the following
2390 argument specifiers:</p></div>
2391 <div class="dlist"><dl>
2392 <dt class="hdlist1">
2393 <tt>name</tt>
2394 </dt>
2395 <dd>
2397 Required Argument - A simple argument name.
2398 </p>
2399 </dd>
2400 <dt class="hdlist1">
2401 <tt>name default</tt>
2402 </dt>
2403 <dd>
2405 Optional Argument - A two-element list consisting of the
2406 argument name, followed by the default value, which will
2407 be used if the corresponding argument is not supplied.
2408 </p>
2409 </dd>
2410 <dt class="hdlist1">
2411 <tt>&amp;name</tt>
2412 </dt>
2413 <dd>
2415 Reference Argument - The caller is expected to pass the name of
2416 an existing variable. An implicit <a href="#_upvar"><strong><tt>upvar</tt></strong></a> <tt>1 'origname' 'name'</tt> is done
2417 to make the variable available in the proc scope.
2418 </p>
2419 </dd>
2420 <dt class="hdlist1">
2421 <tt><strong>args</strong></tt>
2422 </dt>
2423 <dd>
2425 Variable Argument - The special name <tt><em>args</em></tt>, which is
2426 assigned all remaining arguments (including none) as a list. The
2427 variable argument may only be specified once. Note that
2428 the syntax <tt>args newname</tt> may be used to retain the special
2429 behaviour of <tt><em>args</em></tt> with a different local name. In this case,
2430 the variable is named <tt><em>newname</em></tt> rather than <tt><em>args</em></tt>.
2431 </p>
2432 </dd>
2433 </dl></div>
2434 <div class="paragraph"><p>When the command is invoked, a local variable will be created for each of
2435 the formal arguments to the procedure; its value will be the value
2436 of corresponding argument in the invoking command or the argument&#8217;s
2437 default value.</p></div>
2438 <div class="paragraph"><p>Arguments with default values need not be specified in a procedure
2439 invocation. However, there must be enough actual arguments for all
2440 required arguments, and there must not be any extra actual arguments
2441 (unless the Variable Argument is specified).</p></div>
2442 <div class="paragraph"><p>Actual arguments are assigned to formal arguments as in left-to-right
2443 order with the following precedence.</p></div>
2444 <div class="olist arabic"><ol class="arabic">
2445 <li>
2447 Required Arguments (including Reference Arguments)
2448 </p>
2449 </li>
2450 <li>
2452 Optional Arguments
2453 </p>
2454 </li>
2455 <li>
2457 Variable Argument
2458 </p>
2459 </li>
2460 </ol></div>
2461 <div class="paragraph"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2462 <div class="literalblock">
2463 <div class="content">
2464 <pre><tt>proc p {{a A} args b {c C} d} {...}</tt></pre>
2465 </div></div>
2466 <div class="paragraph"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2467 The following table shows how various numbers of arguments are assigned.
2468 Values marked as <tt>-</tt> are assigned the default value.</p></div>
2469 <div class="tableblock">
2470 <table rules="all"
2471 width="40%"
2472 frame="hsides"
2473 cellspacing="0" cellpadding="4">
2474 <col width="16%" />
2475 <col width="16%" />
2476 <col width="16%" />
2477 <col width="16%" />
2478 <col width="16%" />
2479 <col width="16%" />
2480 <thead>
2481 <tr>
2482 <th align="left" valign="top">Number of arguments</th>
2483 <th align="left" valign="top">a</th>
2484 <th align="left" valign="top">args</th>
2485 <th align="left" valign="top">b</th>
2486 <th align="left" valign="top">c</th>
2487 <th align="left" valign="top">d</th>
2488 </tr>
2489 </thead>
2490 <tbody>
2491 <tr>
2492 <td align="left" valign="top"><p class="table">2</p></td>
2493 <td align="left" valign="top"><p class="table">-</p></td>
2494 <td align="left" valign="top"><p class="table">-</p></td>
2495 <td align="left" valign="top"><p class="table">1</p></td>
2496 <td align="left" valign="top"><p class="table">-</p></td>
2497 <td align="left" valign="top"><p class="table">2</p></td>
2498 </tr>
2499 <tr>
2500 <td align="left" valign="top"><p class="table">3</p></td>
2501 <td align="left" valign="top"><p class="table">1</p></td>
2502 <td align="left" valign="top"><p class="table">-</p></td>
2503 <td align="left" valign="top"><p class="table">2</p></td>
2504 <td align="left" valign="top"><p class="table">-</p></td>
2505 <td align="left" valign="top"><p class="table">3</p></td>
2506 </tr>
2507 <tr>
2508 <td align="left" valign="top"><p class="table">4</p></td>
2509 <td align="left" valign="top"><p class="table">1</p></td>
2510 <td align="left" valign="top"><p class="table">-</p></td>
2511 <td align="left" valign="top"><p class="table">2</p></td>
2512 <td align="left" valign="top"><p class="table">3</p></td>
2513 <td align="left" valign="top"><p class="table">4</p></td>
2514 </tr>
2515 <tr>
2516 <td align="left" valign="top"><p class="table">5</p></td>
2517 <td align="left" valign="top"><p class="table">1</p></td>
2518 <td align="left" valign="top"><p class="table">2</p></td>
2519 <td align="left" valign="top"><p class="table">3</p></td>
2520 <td align="left" valign="top"><p class="table">4</p></td>
2521 <td align="left" valign="top"><p class="table">5</p></td>
2522 </tr>
2523 <tr>
2524 <td align="left" valign="top"><p class="table">6</p></td>
2525 <td align="left" valign="top"><p class="table">1</p></td>
2526 <td align="left" valign="top"><p class="table">2,3</p></td>
2527 <td align="left" valign="top"><p class="table">4</p></td>
2528 <td align="left" valign="top"><p class="table">5</p></td>
2529 <td align="left" valign="top"><p class="table">6</p></td>
2530 </tr>
2531 </tbody>
2532 </table>
2533 </div>
2534 <div class="paragraph"><p>When <tt><em>body</em></tt> is being executed, variable names normally refer to local
2535 variables, which are created automatically when referenced and deleted
2536 when the procedure returns. One local variable is automatically created
2537 for each of the procedure&#8217;s arguments. Global variables can be
2538 accessed by invoking the <a href="#_global"><strong><tt>global</tt></strong></a> command or via the <tt>::</tt> prefix.</p></div>
2539 <div class="sect2">
2540 <h3 id="_new_in_jim">New in Jim</h3>
2541 <div class="paragraph"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2542 These variables scoped to the procedure and initialised at procedure definition.
2543 Either from the static variable definition, or from the enclosing scope.</p></div>
2544 <div class="paragraph"><p>Consider the following example:</p></div>
2545 <div class="literalblock">
2546 <div class="content">
2547 <pre><tt>jim&gt; set a 1
2548 jim&gt; proc a {} {a {b 2}} {
2549 set c 1
2550 puts "$a $b $c"
2551 incr a
2552 incr b
2553 incr c
2555 jim&gt; a
2556 1 2 1
2557 jim&gt; a
2558 2 3 1</tt></pre>
2559 </div></div>
2560 <div class="paragraph"><p>The static variable <tt><em>a</em></tt> has no initialiser, so it is initialised from
2561 the enclosing scope with the value 1. (Note that it is an error if there
2562 is no variable with the same name in the enclosing scope). However <tt><em>b</em></tt>
2563 has an initialiser, so it is initialised to 2.</p></div>
2564 <div class="paragraph"><p>Unlike a local variable, the value of a static variable is retained across
2565 invocations of the procedure.</p></div>
2566 <div class="paragraph"><p>See the <a href="#_proc"><strong><tt>proc</tt></strong></a> command for information on
2567 how to define procedures and what happens when they are invoked.</p></div>
2568 </div>
2569 </div>
2570 </div>
2571 <div class="sect1">
2572 <h2 id="_variables_scalars_and_arrays">VARIABLES - SCALARS AND ARRAYS</h2>
2573 <div class="sectionbody">
2574 <div class="paragraph"><p>Tcl allows the definition of variables and the use of their values
2575 either through <em>$</em>-style variable substitution, the <a href="#_set"><strong><tt>set</tt></strong></a>
2576 command, or a few other mechanisms.</p></div>
2577 <div class="paragraph"><p>Variables need not be declared: a new variable will automatically
2578 be created each time a new variable name is used.</p></div>
2579 <div class="paragraph"><p>Tcl supports two types of variables: scalars and arrays.
2580 A scalar variable has a single value, whereas an array variable
2581 can have any number of elements, each with a name (called
2582 its <em>index</em>) and a value.</p></div>
2583 <div class="paragraph"><p>Array indexes may be arbitrary strings; they need not be numeric.
2584 Parentheses are used refer to array elements in Tcl commands.
2585 For example, the command</p></div>
2586 <div class="literalblock">
2587 <div class="content">
2588 <pre><tt>set x(first) 44</tt></pre>
2589 </div></div>
2590 <div class="paragraph"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2591 so that its new value is <em>44</em>.</p></div>
2592 <div class="paragraph"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2593 that contain multiple concatenated values.
2594 For example, the commands</p></div>
2595 <div class="literalblock">
2596 <div class="content">
2597 <pre><tt>set a(2,3) 1
2598 set a(3,6) 2</tt></pre>
2599 </div></div>
2600 <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>
2601 <div class="paragraph"><p>In general, array elements may be used anywhere in Tcl that scalar
2602 variables may be used.</p></div>
2603 <div class="paragraph"><p>If an array is defined with a particular name, then there may
2604 not be a scalar variable with the same name.</p></div>
2605 <div class="paragraph"><p>Similarly, if there is a scalar variable with a particular
2606 name then it is not possible to make array references to the
2607 variable.</p></div>
2608 <div class="paragraph"><p>To convert a scalar variable to an array or vice versa, remove
2609 the existing variable with the <a href="#_unset"><strong><tt>unset</tt></strong></a> command.</p></div>
2610 <div class="paragraph"><p>The <a href="#_array"><strong><tt>array</tt></strong></a> command provides several features for dealing
2611 with arrays, such as querying the names of all the elements of
2612 the array and converting between an array and a list.</p></div>
2613 <div class="paragraph"><p>Variables may be either global or local. If a variable
2614 name is used when a procedure isn&#8217;t being executed, then it
2615 automatically refers to a global variable. Variable names used
2616 within a procedure normally refer to local variables associated with that
2617 invocation of the procedure. Local variables are deleted whenever
2618 a procedure exits. Either <a href="#_global"><strong><tt>global</tt></strong></a> command may be used to request
2619 that a name refer to a global variable for the duration of the current
2620 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2621 may be explicitly scoped with the <tt>::</tt> prefix. For example</p></div>
2622 <div class="literalblock">
2623 <div class="content">
2624 <pre><tt>set a 1
2625 set b 2
2626 proc p {} {
2627 set c 3
2628 global a</tt></pre>
2629 </div></div>
2630 <div class="literalblock">
2631 <div class="content">
2632 <pre><tt> puts "$a $::b $c"
2634 p</tt></pre>
2635 </div></div>
2636 <div class="paragraph"><p>will output:</p></div>
2637 <div class="literalblock">
2638 <div class="content">
2639 <pre><tt>1 2 3</tt></pre>
2640 </div></div>
2641 </div>
2642 </div>
2643 <div class="sect1">
2644 <h2 id="_arrays_as_lists_in_jim">ARRAYS AS LISTS IN JIM</h2>
2645 <div class="sectionbody">
2646 <div class="paragraph"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2647 number of elements) and an array value. This is similar to the way Tcl
2648 can convert between a string and a list.</p></div>
2649 <div class="paragraph"><p>For example:</p></div>
2650 <div class="literalblock">
2651 <div class="content">
2652 <pre><tt>set a {1 one 2 two}
2653 puts $a(2)</tt></pre>
2654 </div></div>
2655 <div class="paragraph"><p>will output:</p></div>
2656 <div class="literalblock">
2657 <div class="content">
2658 <pre><tt>two</tt></pre>
2659 </div></div>
2660 <div class="paragraph"><p>Thus <a href="#_array"><strong><tt>array</tt></strong></a> <tt>set</tt> is equivalent to <a href="#_set"><strong><tt>set</tt></strong></a> when the variable does not
2661 exist or is empty.</p></div>
2662 <div class="paragraph"><p>The reverse is also true where an array will be converted into
2663 a list.</p></div>
2664 <div class="literalblock">
2665 <div class="content">
2666 <pre><tt>set a(1) one; set a(2) two
2667 puts $a</tt></pre>
2668 </div></div>
2669 <div class="paragraph"><p>will output:</p></div>
2670 <div class="literalblock">
2671 <div class="content">
2672 <pre><tt>1 one 2 two</tt></pre>
2673 </div></div>
2674 </div>
2675 </div>
2676 <div class="sect1">
2677 <h2 id="_dictionary_values">DICTIONARY VALUES</h2>
2678 <div class="sectionbody">
2679 <div class="paragraph"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2680 of this command. Dictionaries provide efficient access to key-value
2681 pairs, just like arrays, but dictionaries are pure values. This
2682 means that you can pass them to a procedure just as a list or a
2683 string. Tcl dictionaries are therefore much more like Tcl lists,
2684 except that they represent a mapping from keys to values, rather
2685 than an ordered sequence.</p></div>
2686 <div class="paragraph"><p>You can nest dictionaries, so that the value for a particular key
2687 consists of another dictionary. That way you can elegantly build
2688 complicated data structures, such as hierarchical databases. You
2689 can also combine dictionaries with other Tcl data structures. For
2690 instance, you can build a list of dictionaries that themselves
2691 contain lists.</p></div>
2692 <div class="paragraph"><p>Dictionaries are values that contain an efficient, order-preserving
2693 mapping from arbitrary keys to arbitrary values. Each key in the
2694 dictionary maps to a single value. They have a textual format that
2695 is exactly that of any list with an even number of elements, with
2696 each mapping in the dictionary being represented as two items in
2697 the list. When a command takes a dictionary and produces a new
2698 dictionary based on it (either returning it or writing it back into
2699 the variable that the starting dictionary was read from) the new
2700 dictionary will have the same order of keys, modulo any deleted
2701 keys and with new keys added on to the end. When a string is
2702 interpreted as a dictionary and it would otherwise have duplicate
2703 keys, only the last value for a particular key is used; the others
2704 are ignored, meaning that, "apple banana" and "apple carrot apple
2705 banana" are equivalent dictionaries (with different string
2706 representations).</p></div>
2707 <div class="paragraph"><p>Note that in Jim, arrays are implemented as dictionaries.
2708 Thus automatic conversion between lists and dictionaries applies
2709 as it does for arrays.</p></div>
2710 <div class="literalblock">
2711 <div class="content">
2712 <pre><tt>jim&gt; dict set a 1 one
2713 1 one
2714 jim&gt; dict set a 2 two
2715 1 one 2 two
2716 jim&gt; puts $a
2717 1 one 2 two
2718 jim&gt; puts $a(2)
2720 jim&gt; dict set a 3 T three
2721 1 one 2 two 3 {T three}</tt></pre>
2722 </div></div>
2723 <div class="paragraph"><p>See the <a href="#_dict"><strong><tt>dict</tt></strong></a> command for more details.</p></div>
2724 </div>
2725 </div>
2726 <div class="sect1">
2727 <h2 id="_garbage_collection_references_lambda">GARBAGE COLLECTION, REFERENCES, LAMBDA</h2>
2728 <div class="sectionbody">
2729 <div class="paragraph"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
2730 These are described briefly below.</p></div>
2731 <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>
2732 <div class="sect2">
2733 <h3 id="_references">References</h3>
2734 <div class="paragraph"><p>A reference can be thought of as holding a value with one level of indirection,
2735 where the value may be garbage collected when unreferenced.
2736 Consider the following example:</p></div>
2737 <div class="literalblock">
2738 <div class="content">
2739 <pre><tt>jim&gt; set r [ref "One String" test]
2740 &lt;reference.&lt;test___&gt;.00000000000000000000&gt;
2741 jim&gt; getref $r
2742 One String</tt></pre>
2743 </div></div>
2744 <div class="paragraph"><p>The operation <a href="#_ref"><strong><tt>ref</tt></strong></a> creates a references to the value specified by the
2745 first argument. (The second argument is a "type" used for documentation purposes).</p></div>
2746 <div class="paragraph"><p>The operation <a href="#_getref"><strong><tt>getref</tt></strong></a> is the dereferencing operation which retrieves the value
2747 stored in the reference.</p></div>
2748 <div class="literalblock">
2749 <div class="content">
2750 <pre><tt>jim&gt; setref $r "New String"
2751 New String
2752 jim&gt; getref $r
2753 New String</tt></pre>
2754 </div></div>
2755 <div class="paragraph"><p>The operation <a href="#_setref"><strong><tt>setref</tt></strong></a> replaces the value stored by the reference. If the old value
2756 is no longer accessible by any reference, it will eventually be automatically be garbage
2757 collected.</p></div>
2758 </div>
2759 <div class="sect2">
2760 <h3 id="_garbage_collection">Garbage Collection</h3>
2761 <div class="paragraph"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
2762 automatically as necessary.</p></div>
2763 <div class="paragraph"><p>With the introduction of references, it is possible to create values whose lifetime
2764 transcend their scope. To support this, case, the Jim system will periodically identify
2765 and discard objects which are no longer accessible by any reference.</p></div>
2766 <div class="paragraph"><p>The <a href="#_collect"><strong><tt>collect</tt></strong></a> command may be used to force garbage collection. Consider a reference created
2767 with a finalizer:</p></div>
2768 <div class="literalblock">
2769 <div class="content">
2770 <pre><tt>jim&gt; proc f {ref value} { puts "Finaliser called for $ref,$value" }
2771 jim&gt; set r [ref "One String" test f]
2772 &lt;reference.&lt;test___&gt;.00000000000
2773 jim&gt; collect
2775 jim&gt; set r ""
2776 jim&gt; collect
2777 Finaliser called for &lt;reference.&lt;test___&gt;.00000000000,One String
2778 1</tt></pre>
2779 </div></div>
2780 <div class="paragraph"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
2781 contained a reference to the value, the garbage collector discarded
2782 the value (after calling the finalizer).</p></div>
2783 <div class="paragraph"><p>The finalizer for a reference may be examined or changed with the <a href="#_finalize"><strong><tt>finalize</tt></strong></a> command</p></div>
2784 <div class="literalblock">
2785 <div class="content">
2786 <pre><tt>jim&gt; finalize $r
2788 jim&gt; finalize $r newf
2789 newf</tt></pre>
2790 </div></div>
2791 </div>
2792 <div class="sect2">
2793 <h3 id="_lambda">Lambda</h3>
2794 <div class="paragraph"><p>Jim provides a garbage collected lambda function. This is a procedure
2795 which is able to create an anonymous procedure. Consider:</p></div>
2796 <div class="literalblock">
2797 <div class="content">
2798 <pre><tt>jim&gt; set f [lambda {a} {{x 0}} { incr x $a }]
2799 jim&gt; $f 1
2801 jim&gt; $f 2
2803 jim&gt; set f ""</tt></pre>
2804 </div></div>
2805 <div class="paragraph"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
2806 which is incremented by the supplied value and the result returned.</p></div>
2807 <div class="paragraph"><p>Once the procedure name is no longer accessible, it will automatically be deleted
2808 when the garbage collector runs.</p></div>
2809 <div class="paragraph"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
2810 <div class="literalblock">
2811 <div class="content">
2812 <pre><tt>jim&gt; rename $f ""</tt></pre>
2813 </div></div>
2814 </div>
2815 </div>
2816 </div>
2817 <div class="sect1">
2818 <h2 id="_utf_8_and_unicode">UTF-8 AND UNICODE</h2>
2819 <div class="sectionbody">
2820 <div class="paragraph"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
2821 then most string-related commands become UTF-8 aware. These include,
2822 but are not limited to, <a href="#_string"><strong><tt>string</tt></strong></a> <tt>match</tt>, <a href="#_split"><strong><tt>split</tt></strong></a>, <a href="#_glob"><strong><tt>glob</tt></strong></a>, <a href="#_scan"><strong><tt>scan</tt></strong></a> and
2823 <a href="#_format"><strong><tt>format</tt></strong></a>.</p></div>
2824 <div class="paragraph"><p>UTF-8 encoding has many advantages, but one of the complications is that
2825 characters can take a variable number of bytes. Thus the addition of
2826 <a href="#_string"><strong><tt>string</tt></strong></a> <tt>bytelength</tt> which returns the number of bytes in a string,
2827 while <a href="#_string"><strong><tt>string</tt></strong></a> <tt>length</tt> returns the number of characters.</p></div>
2828 <div class="paragraph"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
2829 and <a href="#_string"><strong><tt>string</tt></strong></a> <tt>bytelength</tt> returns the same value as <a href="#_string"><strong><tt>string</tt></strong></a> <tt>length</tt>.</p></div>
2830 <div class="paragraph"><p>Note that even if UTF-8 support is not enabled, the <tt>\uNNNN</tt> syntax
2831 is still available to embed UTF-8 sequences.</p></div>
2832 <div class="sect2">
2833 <h3 id="_string_matching">String Matching</h3>
2834 <div class="paragraph"><p>Commands such as <a href="#_string"><strong><tt>string</tt></strong></a> <tt>match</tt>, <a href="#_lsearch"><strong><tt>lsearch</tt></strong></a> <tt>-glob</tt>, <a href="#_array"><strong><tt>array</tt></strong></a> <tt>names</tt> and others use string
2835 pattern matching rules. These commands support UTF-8. For example:</p></div>
2836 <div class="literalblock">
2837 <div class="content">
2838 <pre><tt>string match a\[\ua0-\ubf\]b "a\u00a3b"</tt></pre>
2839 </div></div>
2840 </div>
2841 <div class="sect2">
2842 <h3 id="_format_and_scan">format and scan</h3>
2843 <div class="paragraph"><p><tt>format %c</tt> allows a unicode codepoint to be be encoded. For example, the following will return
2844 a string with two bytes and one character. The same as <tt>\ub5</tt></p></div>
2845 <div class="literalblock">
2846 <div class="content">
2847 <pre><tt>format %c 0xb5</tt></pre>
2848 </div></div>
2849 <div class="paragraph"><p><a href="#_format"><strong><tt>format</tt></strong></a> respects widths as character widths, not byte widths. For example, the following will
2850 return a string with three characters, not three bytes.</p></div>
2851 <div class="literalblock">
2852 <div class="content">
2853 <pre><tt>format %.3s \ub5\ub6\ub7\ub8</tt></pre>
2854 </div></div>
2855 <div class="paragraph"><p>Similarly, <tt>scan &#8230; %c</tt> allows a UTF-8 to be decoded to a unicode codepoint. The following will set
2856 <tt><em>a</em></tt> to 181 (0xb5) and <tt><em>b</em></tt> to 65 (0x41).</p></div>
2857 <div class="literalblock">
2858 <div class="content">
2859 <pre><tt>scan \u00b5A %c%c a b</tt></pre>
2860 </div></div>
2861 <div class="paragraph"><p><a href="#_scan"><strong><tt>scan</tt></strong></a> <tt>%s</tt> will also accept a character class, including unicode ranges.</p></div>
2862 </div>
2863 <div class="sect2">
2864 <h3 id="_string_classes">String Classes</h3>
2865 <div class="paragraph"><p><a href="#_string"><strong><tt>string</tt></strong></a> <tt>is</tt> has <strong>not</strong> been extended to classify UTF-8 characters. Therefore, the following
2866 will return 0, even though the string may be considered to be alphabetic.</p></div>
2867 <div class="literalblock">
2868 <div class="content">
2869 <pre><tt>string is alpha \ub5Test</tt></pre>
2870 </div></div>
2871 <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>
2872 </div>
2873 <div class="sect2">
2874 <h3 id="_case_mapping_and_conversion">Case Mapping and Conversion</h3>
2875 <div class="paragraph"><p>Jim provides a simplified unicode case mapping. This means that case conversion
2876 and comparison will not increase or decrease the number of characters in a string.</p></div>
2877 <div class="paragraph"><p><a href="#_string"><strong><tt>string</tt></strong></a> <tt>toupper</tt> will convert any lowercase letters to their uppercase equivalent.
2878 Any character which is not a letter or has no uppercase equivalent is left unchanged.
2879 Similarly for <a href="#_string"><strong><tt>string</tt></strong></a> <tt>tolower</tt>.</p></div>
2880 <div class="paragraph"><p>Commands which perform case insensitive matches, such as <a href="#_string"><strong><tt>string</tt></strong></a> <tt>compare -nocase</tt>
2881 and <a href="#_lsearch"><strong><tt>lsearch</tt></strong></a> <tt>-nocase</tt> fold both strings to uppercase before comparison.</p></div>
2882 </div>
2883 <div class="sect2">
2884 <h3 id="_invalid_utf_8_sequences">Invalid UTF-8 Sequences</h3>
2885 <div class="paragraph"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
2886 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
2887 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
2888 <div class="paragraph"><p>In these situations, the offending bytes are treated as single characters. For example,
2889 the following returns 2.</p></div>
2890 <div class="literalblock">
2891 <div class="content">
2892 <pre><tt>string bytelength \xff\xff</tt></pre>
2893 </div></div>
2894 </div>
2895 <div class="sect2">
2896 <h3 id="_regular_expressions_2">Regular Expressions</h3>
2897 <div class="paragraph"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
2898 selected which supports UTF-8 strings and patterns.</p></div>
2899 <div class="paragraph"><p>See REGULAR EXPRESSIONS</p></div>
2900 </div>
2901 </div>
2902 </div>
2903 <div class="sect1">
2904 <h2 id="_built_in_commands">BUILT-IN COMMANDS</h2>
2905 <div class="sectionbody">
2906 <div class="paragraph"><p>The Tcl library provides the following built-in commands, which will
2907 be available in any application using Tcl. In addition to these
2908 built-in commands, there may be additional commands defined by each
2909 application, plus commands defined as Tcl procedures.</p></div>
2910 <div class="paragraph"><p>In the command syntax descriptions below, words in <tt><strong>boldface</strong></tt> are
2911 literals that you type verbatim to Tcl.</p></div>
2912 <div class="paragraph"><p>Words in <tt><em>italics</em></tt> are meta-symbols; they serve as names for any of
2913 a range of values that you can type.</p></div>
2914 <div class="paragraph"><p>Optional arguments or groups of arguments are indicated by enclosing them
2915 in <tt>?question-marks?</tt>.</p></div>
2916 <div class="paragraph"><p>Ellipses (<tt>...</tt>) indicate that any number of additional
2917 arguments or groups of arguments may appear, in the same format
2918 as the preceding argument(s).</p></div>
2919 <div class="sect2">
2920 <h3 id="CommandIndex">Command Index</h3>
2921 <div class="tableblock">
2922 <table rules="none"
2923 width="100%"
2924 frame="void"
2925 cellspacing="0" cellpadding="4">
2926 <col width="12%" />
2927 <col width="12%" />
2928 <col width="12%" />
2929 <col width="12%" />
2930 <col width="12%" />
2931 <col width="12%" />
2932 <col width="12%" />
2933 <col width="12%" />
2934 <tbody>
2935 <tr>
2936 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><tt>after</tt></strong></a></p></td>
2937 <td align="left" valign="top"><p class="table"><a href="#_aio"><strong><tt>aio</tt></strong></a></p></td>
2938 <td align="left" valign="top"><p class="table"><a href="#_alarm"><strong><tt>alarm</tt></strong></a></p></td>
2939 <td align="left" valign="top"><p class="table"><a href="#_alias"><strong><tt>alias</tt></strong></a></p></td>
2940 <td align="left" valign="top"><p class="table"><a href="#_append"><strong><tt>append</tt></strong></a></p></td>
2941 <td align="left" valign="top"><p class="table"><a href="#_array"><strong><tt>array</tt></strong></a></p></td>
2942 <td align="left" valign="top"><p class="table"><a href="#_binary"><strong><tt>binary</tt></strong></a></p></td>
2943 <td align="left" valign="top"><p class="table"><a href="#_break"><strong><tt>break</tt></strong></a></p></td>
2944 </tr>
2945 <tr>
2946 <td align="left" valign="top"><p class="table"><a href="#_case"><strong><tt>case</tt></strong></a></p></td>
2947 <td align="left" valign="top"><p class="table"><a href="#_catch"><strong><tt>catch</tt></strong></a></p></td>
2948 <td align="left" valign="top"><p class="table"><a href="#_cd"><strong><tt>cd</tt></strong></a></p></td>
2949 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><tt>class</tt></strong></a></p></td>
2950 <td align="left" valign="top"><p class="table"><a href="#_clock"><strong><tt>clock</tt></strong></a></p></td>
2951 <td align="left" valign="top"><p class="table"><a href="#_close"><strong><tt>close</tt></strong></a></p></td>
2952 <td align="left" valign="top"><p class="table"><a href="#_collect"><strong><tt>collect</tt></strong></a></p></td>
2953 <td align="left" valign="top"><p class="table"><a href="#_concat"><strong><tt>concat</tt></strong></a></p></td>
2954 </tr>
2955 <tr>
2956 <td align="left" valign="top"><p class="table"><a href="#_continue"><strong><tt>continue</tt></strong></a></p></td>
2957 <td align="left" valign="top"><p class="table"><a href="#_curry"><strong><tt>curry</tt></strong></a></p></td>
2958 <td align="left" valign="top"><p class="table"><a href="#_dict"><strong><tt>dict</tt></strong></a></p></td>
2959 <td align="left" valign="top"><p class="table"><a href="#_env"><strong><tt>env</tt></strong></a></p></td>
2960 <td align="left" valign="top"><p class="table"><a href="#_eof"><strong><tt>eof</tt></strong></a></p></td>
2961 <td align="left" valign="top"><p class="table"><a href="#_error"><strong><tt>error</tt></strong></a></p></td>
2962 <td align="left" valign="top"><p class="table"><a href="#_eval"><strong><tt>eval</tt></strong></a></p></td>
2963 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><tt>eventloop</tt></strong></a></p></td>
2964 </tr>
2965 <tr>
2966 <td align="left" valign="top"><p class="table"><a href="#_exec"><strong><tt>exec</tt></strong></a></p></td>
2967 <td align="left" valign="top"><p class="table"><a href="#_exists"><strong><tt>exists</tt></strong></a></p></td>
2968 <td align="left" valign="top"><p class="table"><a href="#_exit"><strong><tt>exit</tt></strong></a></p></td>
2969 <td align="left" valign="top"><p class="table"><a href="#_expr"><strong><tt>expr</tt></strong></a></p></td>
2970 <td align="left" valign="top"><p class="table"><a href="#_fconfigure"><strong><tt>fconfigure</tt></strong></a></p></td>
2971 <td align="left" valign="top"><p class="table"><a href="#_file"><strong><tt>file</tt></strong></a></p></td>
2972 <td align="left" valign="top"><p class="table"><a href="#_finalize"><strong><tt>finalize</tt></strong></a></p></td>
2973 <td align="left" valign="top"><p class="table"><a href="#_flush"><strong><tt>flush</tt></strong></a></p></td>
2974 </tr>
2975 <tr>
2976 <td align="left" valign="top"><p class="table"><a href="#_for"><strong><tt>for</tt></strong></a></p></td>
2977 <td align="left" valign="top"><p class="table"><a href="#_foreach"><strong><tt>foreach</tt></strong></a></p></td>
2978 <td align="left" valign="top"><p class="table"><a href="#_format"><strong><tt>format</tt></strong></a></p></td>
2979 <td align="left" valign="top"><p class="table"><a href="#_getref"><strong><tt>getref</tt></strong></a></p></td>
2980 <td align="left" valign="top"><p class="table"><a href="#_gets"><strong><tt>gets</tt></strong></a></p></td>
2981 <td align="left" valign="top"><p class="table"><a href="#_glob"><strong><tt>glob</tt></strong></a></p></td>
2982 <td align="left" valign="top"><p class="table"><a href="#_global"><strong><tt>global</tt></strong></a></p></td>
2983 <td align="left" valign="top"><p class="table"><a href="#_if"><strong><tt>if</tt></strong></a></p></td>
2984 </tr>
2985 <tr>
2986 <td align="left" valign="top"><p class="table"><a href="#_incr"><strong><tt>incr</tt></strong></a></p></td>
2987 <td align="left" valign="top"><p class="table"><a href="#_info"><strong><tt>info</tt></strong></a></p></td>
2988 <td align="left" valign="top"><p class="table"><a href="#_join"><strong><tt>join</tt></strong></a></p></td>
2989 <td align="left" valign="top"><p class="table"><a href="#_kill"><strong><tt>kill</tt></strong></a></p></td>
2990 <td align="left" valign="top"><p class="table"><a href="#_lambda"><strong><tt>lambda</tt></strong></a></p></td>
2991 <td align="left" valign="top"><p class="table"><a href="#_lappend"><strong><tt>lappend</tt></strong></a></p></td>
2992 <td align="left" valign="top"><p class="table"><a href="#_lassign"><strong><tt>lassign</tt></strong></a></p></td>
2993 <td align="left" valign="top"><p class="table"><a href="#_lindex"><strong><tt>lindex</tt></strong></a></p></td>
2994 </tr>
2995 <tr>
2996 <td align="left" valign="top"><p class="table"><a href="#_linsert"><strong><tt>linsert</tt></strong></a></p></td>
2997 <td align="left" valign="top"><p class="table"><a href="#_list"><strong><tt>list</tt></strong></a></p></td>
2998 <td align="left" valign="top"><p class="table"><a href="#_llength"><strong><tt>llength</tt></strong></a></p></td>
2999 <td align="left" valign="top"><p class="table"><a href="#_lmap"><strong><tt>lmap</tt></strong></a></p></td>
3000 <td align="left" valign="top"><p class="table"><a href="#_load"><strong><tt>load</tt></strong></a></p></td>
3001 <td align="left" valign="top"><p class="table"><a href="#_local"><strong><tt>local</tt></strong></a></p></td>
3002 <td align="left" valign="top"><p class="table"><a href="#_loop"><strong><tt>loop</tt></strong></a></p></td>
3003 <td align="left" valign="top"><p class="table"><a href="#_lrange"><strong><tt>lrange</tt></strong></a></p></td>
3004 </tr>
3005 <tr>
3006 <td align="left" valign="top"><p class="table"><a href="#_lrepeat"><strong><tt>lrepeat</tt></strong></a></p></td>
3007 <td align="left" valign="top"><p class="table"><a href="#_lreplace"><strong><tt>lreplace</tt></strong></a></p></td>
3008 <td align="left" valign="top"><p class="table"><a href="#_lreverse"><strong><tt>lreverse</tt></strong></a></p></td>
3009 <td align="left" valign="top"><p class="table"><a href="#_lsearch"><strong><tt>lsearch</tt></strong></a></p></td>
3010 <td align="left" valign="top"><p class="table"><a href="#_lset"><strong><tt>lset</tt></strong></a></p></td>
3011 <td align="left" valign="top"><p class="table"><a href="#_lsort"><strong><tt>lsort</tt></strong></a></p></td>
3012 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><tt>oo</tt></strong></a></p></td>
3013 <td align="left" valign="top"><p class="table"><a href="#_open"><strong><tt>open</tt></strong></a></p></td>
3014 </tr>
3015 <tr>
3016 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><tt>os.fork</tt></strong></a></p></td>
3017 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><tt>os.gethostname</tt></strong></a></p></td>
3018 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><tt>os.getids</tt></strong></a></p></td>
3019 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><tt>os.uptime</tt></strong></a></p></td>
3020 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><tt>os.wait</tt></strong></a></p></td>
3021 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><tt>pack</tt></strong></a></p></td>
3022 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><tt>pack</tt></strong></a></p></td>
3023 <td align="left" valign="top"><p class="table"><a href="#_package"><strong><tt>package</tt></strong></a></p></td>
3024 </tr>
3025 <tr>
3026 <td align="left" valign="top"><p class="table"><a href="#_pid"><strong><tt>pid</tt></strong></a></p></td>
3027 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><tt>posix</tt></strong></a></p></td>
3028 <td align="left" valign="top"><p class="table"><a href="#_proc"><strong><tt>proc</tt></strong></a></p></td>
3029 <td align="left" valign="top"><p class="table"><a href="#_puts"><strong><tt>puts</tt></strong></a></p></td>
3030 <td align="left" valign="top"><p class="table"><a href="#_pwd"><strong><tt>pwd</tt></strong></a></p></td>
3031 <td align="left" valign="top"><p class="table"><a href="#_rand"><strong><tt>rand</tt></strong></a></p></td>
3032 <td align="left" valign="top"><p class="table"><a href="#_range"><strong><tt>range</tt></strong></a></p></td>
3033 <td align="left" valign="top"><p class="table"><a href="#_read"><strong><tt>read</tt></strong></a></p></td>
3034 </tr>
3035 <tr>
3036 <td align="left" valign="top"><p class="table"><a href="#_ref"><strong><tt>ref</tt></strong></a></p></td>
3037 <td align="left" valign="top"><p class="table"><a href="#_regexp"><strong><tt>regexp</tt></strong></a></p></td>
3038 <td align="left" valign="top"><p class="table"><a href="#_regsub"><strong><tt>regsub</tt></strong></a></p></td>
3039 <td align="left" valign="top"><p class="table"><a href="#_rename"><strong><tt>rename</tt></strong></a></p></td>
3040 <td align="left" valign="top"><p class="table"><a href="#_return"><strong><tt>return</tt></strong></a></p></td>
3041 <td align="left" valign="top"><p class="table"><a href="#_scan"><strong><tt>scan</tt></strong></a></p></td>
3042 <td align="left" valign="top"><p class="table"><a href="#_seek"><strong><tt>seek</tt></strong></a></p></td>
3043 <td align="left" valign="top"><p class="table"><a href="#_set"><strong><tt>set</tt></strong></a></p></td>
3044 </tr>
3045 <tr>
3046 <td align="left" valign="top"><p class="table"><a href="#_setref"><strong><tt>setref</tt></strong></a></p></td>
3047 <td align="left" valign="top"><p class="table"><a href="#_signal"><strong><tt>signal</tt></strong></a></p></td>
3048 <td align="left" valign="top"><p class="table"><a href="#_sleep"><strong><tt>sleep</tt></strong></a></p></td>
3049 <td align="left" valign="top"><p class="table"><a href="#_socket"><strong><tt>socket</tt></strong></a></p></td>
3050 <td align="left" valign="top"><p class="table"><a href="#_source"><strong><tt>source</tt></strong></a></p></td>
3051 <td align="left" valign="top"><p class="table"><a href="#_split"><strong><tt>split</tt></strong></a></p></td>
3052 <td align="left" valign="top"><p class="table"><a href="#_stackdump"><strong><tt>stackdump</tt></strong></a></p></td>
3053 <td align="left" valign="top"><p class="table"><a href="#_stacktrace"><strong><tt>stacktrace</tt></strong></a></p></td>
3054 </tr>
3055 <tr>
3056 <td align="left" valign="top"><p class="table"><a href="#_string"><strong><tt>string</tt></strong></a></p></td>
3057 <td align="left" valign="top"><p class="table"><a href="#_subst"><strong><tt>subst</tt></strong></a></p></td>
3058 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><tt>super</tt></strong></a></p></td>
3059 <td align="left" valign="top"><p class="table"><a href="#_switch"><strong><tt>switch</tt></strong></a></p></td>
3060 <td align="left" valign="top"><p class="table"><a href="#_syslog"><strong><tt>syslog</tt></strong></a></p></td>
3061 <td align="left" valign="top"><p class="table"><a href="#_tailcall"><strong><tt>tailcall</tt></strong></a></p></td>
3062 <td align="left" valign="top"><p class="table"><a href="#_tell"><strong><tt>tell</tt></strong></a></p></td>
3063 <td align="left" valign="top"><p class="table"><a href="#_throw"><strong><tt>throw</tt></strong></a></p></td>
3064 </tr>
3065 <tr>
3066 <td align="left" valign="top"><p class="table"><a href="#_time"><strong><tt>time</tt></strong></a></p></td>
3067 <td align="left" valign="top"><p class="table"><a href="#_tree"><strong><tt>tree</tt></strong></a></p></td>
3068 <td align="left" valign="top"><p class="table"><a href="#_try"><strong><tt>try</tt></strong></a></p></td>
3069 <td align="left" valign="top"><p class="table"><a href="#_unknown"><strong><tt>unknown</tt></strong></a></p></td>
3070 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><tt>unpack</tt></strong></a></p></td>
3071 <td align="left" valign="top"><p class="table"><a href="#_unset"><strong><tt>unset</tt></strong></a></p></td>
3072 <td align="left" valign="top"><p class="table"><a href="#_upcall"><strong><tt>upcall</tt></strong></a></p></td>
3073 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><tt>update</tt></strong></a></p></td>
3074 </tr>
3075 <tr>
3076 <td align="left" valign="top"><p class="table"><a href="#_uplevel"><strong><tt>uplevel</tt></strong></a></p></td>
3077 <td align="left" valign="top"><p class="table"><a href="#_upvar"><strong><tt>upvar</tt></strong></a></p></td>
3078 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><tt>vwait</tt></strong></a></p></td>
3079 <td align="left" valign="top"><p class="table"><a href="#_while"><strong><tt>while</tt></strong></a></p></td>
3080 <td align="left" valign="top"><p class="table"></p></td>
3081 <td align="left" valign="top"><p class="table"></p></td>
3082 <td align="left" valign="top"><p class="table"></p></td>
3083 <td align="left" valign="top"><p class="table"></p></td>
3084 </tr>
3085 </tbody>
3086 </table>
3087 </div>
3088 </div>
3089 <div class="sect2">
3090 <h3 id="_alarm">alarm</h3>
3091 <div class="paragraph"><p><tt><strong>alarm</strong> <em>seconds</em></tt></p></div>
3092 <div class="paragraph"><p>Delivers the <tt>SIGALRM</tt> signal to the process after the given
3093 number of seconds. If the platform supports <em>ualarm(3)</em> then
3094 the argument may be a floating point value. Otherwise it must
3095 be an integer.</p></div>
3096 <div class="paragraph"><p>Note that unless a signal handler for <tt>SIGALRM</tt> has been installed
3097 (see <a href="#_signal"><strong><tt>signal</tt></strong></a>), the process will exit on this signal.</p></div>
3098 </div>
3099 <div class="sect2">
3100 <h3 id="_alias">alias</h3>
3101 <div class="paragraph"><p><tt><strong>alias</strong> <em>name args...</em></tt></p></div>
3102 <div class="paragraph"><p>Creates a single word alias (<a href="#_proc"><strong><tt>proc</tt></strong></a>) for one or more words. For example,
3103 the following creates an alias for the command <a href="#_info"><strong><tt>info</tt></strong></a> <tt>exists</tt>.</p></div>
3104 <div class="literalblock">
3105 <div class="content">
3106 <pre><tt>alias e info exists
3107 if {[e var]} {
3109 }</tt></pre>
3110 </div></div>
3111 <div class="paragraph"><p><a href="#_alias"><strong><tt>alias</tt></strong></a> returns <tt><em>name</em></tt>, allowing it to be used with <a href="#_local"><strong><tt>local</tt></strong></a>.</p></div>
3112 <div class="paragraph"><p>See also <a href="#_proc"><strong><tt>proc</tt></strong></a>, <a href="#_curry"><strong><tt>curry</tt></strong></a>, <a href="#_lambda"><strong><tt>lambda</tt></strong></a>, <a href="#_local"><strong><tt>local</tt></strong></a>.</p></div>
3113 </div>
3114 <div class="sect2">
3115 <h3 id="_append">append</h3>
3116 <div class="paragraph"><p><tt><strong>append</strong> <em>varName value ?value value &#8230;?</em></tt></p></div>
3117 <div class="paragraph"><p>Append all of the <tt><em>value</em></tt> arguments to the current value
3118 of variable <tt><em>varName</em></tt>. If <tt><em>varName</em></tt> doesn&#8217;t exist,
3119 it is given a value equal to the concatenation of all the
3120 <tt><em>value</em></tt> arguments.</p></div>
3121 <div class="paragraph"><p>This command provides an efficient way to build up long
3122 variables incrementally.
3123 For example, "<a href="#_append"><strong><tt>append</tt></strong></a> <tt>a $b</tt>" is much more efficient than
3124 "<a href="#_set"><strong><tt>set</tt></strong></a> <tt>a $a$b</tt>" if <tt>$a</tt> is long.</p></div>
3125 </div>
3126 <div class="sect2">
3127 <h3 id="_array">array</h3>
3128 <div class="paragraph"><p><tt><strong>array</strong> <em>option arrayName ?arg...?</em></tt></p></div>
3129 <div class="paragraph"><p>This command performs one of several operations on the
3130 variable given by <tt><em>arrayName</em></tt>.</p></div>
3131 <div class="paragraph"><p>Note that in general, if the named array does not exist, the <tt><em>array</em></tt> command behaves
3132 as though the array exists but is empty.</p></div>
3133 <div class="paragraph"><p>The <tt><em>option</em></tt> argument determines what action is carried out by the
3134 command. The legal <tt><em>options</em></tt> (which may be abbreviated) are:</p></div>
3135 <div class="dlist"><dl>
3136 <dt class="hdlist1">
3137 <tt><strong>array exists</strong> <em>arrayName</em></tt>
3138 </dt>
3139 <dd>
3141 Returns 1 if arrayName is an array variable, 0 if there is
3142 no variable by that name. This command is essentially
3143 identical to <a href="#_info"><strong><tt>info</tt></strong></a> <tt>exists</tt>
3144 </p>
3145 </dd>
3146 <dt class="hdlist1">
3147 <tt><strong>array get</strong> <em>arrayName ?pattern?</em></tt>
3148 </dt>
3149 <dd>
3151 Returns a list containing pairs of elements. The first
3152 element in each pair is the name of an element in arrayName
3153 and the second element of each pair is the value of the
3154 array element. The order of the pairs is undefined. If
3155 pattern is not specified, then all of the elements of the
3156 array are included in the result. If pattern is specified,
3157 then only those elements whose names match pattern (using
3158 the matching rules of string match) are included. If arrayName
3159 isn&#8217;t the name of an array variable, or if the array contains
3160 no elements, then an empty list is returned.
3161 </p>
3162 </dd>
3163 <dt class="hdlist1">
3164 <tt><strong>array names</strong> <em>arrayName ?pattern?</em></tt>
3165 </dt>
3166 <dd>
3168 Returns a list containing the names of all of the elements
3169 in the array that match pattern. If pattern is omitted then
3170 the command returns all of the element names in the array.
3171 If pattern is specified, then only those elements whose
3172 names match pattern (using the matching rules of string
3173 match) are included. If there are no (matching) elements
3174 in the array, or if arrayName isn&#8217;t the name of an array
3175 variable, then an empty string is returned.
3176 </p>
3177 </dd>
3178 <dt class="hdlist1">
3179 <tt><strong>array set</strong> <em>arrayName list</em></tt>
3180 </dt>
3181 <dd>
3183 Sets the values of one or more elements in arrayName. list
3184 must have a form like that returned by array get, consisting
3185 of an even number of elements. Each odd-numbered element
3186 in list is treated as an element name within arrayName, and
3187 the following element in list is used as a new value for
3188 that array element. If the variable arrayName does not
3189 already exist and list is empty, arrayName is created with
3190 an empty array value.
3191 </p>
3192 </dd>
3193 <dt class="hdlist1">
3194 <tt><strong>array size</strong> <em>arrayName</em></tt>
3195 </dt>
3196 <dd>
3198 Returns the number of elements in the array. If arrayName
3199 isn&#8217;t the name of an array then 0 is returned.
3200 </p>
3201 </dd>
3202 <dt class="hdlist1">
3203 <tt><strong>array unset</strong> <em>arrayName ?pattern?</em></tt>
3204 </dt>
3205 <dd>
3207 Unsets all of the elements in the array that match pattern
3208 (using the matching rules of string match). If arrayName
3209 isn&#8217;t the name of an array variable or there are no matching
3210 elements in the array, no error will be raised. If pattern
3211 is omitted and arrayName is an array variable, then the
3212 command unsets the entire array. The command always returns
3213 an empty string.
3214 </p>
3215 </dd>
3216 </dl></div>
3217 </div>
3218 <div class="sect2">
3219 <h3 id="_break">break</h3>
3220 <div class="paragraph"><p><tt><strong>break</strong></tt></p></div>
3221 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command
3222 such as <a href="#_for"><strong><tt>for</tt></strong></a> or <a href="#_foreach"><strong><tt>foreach</tt></strong></a> or <a href="#_while"><strong><tt>while</tt></strong></a>. It returns a <tt>JIM_BREAK</tt> code
3223 to signal the innermost containing loop command to return immediately.</p></div>
3224 </div>
3225 <div class="sect2">
3226 <h3 id="_case">case</h3>
3227 <div class="paragraph"><p><tt><strong>case</strong> <em>string</em> ?in? <em>patList body ?patList body &#8230;?</em></tt></p></div>
3228 <div class="paragraph"><p><tt><strong>case</strong> <em>string</em> ?in? {<em>patList body ?patList body &#8230;?</em>}</tt></p></div>
3229 <div class="paragraph"><p><strong>Note</strong> that the <a href="#_switch"><strong><tt>switch</tt></strong></a> command should generally be preferred unless compatibility
3230 with Tcl 6.x is desired.</p></div>
3231 <div class="paragraph"><p>Match <tt><em>string</em></tt> against each of the <tt><em>patList</em></tt> arguments
3232 in order. If one matches, then evaluate the following <tt><em>body</em></tt> argument
3233 by passing it recursively to the Tcl interpreter, and return the result
3234 of that evaluation. Each <tt><em>patList</em></tt> argument consists of a single
3235 pattern or list of patterns. Each pattern may contain any of the wild-cards
3236 described under <a href="#_string"><strong><tt>string</tt></strong></a> <tt>match</tt>.</p></div>
3237 <div class="paragraph"><p>If a <tt><em>patList</em></tt> argument is <tt>default</tt>, the corresponding body will be
3238 evaluated if no <tt><em>patList</em></tt> matches <tt><em>string</em></tt>. If no <tt><em>patList</em></tt> argument
3239 matches <tt><em>string</em></tt> and no default is given, then the <a href="#_case"><strong><tt>case</tt></strong></a> command returns
3240 an empty string.</p></div>
3241 <div class="paragraph"><p>Two syntaxes are provided.</p></div>
3242 <div class="paragraph"><p>The first uses a separate argument for each of the patterns and commands;
3243 this form is convenient if substitutions are desired on some of the
3244 patterns or commands.</p></div>
3245 <div class="paragraph"><p>The second form places all of the patterns and commands together into
3246 a single argument; the argument must have proper list structure, with
3247 the elements of the list being the patterns and commands.</p></div>
3248 <div class="paragraph"><p>The second form makes it easy to construct multi-line case commands,
3249 since the braces around the whole list make it unnecessary to include a
3250 backslash at the end of each line.</p></div>
3251 <div class="paragraph"><p>Since the <tt><em>patList</em></tt> arguments are in braces in the second form,
3252 no command or variable substitutions are performed on them; this makes
3253 the behaviour of the second form different than the first form in some
3254 cases.</p></div>
3255 <div class="paragraph"><p>Below are some examples of <a href="#_case"><strong><tt>case</tt></strong></a> commands:</p></div>
3256 <div class="literalblock">
3257 <div class="content">
3258 <pre><tt>case abc in {a b} {format 1} default {format 2} a* {format 3}</tt></pre>
3259 </div></div>
3260 <div class="paragraph"><p>will return <em>3</em>,</p></div>
3261 <div class="literalblock">
3262 <div class="content">
3263 <pre><tt>case a in {
3264 {a b} {format 1}
3265 default {format 2}
3266 a* {format 3}
3267 }</tt></pre>
3268 </div></div>
3269 <div class="paragraph"><p>will return <em>1</em>, and</p></div>
3270 <div class="literalblock">
3271 <div class="content">
3272 <pre><tt>case xyz {
3273 {a b}
3274 {format 1}
3275 default
3276 {format 2}
3278 {format 3}
3279 }</tt></pre>
3280 </div></div>
3281 <div class="paragraph"><p>will return <em>2</em>.</p></div>
3282 </div>
3283 <div class="sect2">
3284 <h3 id="_catch">catch</h3>
3285 <div class="paragraph"><p><tt><strong>catch</strong> ?-?no?<em>code ...</em>? ?--? <em>command ?resultVarName? ?optionsVarName?</em></tt></p></div>
3286 <div class="paragraph"><p>The <a href="#_catch"><strong><tt>catch</tt></strong></a> command may be used to prevent errors from aborting
3287 command interpretation. <a href="#_catch"><strong><tt>catch</tt></strong></a> evaluates <tt><em>command</em></tt>, and returns a
3288 <tt>JIM_OK</tt> code, regardless of any errors that might occur while
3289 executing <tt><em>command</em></tt> (with the possible exception of <tt>JIM_SIGNAL</tt> -
3290 see below).</p></div>
3291 <div class="paragraph"><p>The return value from <a href="#_catch"><strong><tt>catch</tt></strong></a> is a decimal string giving the code
3292 returned by the Tcl interpreter after executing <tt><em>command</em></tt>. This
3293 will be <em>0</em> (<tt>JIM_OK</tt>) if there were no errors in <tt><em>command</em></tt>; otherwise
3294 it will have a non-zero value corresponding to one of the exceptional
3295 return codes (see jim.h for the definitions of code values, or the
3296 <a href="#_info"><strong><tt>info</tt></strong></a> <tt>returncodes</tt> command).</p></div>
3297 <div class="paragraph"><p>If the <tt><em>resultVarName</em></tt> argument is given, then it gives the name
3298 of a variable; <a href="#_catch"><strong><tt>catch</tt></strong></a> will set the value of the variable to the
3299 string returned from <tt><em>command</em></tt> (either a result or an error message).</p></div>
3300 <div class="paragraph"><p>If the <tt><em>optionsVarName</em></tt> argument is given, then it gives the name
3301 of a variable; <a href="#_catch"><strong><tt>catch</tt></strong></a> will set the value of the variable to a
3302 dictionary. For any return code other than <tt>JIM_RETURN</tt>, the value
3303 for the key <tt>-code</tt> will be set to the return code. For <tt>JIM_RETURN</tt>
3304 it will be set to the code given in <a href="#_return"><strong><tt>return</tt></strong></a> <tt>-code</tt>. Additionally,
3305 for the return code <tt>JIM_ERR</tt>, the value of the key <tt>-errorinfo</tt>
3306 will contain the current stack trace (the same result as <a href="#_info"><strong><tt>info</tt></strong></a> <tt>stacktrace</tt>),
3307 the value of the key <tt>-errorcode</tt> will contain the
3308 same value as the global variable $::errorCode, and the value of
3309 the key <tt>-level</tt> will be the current return level (see <a href="#_return"><strong><tt>return</tt></strong></a> <tt>-level</tt>).
3310 This can be useful to rethrow an error:</p></div>
3311 <div class="literalblock">
3312 <div class="content">
3313 <pre><tt>if {[catch {...} msg opts]} {
3314 ...maybe do something with the error...
3315 incr opts(-level)
3316 return {*}$opts $msg
3317 }</tt></pre>
3318 </div></div>
3319 <div class="paragraph"><p>Normally <a href="#_catch"><strong><tt>catch</tt></strong></a> will <tt><em>not</em></tt> catch any of the codes <tt>JIM_EXIT</tt>, <tt>JIM_EVAL</tt> or <tt>JIM_SIGNAL</tt>.
3320 The set of codes which will be caught may be modified by specifying the one more codes before
3321 <tt><em>command</em></tt>.</p></div>
3322 <div class="paragraph"><p>e.g. To catch <tt>JIM_EXIT</tt> but not <tt>JIM_BREAK</tt> or <tt>JIM_CONTINUE</tt></p></div>
3323 <div class="literalblock">
3324 <div class="content">
3325 <pre><tt>catch -exit -nobreak -nocontinue -- { ... }</tt></pre>
3326 </div></div>
3327 <div class="paragraph"><p>The use of <tt>--</tt> is optional. It signifies that no more return code options follow.</p></div>
3328 <div class="paragraph"><p>Note that if a signal marked as <a href="#_signal"><strong><tt>signal</tt></strong></a> <tt>handle</tt> is caught with <a href="#_catch"><strong><tt>catch</tt></strong></a> <tt>-signal</tt>, the return value
3329 (stored in <tt><em>resultVarName</em></tt>) is name of the signal caught.</p></div>
3330 </div>
3331 <div class="sect2">
3332 <h3 id="_cd">cd</h3>
3333 <div class="paragraph"><p><tt><strong>cd</strong> <em>dirName</em></tt></p></div>
3334 <div class="paragraph"><p>Change the current working directory to <tt><em>dirName</em></tt>.</p></div>
3335 <div class="paragraph"><p>Returns an empty string.</p></div>
3336 <div class="paragraph"><p>This command can potentially be disruptive to an application, so it may
3337 be removed in some applications.</p></div>
3338 </div>
3339 <div class="sect2">
3340 <h3 id="_clock">clock</h3>
3341 <div class="dlist"><dl>
3342 <dt class="hdlist1">
3343 <tt><strong>clock seconds</strong></tt>
3344 </dt>
3345 <dd>
3347 Returns the current time as seconds since the epoch.
3348 </p>
3349 </dd>
3350 <dt class="hdlist1">
3351 <tt><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em></tt>
3352 </dt>
3353 <dd>
3355 Format the given time (seconds since the epoch) according to the given
3356 format. See strftime(3) for supported formats.
3357 If no format is supplied, "%c" is used.
3358 </p>
3359 </dd>
3360 <dt class="hdlist1">
3361 <tt><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em></tt>
3362 </dt>
3363 <dd>
3365 Scan the given time string using the given format string.
3366 See strptime(3) for supported formats.
3367 </p>
3368 </dd>
3369 </dl></div>
3370 </div>
3371 <div class="sect2">
3372 <h3 id="_close">close</h3>
3373 <div class="paragraph"><p><tt><strong>close</strong> <em>fileId</em></tt></p></div>
3374 <div class="paragraph"><p><tt><em>fileId</em> <strong>close</strong></tt></p></div>
3375 <div class="paragraph"><p>Closes the file given by <tt><em>fileId</em></tt>.
3376 <tt><em>fileId</em></tt> must be the return value from a previous invocation
3377 of the <a href="#_open"><strong><tt>open</tt></strong></a> command; after this command, it should not be
3378 used anymore.</p></div>
3379 </div>
3380 <div class="sect2">
3381 <h3 id="_collect">collect</h3>
3382 <div class="paragraph"><p><tt><strong>collect</strong></tt></p></div>
3383 <div class="paragraph"><p>Normally reference garbage collection is automatically performed periodically.
3384 However it may be run immediately with the <a href="#_collect"><strong><tt>collect</tt></strong></a> command.</p></div>
3385 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
3386 </div>
3387 <div class="sect2">
3388 <h3 id="_concat">concat</h3>
3389 <div class="paragraph"><p><tt><strong>concat</strong> <em>arg ?arg ...?</em></tt></p></div>
3390 <div class="paragraph"><p>This command treats each argument as a list and concatenates them
3391 into a single list. It permits any number of arguments. For example,
3392 the command</p></div>
3393 <div class="literalblock">
3394 <div class="content">
3395 <pre><tt>concat a b {c d e} {f {g h}}</tt></pre>
3396 </div></div>
3397 <div class="paragraph"><p>will return</p></div>
3398 <div class="literalblock">
3399 <div class="content">
3400 <pre><tt>a b c d e f {g h}</tt></pre>
3401 </div></div>
3402 <div class="paragraph"><p>as its result.</p></div>
3403 </div>
3404 <div class="sect2">
3405 <h3 id="_continue">continue</h3>
3406 <div class="paragraph"><p><tt><strong>continue</strong></tt></p></div>
3407 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command such
3408 as <a href="#_for"><strong><tt>for</tt></strong></a> or <a href="#_foreach"><strong><tt>foreach</tt></strong></a> or <a href="#_while"><strong><tt>while</tt></strong></a>. It returns a <tt>JIM_CONTINUE</tt> code to
3409 signal the innermost containing loop command to skip the remainder of
3410 the loop&#8217;s body but continue with the next iteration of the loop.</p></div>
3411 </div>
3412 <div class="sect2">
3413 <h3 id="_curry">curry</h3>
3414 <div class="paragraph"><p><tt><strong>alias</strong> <em>args...</em></tt></p></div>
3415 <div class="paragraph"><p>Similar to <a href="#_alias"><strong><tt>alias</tt></strong></a> except it creates an anonymous procedure (lambda) instead of
3416 a named procedure.</p></div>
3417 <div class="paragraph"><p>the following creates a local, unnamed alias for the command <a href="#_info"><strong><tt>info</tt></strong></a> <tt>exists</tt>.</p></div>
3418 <div class="literalblock">
3419 <div class="content">
3420 <pre><tt>set e [local curry info exists]
3421 if {[$e var]} {
3423 }</tt></pre>
3424 </div></div>
3425 <div class="paragraph"><p><a href="#_curry"><strong><tt>curry</tt></strong></a> returns the name of the procedure.</p></div>
3426 <div class="paragraph"><p>See also <a href="#_proc"><strong><tt>proc</tt></strong></a>, <a href="#_alias"><strong><tt>alias</tt></strong></a>, <a href="#_lambda"><strong><tt>lambda</tt></strong></a>, <a href="#_local"><strong><tt>local</tt></strong></a>.</p></div>
3427 </div>
3428 <div class="sect2">
3429 <h3 id="_dict">dict</h3>
3430 <div class="paragraph"><p><tt><strong>dict</strong> <em>option ?arg...?</em></tt></p></div>
3431 <div class="paragraph"><p>Performs one of several operations on dictionary values.</p></div>
3432 <div class="paragraph"><p>The <tt><em>option</em></tt> argument determines what action is carried out by the
3433 command. The legal <tt><em>options</em></tt> are:</p></div>
3434 <div class="dlist"><dl>
3435 <dt class="hdlist1">
3436 <tt><strong>dict create</strong> <em>?key value ...?</em></tt>
3437 </dt>
3438 <dd>
3440 Create and return a new dictionary value that contains each of
3441 the key/value mappings listed as arguments (keys and values
3442 alternating, with each key being followed by its associated
3443 value.)
3444 </p>
3445 </dd>
3446 <dt class="hdlist1">
3447 <tt><strong>dict exists</strong> <em>dictionary key ?key ...?</em></tt>
3448 </dt>
3449 <dd>
3451 Returns a boolean value indicating whether the given key (or path
3452 of keys through a set of nested dictionaries) exists in the given
3453 dictionary value. This returns a true value exactly when <a href="#_dict"><strong><tt>dict</tt></strong></a> <tt>get</tt>
3454 on that path will succeed.
3455 </p>
3456 </dd>
3457 <dt class="hdlist1">
3458 <tt><strong>dict get</strong> <em>dictionary ?key ...?</em></tt>
3459 </dt>
3460 <dd>
3462 Given a dictionary value (first argument) and a key (second argument),
3463 this will retrieve the value for that key. Where several keys are
3464 supplied, the behaviour of the command shall be as if the result
3465 of "<a href="#_dict"><strong><tt>dict</tt></strong></a> <tt>get $dictVal $key</tt>" was passed as the first argument to
3466 dict get with the remaining arguments as second (and possibly
3467 subsequent) arguments. This facilitates lookups in nested dictionaries.
3468 If no keys are provided, dict would return a list containing pairs
3469 of elements in a man- ner similar to array get. That is, the first
3470 element of each pair would be the key and the second element would
3471 be the value for that key. It is an error to attempt to retrieve
3472 a value for a key that is not present in the dictionary.
3473 </p>
3474 </dd>
3475 <dt class="hdlist1">
3476 <tt><strong>dict keys</strong> <em>dictionary ?pattern?</em></tt>
3477 </dt>
3478 <dd>
3480 Returns a list of the keys in the dictionary.
3481 If pattern is specified, then only those keys whose
3482 names match <tt><em>pattern</em></tt> (using the matching rules of string
3483 match) are included.
3484 </p>
3485 </dd>
3486 <dt class="hdlist1">
3487 <tt><strong>dict merge</strong> ?<em>dictionary ...</em>?</tt>
3488 </dt>
3489 <dd>
3491 Return a dictionary that contains the contents of each of the
3492 <tt><em>dictionary</em></tt> arguments. Where two (or more) dictionaries
3493 contain a mapping for the same key, the resulting dictionary
3494 maps that key to the value according to the last dictionary on
3495 the command line containing a mapping for that key.
3496 </p>
3497 </dd>
3498 <dt class="hdlist1">
3499 <tt><strong>dict set</strong> <em>dictionaryName key ?key ...? value</em></tt>
3500 </dt>
3501 <dd>
3503 This operation takes the <tt><em>name</em></tt> of a variable containing a dictionary
3504 value and places an updated dictionary value in that variable
3505 containing a mapping from the given key to the given value. When
3506 multiple keys are present, this operation creates or updates a chain
3507 of nested dictionaries.
3508 </p>
3509 </dd>
3510 <dt class="hdlist1">
3511 <tt><strong>dict size</strong> <em>dictionary</em></tt>
3512 </dt>
3513 <dd>
3515 Return the number of key/value mappings in the given dictionary value.
3516 </p>
3517 </dd>
3518 <dt class="hdlist1">
3519 <tt><strong>dict unset</strong> <em>dictionaryName key ?key ...? value</em></tt>
3520 </dt>
3521 <dd>
3523 This operation (the companion to <a href="#_dict"><strong><tt>dict</tt></strong></a> <tt>set</tt>) takes the name of a
3524 variable containing a dictionary value and places an updated
3525 dictionary value in that variable that does not contain a mapping
3526 for the given key. Where multiple keys are present, this describes
3527 a path through nested dictionaries to the mapping to remove. At
3528 least one key must be specified, but the last key on the key-path
3529 need not exist. All other components on the path must exist.
3530 </p>
3531 </dd>
3532 <dt class="hdlist1">
3533 <tt><strong>dict with</strong> <em>dictionaryName key ?key ...? script</em></tt>
3534 </dt>
3535 <dd>
3537 Execute the Tcl script in <tt><em>script</em></tt> with the value for each
3538 key in <tt><em>dictionaryName</em></tt> mapped to a variable with the same
3539 name. Where one or more keys are given, these indicate a chain
3540 of nested dictionaries, with the innermost dictionary being the
3541 one opened out for the execution of body. Making <tt><em>dictionaryName</em></tt>
3542 unreadable will make the updates to the dictionary be discarded,
3543 and this also happens if the contents of <tt><em>dictionaryName</em></tt> are
3544 adjusted so that the chain of dictionaries no longer exists.
3545 The result of <a href="#_dict"><strong><tt>dict</tt></strong></a> <tt>with</tt> is (unless some kind of error occurs)
3546 the result of the evaluation of body.
3547 </p>
3548 </dd>
3549 <dt class="hdlist1">
3551 </dt>
3552 <dd>
3554 The variables are mapped in the scope enclosing the <a href="#_dict"><strong><tt>dict</tt></strong></a> <tt>with</tt>;
3555 it is recommended that this command only be used in a local
3556 scope (procedure). Because of this, the variables set by
3557 <a href="#_dict"><strong><tt>dict</tt></strong></a> <tt>with</tt> will continue to exist after the command finishes (unless
3558 explicitly unset). Note that changes to the contents of <tt><em>dictionaryName</em></tt>
3559 only happen when <tt><em>script</em></tt> terminates.
3560 </p>
3561 </dd>
3562 </dl></div>
3563 </div>
3564 <div class="sect2">
3565 <h3 id="_env">env</h3>
3566 <div class="paragraph"><p><tt><strong>env</strong> <em>?name? ?default?</em></tt></p></div>
3567 <div class="paragraph"><p>If <tt><em>name</em></tt> is supplied, returns the value of <tt><em>name</em></tt> from the initial
3568 environment (see getenv(3)). An error is returned if <tt><em>name</em></tt> does not
3569 exist in the environment, unless <tt><em>default</em></tt> is supplied - in which case
3570 that value is returned instead.</p></div>
3571 <div class="paragraph"><p>If no arguments are supplied, returns a list of all environment variables
3572 and their values as <tt>{name value ...}</tt></p></div>
3573 <div class="paragraph"><p>See also the global variable <tt>::env</tt></p></div>
3574 </div>
3575 <div class="sect2">
3576 <h3 id="_eof">eof</h3>
3577 <div class="paragraph"><p><tt><strong>eof</strong> <em>fileId</em></tt></p></div>
3578 <div class="paragraph"><p><tt><em>fileId</em> <strong>eof</strong></tt></p></div>
3579 <div class="paragraph"><p>Returns 1 if an end-of-file condition has occurred on <tt><em>fileId</em></tt>,
3580 0 otherwise.</p></div>
3581 <div class="paragraph"><p><tt><em>fileId</em></tt> must have been the return value from a previous call to <a href="#_open"><strong><tt>open</tt></strong></a>,
3582 or it may be <tt>stdin</tt>, <tt>stdout</tt>, or <tt>stderr</tt> to refer to one of the
3583 standard I/O channels.</p></div>
3584 </div>
3585 <div class="sect2">
3586 <h3 id="_error">error</h3>
3587 <div class="paragraph"><p><tt><strong>error</strong> <em>message ?stacktrace?</em></tt></p></div>
3588 <div class="paragraph"><p>Returns a <tt>JIM_ERR</tt> code, which causes command interpretation to be
3589 unwound. <tt><em>message</em></tt> is a string that is returned to the application
3590 to indicate what went wrong.</p></div>
3591 <div class="paragraph"><p>If the <tt><em>stacktrace</em></tt> argument is provided and is non-empty,
3592 it is used to initialize the stacktrace.</p></div>
3593 <div class="paragraph"><p>This feature is most useful in conjunction with the <a href="#_catch"><strong><tt>catch</tt></strong></a> command:
3594 if a caught error cannot be handled successfully, <tt><em>stacktrace</em></tt> can be used
3595 to return a stack trace reflecting the original point of occurrence
3596 of the error:</p></div>
3597 <div class="literalblock">
3598 <div class="content">
3599 <pre><tt>catch {...} errMsg
3601 error $errMsg [info stacktrace]</tt></pre>
3602 </div></div>
3603 <div class="paragraph"><p>See also <tt>errorInfo</tt>, <a href="#_info"><strong><tt>info</tt></strong></a> <tt>stacktrace</tt>, <a href="#_catch"><strong><tt>catch</tt></strong></a> and <a href="#_return"><strong><tt>return</tt></strong></a></p></div>
3604 </div>
3605 <div class="sect2">
3606 <h3 id="_errorinfo">errorInfo</h3>
3607 <div class="paragraph"><p><tt><strong>errorInfo</strong> <em>error ?stacktrace?</em></tt></p></div>
3608 <div class="paragraph"><p>Returns a human-readable representation of the given error message and stack trace.
3609 Typical usage is:</p></div>
3610 <div class="literalblock">
3611 <div class="content">
3612 <pre><tt>if {[catch {...} error]} {
3613 puts stderr [errorInfo $error [info stacktrace]]
3614 exit 1
3615 }</tt></pre>
3616 </div></div>
3617 <div class="paragraph"><p>See also <a href="#_error"><strong><tt>error</tt></strong></a>.</p></div>
3618 </div>
3619 <div class="sect2">
3620 <h3 id="_eval">eval</h3>
3621 <div class="paragraph"><p><tt><strong>eval</strong> <em>arg ?arg...?</em></tt></p></div>
3622 <div class="paragraph"><p><a href="#_eval"><strong><tt>eval</tt></strong></a> takes one or more arguments, which together comprise a Tcl
3623 command (or collection of Tcl commands separated by newlines in the
3624 usual way). <a href="#_eval"><strong><tt>eval</tt></strong></a> concatenates all its arguments in the same
3625 fashion as the <a href="#_concat"><strong><tt>concat</tt></strong></a> command, passes the concatenated string to the
3626 Tcl interpreter recursively, and returns the result of that
3627 evaluation (or any error generated by it).</p></div>
3628 </div>
3629 <div class="sect2">
3630 <h3 id="_exec">exec</h3>
3631 <div class="paragraph"><p><tt><strong>exec</strong> <em>arg ?arg...?</em></tt></p></div>
3632 <div class="paragraph"><p>This command treats its arguments as the specification
3633 of one or more UNIX commands to execute as subprocesses.
3634 The commands take the form of a standard shell pipeline;
3635 <tt>|</tt> arguments separate commands in the
3636 pipeline and cause standard output of the preceding command
3637 to be piped into standard input of the next command (or <tt>|&amp;</tt> for
3638 both standard output and standard error).</p></div>
3639 <div class="paragraph"><p>Under normal conditions the result of the <a href="#_exec"><strong><tt>exec</tt></strong></a> command
3640 consists of the standard output produced by the last command
3641 in the pipeline.</p></div>
3642 <div class="paragraph"><p>If any of the commands in the pipeline exit abnormally or
3643 are killed or suspended, then <a href="#_exec"><strong><tt>exec</tt></strong></a> will return an error
3644 and the error message will include the pipeline&#8217;s output followed by
3645 error messages describing the abnormal terminations.</p></div>
3646 <div class="paragraph"><p>If any of the commands writes to its standard error file,
3647 then <a href="#_exec"><strong><tt>exec</tt></strong></a> will return an error, and the error message
3648 will include the pipeline&#8217;s output, followed by messages
3649 about abnormal terminations (if any), followed by the standard error
3650 output.</p></div>
3651 <div class="paragraph"><p>If the last character of the result or error message
3652 is a newline then that character is deleted from the result
3653 or error message for consistency with normal
3654 Tcl return values.</p></div>
3655 <div class="paragraph"><p>An <tt><em>arg</em></tt> may have one of the following special forms:</p></div>
3656 <div class="dlist"><dl>
3657 <dt class="hdlist1">
3658 <tt>&gt;filename</tt>
3659 </dt>
3660 <dd>
3662 The standard output of the last command in the pipeline
3663 is redirected to the file. In this situation <a href="#_exec"><strong><tt>exec</tt></strong></a>
3664 will normally return an empty string.
3665 </p>
3666 </dd>
3667 <dt class="hdlist1">
3668 <tt>&gt;&gt;filename</tt>
3669 </dt>
3670 <dd>
3672 As above, but append to the file.
3673 </p>
3674 </dd>
3675 <dt class="hdlist1">
3676 <tt>&gt;@fileId</tt>
3677 </dt>
3678 <dd>
3680 The standard output of the last command in the pipeline is
3681 redirected to the given (writable) file descriptor (e.g. stdout,
3682 stderr, or the result of <a href="#_open"><strong><tt>open</tt></strong></a>). In this situation <a href="#_exec"><strong><tt>exec</tt></strong></a>
3683 will normally return an empty string.
3684 </p>
3685 </dd>
3686 <dt class="hdlist1">
3687 <tt>2&gt;filename</tt>
3688 </dt>
3689 <dd>
3691 The standard error of the last command in the pipeline
3692 is redirected to the file.
3693 </p>
3694 </dd>
3695 <dt class="hdlist1">
3696 <tt>2&gt;&gt;filename</tt>
3697 </dt>
3698 <dd>
3700 As above, but append to the file.
3701 </p>
3702 </dd>
3703 <dt class="hdlist1">
3704 <tt>2&gt;@fileId</tt>
3705 </dt>
3706 <dd>
3708 The standard error of the last command in the pipeline is
3709 redirected to the given (writable) file descriptor.
3710 </p>
3711 </dd>
3712 <dt class="hdlist1">
3713 <tt>2&gt;@1</tt>
3714 </dt>
3715 <dd>
3717 The standard error of the last command in the pipeline is
3718 redirected to the same file descriptor as the standard output.
3719 </p>
3720 </dd>
3721 <dt class="hdlist1">
3722 <tt>&gt;&amp;filename</tt>
3723 </dt>
3724 <dd>
3726 Both the standard output and standard error of the last command
3727 in the pipeline is redirected to the file.
3728 </p>
3729 </dd>
3730 <dt class="hdlist1">
3731 <tt>&gt;&gt;&amp;filename</tt>
3732 </dt>
3733 <dd>
3735 As above, but append to the file.
3736 </p>
3737 </dd>
3738 <dt class="hdlist1">
3739 <tt>&lt;filename</tt>
3740 </dt>
3741 <dd>
3743 The standard input of the first command in the pipeline
3744 is taken from the file.
3745 </p>
3746 </dd>
3747 <dt class="hdlist1">
3748 <tt>&lt;&lt;string</tt>
3749 </dt>
3750 <dd>
3752 The standard input of the first command is taken as the
3753 given immediate value.
3754 </p>
3755 </dd>
3756 <dt class="hdlist1">
3757 <tt>&lt;@fileId</tt>
3758 </dt>
3759 <dd>
3761 The standard input of the first command in the pipeline
3762 is taken from the given (readable) file descriptor.
3763 </p>
3764 </dd>
3765 </dl></div>
3766 <div class="paragraph"><p>If there is no redirection of standard input, standard error
3767 or standard output, these are connected to the corresponding
3768 input or output of the application.</p></div>
3769 <div class="paragraph"><p>If the last <tt><em>arg</em></tt> is <tt>&amp;</tt> then the command will be
3770 executed in background.
3771 In this case the standard output from the last command
3772 in the pipeline will
3773 go to the application&#8217;s standard output unless
3774 redirected in the command, and error output from all
3775 the commands in the pipeline will go to the application&#8217;s
3776 standard error file. The return value of exec in this case
3777 is a list of process ids (pids) in the pipeline.</p></div>
3778 <div class="paragraph"><p>Each <tt><em>arg</em></tt> becomes one word for a command, except for
3779 <tt>|</tt>, <tt>&lt;</tt>, <tt>&lt;&lt;</tt>, <tt>&gt;</tt>, and <tt>&amp;</tt> arguments, and the
3780 arguments that follow <tt>&lt;</tt>, <tt>&lt;&lt;</tt>, and <tt>&gt;</tt>.</p></div>
3781 <div class="paragraph"><p>The first word in each command is taken as the command name;
3782 the directories in the PATH environment variable are searched for
3783 an executable by the given name.</p></div>
3784 <div class="paragraph"><p>No <a href="#_glob"><strong><tt>glob</tt></strong></a> expansion or other shell-like substitutions
3785 are performed on the arguments to commands.</p></div>
3786 <div class="paragraph"><p>If the command fails, the global $::errorCode (and the -errorcode
3787 option in <a href="#_catch"><strong><tt>catch</tt></strong></a>) will be set to a list, as follows:</p></div>
3788 <div class="dlist"><dl>
3789 <dt class="hdlist1">
3790 <tt><strong>CHILDKILLED</strong> <em>pid sigName msg</em></tt>
3791 </dt>
3792 <dd>
3794 This format is used when a child process has been killed
3795 because of a signal. The pid element will be the process&#8217;s
3796 identifier (in decimal). The sigName element will be the
3797 symbolic name of the signal that caused the process to
3798 terminate; it will be one of the names from the include
3799 file signal.h, such as SIGPIPE. The msg element will be a
3800 short human-readable message describing the signal, such
3801 as "write on pipe with no readers" for SIGPIPE.
3802 </p>
3803 </dd>
3804 <dt class="hdlist1">
3805 <tt><strong>CHILDSUSP</strong> <em>pid sigName msg</em></tt>
3806 </dt>
3807 <dd>
3809 This format is used when a child process has been suspended
3810 because of a signal. The pid element will be the process&#8217;s
3811 identifier, in decimal. The sigName element will be the
3812 symbolic name of the signal that caused the process to
3813 suspend; this will be one of the names from the include
3814 file signal.h, such as SIGTTIN. The msg element will be a
3815 short human-readable message describing the signal, such
3816 as "background tty read" for SIGTTIN.
3817 </p>
3818 </dd>
3819 <dt class="hdlist1">
3820 <tt><strong>CHILDSTATUS</strong> <em>pid code</em></tt>
3821 </dt>
3822 <dd>
3824 This format is used when a child process has exited with a
3825 non-zero exit status. The pid element will be the process&#8217;s
3826 identifier (in decimal) and the code element will be the
3827 exit code returned by the process (also in decimal).
3828 </p>
3829 </dd>
3830 </dl></div>
3831 <div class="paragraph"><p>The environment for the executed command is set from $::env (unless
3832 this variable is unset, in which case the original environment is used).</p></div>
3833 </div>
3834 <div class="sect2">
3835 <h3 id="_exists">exists</h3>
3836 <div class="paragraph"><p><tt><strong>exists ?-var|-proc|-command?</strong> <em>name</em></tt></p></div>
3837 <div class="paragraph"><p>Checks the existence of the given variable, procedure or command
3838 respectively and returns 1 if it exists or 0 if not. This command
3839 provides a more simplified/convenient version of <a href="#_info"><strong><tt>info</tt></strong></a> <tt>exists</tt>,
3840 <a href="#_info"><strong><tt>info</tt></strong></a> <tt>procs</tt> and <a href="#_info"><strong><tt>info</tt></strong></a> <tt>commands</tt>.</p></div>
3841 <div class="paragraph"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
3842 </div>
3843 <div class="sect2">
3844 <h3 id="_exit">exit</h3>
3845 <div class="paragraph"><p><tt><strong>exit</strong> <em>?returnCode?</em></tt></p></div>
3846 <div class="paragraph"><p>Terminate the process, returning <tt><em>returnCode</em></tt> to the
3847 parent as the exit status.</p></div>
3848 <div class="paragraph"><p>If <tt><em>returnCode</em></tt> isn&#8217;t specified then it defaults
3849 to 0.</p></div>
3850 <div class="paragraph"><p>Note that exit can be caught with <a href="#_catch"><strong><tt>catch</tt></strong></a>.</p></div>
3851 </div>
3852 <div class="sect2">
3853 <h3 id="_expr">expr</h3>
3854 <div class="paragraph"><p><tt><strong>expr</strong> <em>arg</em></tt></p></div>
3855 <div class="paragraph"><p>Calls the expression processor to evaluate <tt><em>arg</em></tt>, and returns
3856 the result as a string. See the section EXPRESSIONS above.</p></div>
3857 <div class="paragraph"><p>Note that Jim supports a shorthand syntax for <a href="#_expr"><strong><tt>expr</tt></strong></a> as <tt>$(...)</tt>
3858 The following two are identical.</p></div>
3859 <div class="literalblock">
3860 <div class="content">
3861 <pre><tt>set x [expr {3 * 2 + 1}]
3862 set x $(3 * 2 + 1)</tt></pre>
3863 </div></div>
3864 </div>
3865 <div class="sect2">
3866 <h3 id="_file">file</h3>
3867 <div class="paragraph"><p><tt><strong>file</strong> <em>option name ?arg...?</em></tt></p></div>
3868 <div class="paragraph"><p>Operate on a file or a file name. <tt><em>name</em></tt> is the name of a file.</p></div>
3869 <div class="paragraph"><p><tt><em>option</em></tt> indicates what to do with the file name. Any unique
3870 abbreviation for <tt><em>option</em></tt> is acceptable. The valid options are:</p></div>
3871 <div class="dlist"><dl>
3872 <dt class="hdlist1">
3873 <tt><strong>file atime</strong> <em>name</em></tt>
3874 </dt>
3875 <dd>
3877 Return a decimal string giving the time at which file <tt><em>name</em></tt>
3878 was last accessed. The time is measured in the standard UNIX
3879 fashion as seconds from a fixed starting time (often January 1, 1970).
3880 If the file doesn&#8217;t exist or its access time cannot be queried then an
3881 error is generated.
3882 </p>
3883 </dd>
3884 <dt class="hdlist1">
3885 <tt><strong>file copy ?-force?</strong> <em>source target</em></tt>
3886 </dt>
3887 <dd>
3889 Copies file <tt><em>source</em></tt> to file <tt><em>target</em></tt>. The source file must exist.
3890 The target file must not exist, unless <tt>-force</tt> is specified.
3891 </p>
3892 </dd>
3893 <dt class="hdlist1">
3894 <tt><strong>file delete ?-force?</strong> <em>name...</em></tt>
3895 </dt>
3896 <dd>
3898 Deletes file or directory <tt><em>name</em></tt>. If the file or directory doesn&#8217;t exist, nothing happens.
3899 If it can&#8217;t be deleted, an error is generated. Non-empty directories will not be deleted
3900 unless the <tt>-force</tt> options is given. In this case no errors will be generated, even
3901 if the file/directory can&#8217;t be deleted.
3902 </p>
3903 </dd>
3904 <dt class="hdlist1">
3905 <tt><strong>file dirname</strong> <em>name</em></tt>
3906 </dt>
3907 <dd>
3909 Return all of the characters in <tt><em>name</em></tt> up to but not including
3910 the last slash character. If there are no slashes in <tt><em>name</em></tt>
3911 then return <tt>.</tt> (a single dot). If the last slash in <tt><em>name</em></tt> is its first
3912 character, then return <tt>/</tt>.
3913 </p>
3914 </dd>
3915 <dt class="hdlist1">
3916 <tt><strong>file executable</strong> <em>name</em></tt>
3917 </dt>
3918 <dd>
3920 Return <em>1</em> if file <tt><em>name</em></tt> is executable by
3921 the current user, <em>0</em> otherwise.
3922 </p>
3923 </dd>
3924 <dt class="hdlist1">
3925 <tt><strong>file exists</strong> <em>name</em></tt>
3926 </dt>
3927 <dd>
3929 Return <em>1</em> if file <tt><em>name</em></tt> exists and the current user has
3930 search privileges for the directories leading to it, <em>0</em> otherwise.
3931 </p>
3932 </dd>
3933 <dt class="hdlist1">
3934 <tt><strong>file extension</strong> <em>name</em></tt>
3935 </dt>
3936 <dd>
3938 Return all of the characters in <tt><em>name</em></tt> after and including the
3939 last dot in <tt><em>name</em></tt>. If there is no dot in <tt><em>name</em></tt> then return
3940 the empty string.
3941 </p>
3942 </dd>
3943 <dt class="hdlist1">
3944 <tt><strong>file isdirectory</strong> <em>name</em></tt>
3945 </dt>
3946 <dd>
3948 Return <em>1</em> if file <tt><em>name</em></tt> is a directory,
3949 <em>0</em> otherwise.
3950 </p>
3951 </dd>
3952 <dt class="hdlist1">
3953 <tt><strong>file isfile</strong> <em>name</em></tt>
3954 </dt>
3955 <dd>
3957 Return <em>1</em> if file <tt><em>name</em></tt> is a regular file,
3958 <em>0</em> otherwise.
3959 </p>
3960 </dd>
3961 <dt class="hdlist1">
3962 <tt><strong>file join</strong> <em>arg...</em></tt>
3963 </dt>
3964 <dd>
3966 Joins multiple path components. Note that if any components is
3967 an absolute path, the preceding components are ignored.
3968 Thus <tt>"<a href="#_file"><strong><tt>file</tt></strong></a> join /tmp /root"</tt> returns <tt>"/root"</tt>.
3969 </p>
3970 </dd>
3971 <dt class="hdlist1">
3972 <tt><strong>file lstat</strong> <em>name varName</em></tt>
3973 </dt>
3974 <dd>
3976 Same as <em>stat</em> option (see below) except uses the <tt><em>lstat</em></tt>
3977 kernel call instead of <tt><em>stat</em></tt>. This means that if <tt><em>name</em></tt>
3978 refers to a symbolic link the information returned in <tt><em>varName</em></tt>
3979 is for the link rather than the file it refers to. On systems that
3980 don&#8217;t support symbolic links this option behaves exactly the same
3981 as the <em>stat</em> option.
3982 </p>
3983 </dd>
3984 <dt class="hdlist1">
3985 <tt><strong>file mkdir</strong> <em>dir1 ?dir2...?</em></tt>
3986 </dt>
3987 <dd>
3989 Creates each directory specified. For each pathname <tt><em>dir</em></tt> specified,
3990 this command will create all non-existing parent directories
3991 as well as <tt><em>dir</em></tt> itself. If an existing directory is specified,
3992 then no action is taken and no error is returned. Trying to
3993 overwrite an existing file with a directory will result in an
3994 error. Arguments are processed in the order specified, halting
3995 at the first error, if any.
3996 </p>
3997 </dd>
3998 <dt class="hdlist1">
3999 <tt><strong>file mtime</strong> <em>name ?time?</em></tt>
4000 </dt>
4001 <dd>
4003 Return a decimal string giving the time at which file <tt><em>name</em></tt>
4004 was last modified. The time is measured in the standard UNIX
4005 fashion as seconds from a fixed starting time (often January 1, 1970).
4006 If the file doesn&#8217;t exist or its modified time cannot be queried then an
4007 error is generated. If <tt><em>time</em></tt> is given, sets the modification time
4008 of the file to the given value.
4009 </p>
4010 </dd>
4011 <dt class="hdlist1">
4012 <tt><strong>file normalize</strong> <em>name</em></tt>
4013 </dt>
4014 <dd>
4016 Return the normalized path of <tt><em>name</em></tt>. See <em>realpath(3)</em>.
4017 </p>
4018 </dd>
4019 <dt class="hdlist1">
4020 <tt><strong>file owned</strong> <em>name</em></tt>
4021 </dt>
4022 <dd>
4024 Return <em>1</em> if file <tt><em>name</em></tt> is owned by the current user,
4025 <em>0</em> otherwise.
4026 </p>
4027 </dd>
4028 <dt class="hdlist1">
4029 <tt><strong>file readable</strong> <em>name</em></tt>
4030 </dt>
4031 <dd>
4033 Return <em>1</em> if file <tt><em>name</em></tt> is readable by
4034 the current user, <em>0</em> otherwise.
4035 </p>
4036 </dd>
4037 <dt class="hdlist1">
4038 <tt><strong>file readlink</strong> <em>name</em></tt>
4039 </dt>
4040 <dd>
4042 Returns the value of the symbolic link given by <tt><em>name</em></tt> (i.e. the
4043 name of the file it points to). If
4044 <tt><em>name</em></tt> isn&#8217;t a symbolic link or its value cannot be read, then
4045 an error is returned. On systems that don&#8217;t support symbolic links
4046 this option is undefined.
4047 </p>
4048 </dd>
4049 <dt class="hdlist1">
4050 <tt><strong>file rename</strong> <em>oldname</em> <em>newname</em></tt>
4051 </dt>
4052 <dd>
4054 Renames the file from the old name to the new name.
4055 </p>
4056 </dd>
4057 <dt class="hdlist1">
4058 <tt><strong>file rootname</strong> <em>name</em></tt>
4059 </dt>
4060 <dd>
4062 Return all of the characters in <tt><em>name</em></tt> up to but not including
4063 the last <em>.</em> character in the name. If <tt><em>name</em></tt> doesn&#8217;t contain
4064 a dot, then return <tt><em>name</em></tt>.
4065 </p>
4066 </dd>
4067 <dt class="hdlist1">
4068 <tt><strong>file size</strong> <em>name</em></tt>
4069 </dt>
4070 <dd>
4072 Return a decimal string giving the size of file <tt><em>name</em></tt> in bytes.
4073 If the file doesn&#8217;t exist or its size cannot be queried then an
4074 error is generated.
4075 </p>
4076 </dd>
4077 <dt class="hdlist1">
4078 <tt><strong>file stat</strong> <em>name varName</em></tt>
4079 </dt>
4080 <dd>
4082 Invoke the <em>stat</em> kernel call on <tt><em>name</em></tt>, and use the
4083 variable given by <tt><em>varName</em></tt> to hold information returned from
4084 the kernel call.
4085 <tt><em>varName</em></tt> is treated as an array variable,
4086 and the following elements of that variable are set: <em>atime</em>,
4087 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
4088 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>.
4089 Each element except <em>type</em> is a decimal string with the value of
4090 the corresponding field from the <em>stat</em> return structure; see the
4091 manual entry for <em>stat</em> for details on the meanings of the values.
4092 The <em>type</em> element gives the type of the file in the same form
4093 returned by the command <a href="#_file"><strong><tt>file</tt></strong></a> <tt>type</tt>.
4094 This command returns an empty string.
4095 </p>
4096 </dd>
4097 <dt class="hdlist1">
4098 <tt><strong>file tail</strong> <em>name</em></tt>
4099 </dt>
4100 <dd>
4102 Return all of the characters in <tt><em>name</em></tt> after the last slash.
4103 If <tt><em>name</em></tt> contains no slashes then return <tt><em>name</em></tt>.
4104 </p>
4105 </dd>
4106 <dt class="hdlist1">
4107 <tt><strong>file tempfile</strong> <em>?template?</em></tt>
4108 </dt>
4109 <dd>
4111 Creates and returns the name of a unique temporary file. If <tt><em>template</em></tt> is omitted, a
4112 default template will be used to place the file in /tmp. See <em>mkstemp(3)</em> for
4113 the format of the template and security concerns.
4114 </p>
4115 </dd>
4116 <dt class="hdlist1">
4117 <tt><strong>file type</strong> <em>name</em></tt>
4118 </dt>
4119 <dd>
4121 Returns a string giving the type of file <tt><em>name</em></tt>, which will be
4122 one of <tt>file</tt>, <tt>directory</tt>, <tt>characterSpecial</tt>,
4123 <tt>blockSpecial</tt>, <tt>fifo</tt>, <tt>link</tt>, or <tt>socket</tt>.
4124 </p>
4125 </dd>
4126 <dt class="hdlist1">
4127 <tt><strong>file writable</strong> <em>name</em></tt>
4128 </dt>
4129 <dd>
4131 Return <em>1</em> if file <tt><em>name</em></tt> is writable by
4132 the current user, <em>0</em> otherwise.
4133 </p>
4134 </dd>
4135 </dl></div>
4136 <div class="paragraph"><p>The <a href="#_file"><strong><tt>file</tt></strong></a> commands that return 0/1 results are often used in
4137 conditional or looping commands, for example:</p></div>
4138 <div class="literalblock">
4139 <div class="content">
4140 <pre><tt>if {![file exists foo]} {
4141 error {bad file name}
4142 } else {
4144 }</tt></pre>
4145 </div></div>
4146 </div>
4147 <div class="sect2">
4148 <h3 id="_finalize">finalize</h3>
4149 <div class="paragraph"><p><tt><strong>finalize</strong> <em>reference ?command?</em></tt></p></div>
4150 <div class="paragraph"><p>If <tt><em>command</em></tt> is omitted, returns the finalizer command for the given reference.</p></div>
4151 <div class="paragraph"><p>Otherwise, sets a new finalizer command for the given reference. <tt><em>command</em></tt> may be
4152 the empty string to remove the current finalizer.</p></div>
4153 <div class="paragraph"><p>The reference must be a valid reference create with the <a href="#_ref"><strong><tt>ref</tt></strong></a>
4154 command.</p></div>
4155 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4156 </div>
4157 <div class="sect2">
4158 <h3 id="_flush">flush</h3>
4159 <div class="paragraph"><p><tt><strong>flush</strong> <em>fileId</em></tt></p></div>
4160 <div class="paragraph"><p><tt><em>fileId</em> <strong>flush</strong></tt></p></div>
4161 <div class="paragraph"><p>Flushes any output that has been buffered for <tt><em>fileId</em></tt>. <tt><em>fileId</em></tt> must
4162 have been the return value from a previous call to <a href="#_open"><strong><tt>open</tt></strong></a>, or it may be
4163 <tt>stdout</tt> or <tt>stderr</tt> to access one of the standard I/O streams; it must
4164 refer to a file that was opened for writing. This command returns an
4165 empty string.</p></div>
4166 </div>
4167 <div class="sect2">
4168 <h3 id="_for">for</h3>
4169 <div class="paragraph"><p><tt><strong>for</strong> <em>start test next body</em></tt></p></div>
4170 <div class="paragraph"><p><a href="#_for"><strong><tt>for</tt></strong></a> is a looping command, similar in structure to the C <a href="#_for"><strong><tt>for</tt></strong></a> statement.
4171 The <tt><em>start</em></tt>, <tt><em>next</em></tt>, and <tt><em>body</em></tt> arguments must be Tcl command strings,
4172 and <tt><em>test</em></tt> is an expression string.</p></div>
4173 <div class="paragraph"><p>The <a href="#_for"><strong><tt>for</tt></strong></a> command first invokes the Tcl interpreter to execute <tt><em>start</em></tt>.
4174 Then it repeatedly evaluates <tt><em>test</em></tt> as an expression; if the result is
4175 non-zero it invokes the Tcl interpreter on <tt><em>body</em></tt>, then invokes the Tcl
4176 interpreter on <tt><em>next</em></tt>, then repeats the loop. The command terminates
4177 when <tt><em>test</em></tt> evaluates to 0.</p></div>
4178 <div class="paragraph"><p>If a <a href="#_continue"><strong><tt>continue</tt></strong></a> command is invoked within <tt><em>body</em></tt> then any remaining
4179 commands in the current execution of <tt><em>body</em></tt> are skipped; processing
4180 continues by invoking the Tcl interpreter on <tt><em>next</em></tt>, then evaluating
4181 <tt><em>test</em></tt>, and so on.</p></div>
4182 <div class="paragraph"><p>If a <a href="#_break"><strong><tt>break</tt></strong></a> command is invoked within <tt><em>body</em></tt> or <tt><em>next</em></tt>, then the <a href="#_for"><strong><tt>for</tt></strong></a>
4183 command will return immediately.</p></div>
4184 <div class="paragraph"><p>The operation of <a href="#_break"><strong><tt>break</tt></strong></a> and <a href="#_continue"><strong><tt>continue</tt></strong></a> are similar to the corresponding
4185 statements in C.</p></div>
4186 <div class="paragraph"><p><a href="#_for"><strong><tt>for</tt></strong></a> returns an empty string.</p></div>
4187 </div>
4188 <div class="sect2">
4189 <h3 id="_foreach">foreach</h3>
4190 <div class="paragraph"><p><tt><strong>foreach</strong> <em>varName list body</em></tt></p></div>
4191 <div class="paragraph"><p><tt><strong>foreach</strong> <em>varList list ?varList2 list2 ...? body</em></tt></p></div>
4192 <div class="paragraph"><p>In this command, <tt><em>varName</em></tt> is the name of a variable, <tt><em>list</em></tt>
4193 is a list of values to assign to <tt><em>varName</em></tt>, and <tt><em>body</em></tt> is a
4194 collection of Tcl commands.</p></div>
4195 <div class="paragraph"><p>For each field in <tt><em>list</em></tt> (in order from left to right), <a href="#_foreach"><strong><tt>foreach</tt></strong></a> assigns
4196 the contents of the field to <tt><em>varName</em></tt> (as if the <a href="#_lindex"><strong><tt>lindex</tt></strong></a> command
4197 had been used to extract the field), then calls the Tcl interpreter to
4198 execute <tt><em>body</em></tt>.</p></div>
4199 <div class="paragraph"><p>If instead of being a simple name, <tt><em>varList</em></tt> is used, multiple assignments
4200 are made each time through the loop, one for each element of <tt><em>varList</em></tt>.</p></div>
4201 <div class="paragraph"><p>For example, if there are two elements in <tt><em>varList</em></tt> and six elements in
4202 the list, the loop will be executed three times.</p></div>
4203 <div class="paragraph"><p>If the length of the list doesn&#8217;t evenly divide by the number of elements
4204 in <tt><em>varList</em></tt>, the value of the remaining variables in the last iteration
4205 of the loop are undefined.</p></div>
4206 <div class="paragraph"><p>The <a href="#_break"><strong><tt>break</tt></strong></a> and <a href="#_continue"><strong><tt>continue</tt></strong></a> statements may be invoked inside <tt><em>body</em></tt>,
4207 with the same effect as in the <a href="#_for"><strong><tt>for</tt></strong></a> command.</p></div>
4208 <div class="paragraph"><p><a href="#_foreach"><strong><tt>foreach</tt></strong></a> returns an empty string.</p></div>
4209 </div>
4210 <div class="sect2">
4211 <h3 id="_format">format</h3>
4212 <div class="paragraph"><p><tt><strong>format</strong> <em>formatString ?arg ...?</em></tt></p></div>
4213 <div class="paragraph"><p>This command generates a formatted string in the same way as the
4214 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
4215 implementation). <tt><em>formatString</em></tt> indicates how to format
4216 the result, using <tt>%</tt> fields as in <em>sprintf</em>, and the additional
4217 arguments, if any, provide values to be substituted into the result.</p></div>
4218 <div class="paragraph"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
4219 man page for details. Each <tt><em>arg</em></tt> must match the expected type
4220 from the <tt>%</tt> field in <tt><em>formatString</em></tt>; the <a href="#_format"><strong><tt>format</tt></strong></a> command
4221 converts each argument to the correct type (floating, integer, etc.)
4222 before passing it to <em>sprintf</em> for formatting.</p></div>
4223 <div class="paragraph"><p>The only unusual conversion is for <tt>%c</tt>; in this case the argument
4224 must be a decimal string, which will then be converted to the corresponding
4225 ASCII character value.</p></div>
4226 <div class="paragraph"><p><a href="#_format"><strong><tt>format</tt></strong></a> does backslash substitution on its <tt><em>formatString</em></tt>
4227 argument, so backslash sequences in <tt><em>formatString</em></tt> will be handled
4228 correctly even if the argument is in braces.</p></div>
4229 <div class="paragraph"><p>The return value from <a href="#_format"><strong><tt>format</tt></strong></a> is the formatted string.</p></div>
4230 </div>
4231 <div class="sect2">
4232 <h3 id="_getref">getref</h3>
4233 <div class="paragraph"><p><tt><strong>getref</strong> <em>reference</em></tt></p></div>
4234 <div class="paragraph"><p>Returns the string associated with <tt><em>reference</em></tt>. The reference must
4235 be a valid reference create with the <a href="#_ref"><strong><tt>ref</tt></strong></a> command.</p></div>
4236 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4237 </div>
4238 <div class="sect2">
4239 <h3 id="_gets">gets</h3>
4240 <div class="paragraph"><p><tt><strong>gets</strong> <em>fileId ?varName?</em></tt></p></div>
4241 <div class="paragraph"><p><tt><em>fileId</em> <strong>gets</strong> <em>?varName?</em></tt></p></div>
4242 <div class="paragraph"><p>Reads the next line from the file given by <tt><em>fileId</em></tt> and discards
4243 the terminating newline character.</p></div>
4244 <div class="paragraph"><p>If <tt><em>varName</em></tt> is specified, then the line is placed in the variable
4245 by that name and the return value is a count of the number of characters
4246 read (not including the newline).</p></div>
4247 <div class="paragraph"><p>If the end of the file is reached before reading
4248 any characters then -1 is returned and <tt><em>varName</em></tt> is set to an
4249 empty string.</p></div>
4250 <div class="paragraph"><p>If <tt><em>varName</em></tt> is not specified then the return value will be
4251 the line (minus the newline character) or an empty string if
4252 the end of the file is reached before reading any characters.</p></div>
4253 <div class="paragraph"><p>An empty string will also be returned if a line contains no characters
4254 except the newline, so <a href="#_eof"><strong><tt>eof</tt></strong></a> may have to be used to determine
4255 what really happened.</p></div>
4256 <div class="paragraph"><p>If the last character in the file is not a newline character, then
4257 <a href="#_gets"><strong><tt>gets</tt></strong></a> behaves as if there were an additional newline character
4258 at the end of the file.</p></div>
4259 <div class="paragraph"><p><tt><em>fileId</em></tt> must be <tt>stdin</tt> or the return value from a previous
4260 call to <a href="#_open"><strong><tt>open</tt></strong></a>; it must refer to a file that was opened
4261 for reading.</p></div>
4262 </div>
4263 <div class="sect2">
4264 <h3 id="_glob">glob</h3>
4265 <div class="paragraph"><p><tt><strong>glob</strong> ?<strong>-nocomplain</strong>? <em>pattern ?pattern ...?</em></tt></p></div>
4266 <div class="paragraph"><p>This command performs filename globbing, using csh rules. The returned
4267 value from <a href="#_glob"><strong><tt>glob</tt></strong></a> is the list of expanded filenames.</p></div>
4268 <div class="paragraph"><p>If <tt>-nocomplain</tt> is specified as the first argument then an empty
4269 list may be returned; otherwise an error is returned if the expanded
4270 list is empty. The <tt>-nocomplain</tt> argument must be provided
4271 exactly: an abbreviation will not be accepted.</p></div>
4272 </div>
4273 <div class="sect2">
4274 <h3 id="_global">global</h3>
4275 <div class="paragraph"><p><tt><strong>global</strong> <em>varName ?varName ...?</em></tt></p></div>
4276 <div class="paragraph"><p>This command is ignored unless a Tcl procedure is being interpreted.
4277 If so, then it declares each given <tt><em>varName</em></tt> to be a global variable
4278 rather than a local one. For the duration of the current procedure
4279 (and only while executing in the current procedure), any reference to
4280 <tt><em>varName</em></tt> will be bound to a global variable instead
4281 of a local one.</p></div>
4282 <div class="paragraph"><p>An alternative to using <a href="#_global"><strong><tt>global</tt></strong></a> is to use the <tt>::</tt> prefix
4283 to explicitly name a variable in the global scope.</p></div>
4284 </div>
4285 <div class="sect2">
4286 <h3 id="_if">if</h3>
4287 <div class="paragraph"><p><tt><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>?</tt></p></div>
4288 <div class="paragraph"><p>The <a href="#_if"><strong><tt>if</tt></strong></a> command evaluates <tt><em>expr1</em></tt> as an expression (in the same way
4289 that <a href="#_expr"><strong><tt>expr</tt></strong></a> evaluates its argument). The value of the expression must
4290 be numeric; if it is non-zero then <tt><em>body1</em></tt> is executed by passing it to
4291 the Tcl interpreter.</p></div>
4292 <div class="paragraph"><p>Otherwise <tt><em>expr2</em></tt> is evaluated as an expression and if it is non-zero
4293 then <tt><em>body2</em></tt> is executed, and so on.</p></div>
4294 <div class="paragraph"><p>If none of the expressions evaluates to non-zero then <tt><em>bodyN</em></tt> is executed.</p></div>
4295 <div class="paragraph"><p>The <tt>then</tt> and <tt>else</tt> arguments are optional "noise words" to make the
4296 command easier to read.</p></div>
4297 <div class="paragraph"><p>There may be any number of <tt>elseif</tt> clauses, including zero. <tt><em>bodyN</em></tt>
4298 may also be omitted as long as <tt>else</tt> is omitted too.</p></div>
4299 <div class="paragraph"><p>The return value from the command is the result of the body script that
4300 was executed, or an empty string if none of the expressions was non-zero
4301 and there was no <tt><em>bodyN</em></tt>.</p></div>
4302 </div>
4303 <div class="sect2">
4304 <h3 id="_incr">incr</h3>
4305 <div class="paragraph"><p><tt><strong>incr</strong> <em>varName ?increment?</em></tt></p></div>
4306 <div class="paragraph"><p>Increment the value stored in the variable whose name is <tt><em>varName</em></tt>.
4307 The value of the variable must be integral.</p></div>
4308 <div class="paragraph"><p>If <tt><em>increment</em></tt> is supplied then its value (which must be an
4309 integer) is added to the value of variable <tt><em>varName</em></tt>; otherwise
4310 1 is added to <tt><em>varName</em></tt>.</p></div>
4311 <div class="paragraph"><p>The new value is stored as a decimal string in variable <tt><em>varName</em></tt>
4312 and also returned as result.</p></div>
4313 <div class="paragraph"><p>If the variable does not exist, the variable is implicitly created
4314 and set to <tt>0</tt> first.</p></div>
4315 </div>
4316 <div class="sect2">
4317 <h3 id="_info">info</h3>
4318 <div class="dlist"><dl>
4319 <dt class="hdlist1">
4320 <tt><strong>info</strong> <em>option ?arg...?</em></tt>
4321 </dt>
4322 <dd>
4324 Provide information about various internals to the Tcl interpreter.
4325 The legal <tt><em>option</em></tt>'s (which may be abbreviated) are:
4326 </p>
4327 </dd>
4328 <dt class="hdlist1">
4329 <tt><strong>info args</strong> <em>procname</em></tt>
4330 </dt>
4331 <dd>
4333 Returns a list containing the names of the arguments to procedure
4334 <tt><em>procname</em></tt>, in order. <tt><em>procname</em></tt> must be the name of a
4335 Tcl command procedure.
4336 </p>
4337 </dd>
4338 <dt class="hdlist1">
4339 <tt><strong>info body</strong> <em>procname</em></tt>
4340 </dt>
4341 <dd>
4343 Returns the body of procedure <tt><em>procname</em></tt>. <tt><em>procname</em></tt> must be
4344 the name of a Tcl command procedure.
4345 </p>
4346 </dd>
4347 <dt class="hdlist1">
4348 <tt><strong>info channels</strong></tt>
4349 </dt>
4350 <dd>
4352 Returns a list of all open file handles from <a href="#_open"><strong><tt>open</tt></strong></a> or <a href="#_socket"><strong><tt>socket</tt></strong></a>
4353 </p>
4354 </dd>
4355 <dt class="hdlist1">
4356 <tt><strong>info commands</strong> ?<em>pattern</em>?</tt>
4357 </dt>
4358 <dd>
4360 If <tt><em>pattern</em></tt> isn&#8217;t specified, returns a list of names of all the
4361 Tcl commands, including both the built-in commands written in C and
4362 the command procedures defined using the <a href="#_proc"><strong><tt>proc</tt></strong></a> command.
4363 If <tt><em>pattern</em></tt> is specified, only those names matching <tt><em>pattern</em></tt>
4364 are returned. Matching is determined using the same rules as for
4365 <a href="#_string"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4366 </p>
4367 </dd>
4368 <dt class="hdlist1">
4369 <tt><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</tt>
4370 </dt>
4371 <dd>
4373 Returns 1 if <tt><em>command</em></tt> is a complete Tcl command in the sense of
4374 having no unclosed quotes, braces, brackets or array element names,
4375 If the command doesn&#8217;t appear to be complete then 0 is returned.
4376 This command is typically used in line-oriented input environments
4377 to allow users to type in commands that span multiple lines; if the
4378 command isn&#8217;t complete, the script can delay evaluating it until additional
4379 lines have been typed to complete the command. If <tt><em>varName</em></tt> is specified, the
4380 missing character is stored in the variable with that name.
4381 </p>
4382 </dd>
4383 <dt class="hdlist1">
4384 <tt><strong>info exists</strong> <em>varName</em></tt>
4385 </dt>
4386 <dd>
4388 Returns <em>1</em> if the variable named <tt><em>varName</em></tt> exists in the
4389 current context (either as a global or local variable), returns <em>0</em>
4390 otherwise.
4391 </p>
4392 </dd>
4393 <dt class="hdlist1">
4394 <tt><strong>info frame</strong> ?<em>number</em>?</tt>
4395 </dt>
4396 <dd>
4398 If <tt><em>number</em></tt> is not specified, this command returns a number
4399 which is the same result as <a href="#_info"><strong><tt>info</tt></strong></a> <tt>level</tt> - the current stack frame level.
4400 If <tt><em>number</em></tt> is specified, then the result is a list consisting of the procedure,
4401 filename and line number for the procedure call at level <tt><em>number</em></tt> on the stack.
4402 If <tt><em>number</em></tt> is positive then it selects a particular stack level (1 refers
4403 to the top-most active procedure, 2 to the procedure it called, and
4404 so on); otherwise it gives a level relative to the current level
4405 (0 refers to the current procedure, -1 to its caller, and so on).
4406 The level has an identical meaning to <a href="#_info"><strong><tt>info</tt></strong></a> <tt>level</tt>.
4407 </p>
4408 </dd>
4409 <dt class="hdlist1">
4410 <tt><strong>info globals</strong> ?<em>pattern</em>?</tt>
4411 </dt>
4412 <dd>
4414 If <tt><em>pattern</em></tt> isn&#8217;t specified, returns a list of all the names
4415 of currently-defined global variables.
4416 If <tt><em>pattern</em></tt> is specified, only those names matching <tt><em>pattern</em></tt>
4417 are returned. Matching is determined using the same rules as for
4418 <a href="#_string"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4419 </p>
4420 </dd>
4421 <dt class="hdlist1">
4422 <tt><strong>info hostname</strong></tt>
4423 </dt>
4424 <dd>
4426 An alias for <a href="#cmd_1"><strong><tt>os.gethostname</tt></strong></a> for compatibility with Tcl 6.x
4427 </p>
4428 </dd>
4429 <dt class="hdlist1">
4430 <tt><strong>info level</strong> ?<em>number</em>?</tt>
4431 </dt>
4432 <dd>
4434 If <tt><em>number</em></tt> is not specified, this command returns a number
4435 giving the stack level of the invoking procedure, or 0 if the
4436 command is invoked at top-level. If <tt><em>number</em></tt> is specified,
4437 then the result is a list consisting of the name and arguments for the
4438 procedure call at level <tt><em>number</em></tt> on the stack. If <tt><em>number</em></tt>
4439 is positive then it selects a particular stack level (1 refers
4440 to the top-most active procedure, 2 to the procedure it called, and
4441 so on); otherwise it gives a level relative to the current level
4442 (0 refers to the current procedure, -1 to its caller, and so on).
4443 See the <a href="#_uplevel"><strong><tt>uplevel</tt></strong></a> command for more information on what stack
4444 levels mean.
4445 </p>
4446 </dd>
4447 <dt class="hdlist1">
4448 <tt><strong>info locals</strong> ?<em>pattern</em>?</tt>
4449 </dt>
4450 <dd>
4452 If <tt><em>pattern</em></tt> isn&#8217;t specified, returns a list of all the names
4453 of currently-defined local variables, including arguments to the
4454 current procedure, if any. Variables defined with the <a href="#_global"><strong><tt>global</tt></strong></a>
4455 and <a href="#_upvar"><strong><tt>upvar</tt></strong></a> commands will not be returned. If <tt><em>pattern</em></tt> is
4456 specified, only those names matching <tt><em>pattern</em></tt> are returned.
4457 Matching is determined using the same rules as for <a href="#_string"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4458 </p>
4459 </dd>
4460 <dt class="hdlist1">
4461 <tt><strong>info nameofexecutable</strong></tt>
4462 </dt>
4463 <dd>
4465 Returns the name of the binary file from which the application
4466 was invoked. A full path will be returned, unless the path
4467 can&#8217;t be determined, in which case the empty string will be returned.
4468 </p>
4469 </dd>
4470 <dt class="hdlist1">
4471 <tt><strong>info procs</strong> ?<em>pattern</em>?</tt>
4472 </dt>
4473 <dd>
4475 If <tt><em>pattern</em></tt> isn&#8217;t specified, returns a list of all the
4476 names of Tcl command procedures.
4477 If <tt><em>pattern</em></tt> is specified, only those names matching <tt><em>pattern</em></tt>
4478 are returned. Matching is determined using the same rules as for
4479 <a href="#_string"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4480 </p>
4481 </dd>
4482 <dt class="hdlist1">
4483 <tt><strong>info references</strong></tt>
4484 </dt>
4485 <dd>
4487 Returns a list of all references which have not yet been garbage
4488 collected.
4489 </p>
4490 </dd>
4491 <dt class="hdlist1">
4492 <tt><strong>info returncodes</strong> ?<em>code</em>?</tt>
4493 </dt>
4494 <dd>
4496 Returns a list representing the mapping of standard return codes
4497 to names. e.g. <tt>{0 ok 1 error 2 return ...}</tt>. If a code is given,
4498 instead returns the name for the given code.
4499 </p>
4500 </dd>
4501 <dt class="hdlist1">
4502 <tt><strong>info script</strong></tt>
4503 </dt>
4504 <dd>
4506 If a Tcl script file is currently being evaluated (i.e. there is a
4507 call to <em>Jim_EvalFile</em> active or there is an active invocation
4508 of the <a href="#_source"><strong><tt>source</tt></strong></a> command), then this command returns the name
4509 of the innermost file being processed. Otherwise the command returns an
4510 empty string.
4511 </p>
4512 </dd>
4513 <dt class="hdlist1">
4514 <tt><strong>info source</strong> <em>script</em></tt>
4515 </dt>
4516 <dd>
4518 Returns the original source location of the given script as a list of
4519 <tt>{filename linenumber}</tt>. If the source location can&#8217;t be determined, the
4520 list <tt>{{} 0}</tt> is returned.
4521 </p>
4522 </dd>
4523 <dt class="hdlist1">
4524 <tt><strong>info stacktrace</strong></tt>
4525 </dt>
4526 <dd>
4528 After an error is caught with <a href="#_catch"><strong><tt>catch</tt></strong></a>, returns the stack trace as a list
4529 of <tt>{procedure filename line ...}</tt>.
4530 </p>
4531 </dd>
4532 <dt class="hdlist1">
4533 <tt><strong>info version</strong></tt>
4534 </dt>
4535 <dd>
4537 Returns the version number for this version of Jim in the form <tt><strong>x.yy</strong></tt>.
4538 </p>
4539 </dd>
4540 <dt class="hdlist1">
4541 <tt><strong>info vars</strong> ?<em>pattern</em>?</tt>
4542 </dt>
4543 <dd>
4545 If <tt><em>pattern</em></tt> isn&#8217;t specified,
4546 returns a list of all the names of currently-visible variables, including
4547 both locals and currently-visible globals.
4548 If <tt><em>pattern</em></tt> is specified, only those names matching <tt><em>pattern</em></tt>
4549 are returned. Matching is determined using the same rules as for
4550 <a href="#_string"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4551 </p>
4552 </dd>
4553 </dl></div>
4554 </div>
4555 <div class="sect2">
4556 <h3 id="_join">join</h3>
4557 <div class="paragraph"><p><tt><strong>join</strong> <em>list ?joinString?</em></tt></p></div>
4558 <div class="paragraph"><p>The <tt><em>list</em></tt> argument must be a valid Tcl list. This command returns the
4559 string formed by joining all of the elements of <tt><em>list</em></tt> together with
4560 <tt><em>joinString</em></tt> separating each adjacent pair of elements.</p></div>
4561 <div class="paragraph"><p>The <tt><em>joinString</em></tt> argument defaults to a space character.</p></div>
4562 </div>
4563 <div class="sect2">
4564 <h3 id="_kill">kill</h3>
4565 <div class="paragraph"><p><tt><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></tt></p></div>
4566 <div class="paragraph"><p>Sends the given signal to the process identified by <tt><em>pid</em></tt>.</p></div>
4567 <div class="paragraph"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4568 <div class="ulist"><ul>
4569 <li>
4571 <tt>TERM</tt>
4572 </p>
4573 </li>
4574 <li>
4576 <tt>SIGTERM</tt>
4577 </p>
4578 </li>
4579 <li>
4581 <tt>-TERM</tt>
4582 </p>
4583 </li>
4584 <li>
4586 <tt>15</tt>
4587 </p>
4588 </li>
4589 <li>
4591 <tt>-15</tt>
4592 </p>
4593 </li>
4594 </ul></div>
4595 <div class="paragraph"><p>The signal name may be in either upper or lower case.</p></div>
4596 <div class="paragraph"><p>The special signal name <tt>-0</tt> simply checks that a signal <tt><em>could</em></tt> be sent.</p></div>
4597 <div class="paragraph"><p>If no signal is specified, SIGTERM is used.</p></div>
4598 <div class="paragraph"><p>An error is raised if the signal could not be delivered.</p></div>
4599 </div>
4600 <div class="sect2">
4601 <h3 id="_lambda_2">lambda</h3>
4602 <div class="paragraph"><p><tt><strong>lambda</strong> <em>args ?statics? body</em></tt></p></div>
4603 <div class="paragraph"><p>The <a href="#_lambda"><strong><tt>lambda</tt></strong></a> command is identical to <a href="#_proc"><strong><tt>proc</tt></strong></a>, except rather than
4604 creating a named procedure, it creates an anonymous procedure and returns
4605 the name of the procedure.</p></div>
4606 <div class="paragraph"><p>See <a href="#_proc"><strong><tt>proc</tt></strong></a> and GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4607 </div>
4608 <div class="sect2">
4609 <h3 id="_lappend">lappend</h3>
4610 <div class="paragraph"><p><tt><strong>lappend</strong> <em>varName value ?value value ...?</em></tt></p></div>
4611 <div class="paragraph"><p>Treat the variable given by <tt><em>varName</em></tt> as a list and append each of
4612 the <tt><em>value</em></tt> arguments to that list as a separate element, with spaces
4613 between elements.</p></div>
4614 <div class="paragraph"><p>If <tt><em>varName</em></tt> doesn&#8217;t exist, it is created as a list with elements given
4615 by the <tt><em>value</em></tt> arguments. <a href="#_lappend"><strong><tt>lappend</tt></strong></a> is similar to <a href="#_append"><strong><tt>append</tt></strong></a> except that
4616 each <tt><em>value</em></tt> is appended as a list element rather than raw text.</p></div>
4617 <div class="paragraph"><p>This command provides a relatively efficient way to build up large lists.
4618 For example,</p></div>
4619 <div class="literalblock">
4620 <div class="content">
4621 <pre><tt>lappend a $b</tt></pre>
4622 </div></div>
4623 <div class="paragraph"><p>is much more efficient than</p></div>
4624 <div class="literalblock">
4625 <div class="content">
4626 <pre><tt>set a [concat $a [list $b]]</tt></pre>
4627 </div></div>
4628 <div class="paragraph"><p>when <tt>$a</tt> is long.</p></div>
4629 </div>
4630 <div class="sect2">
4631 <h3 id="_lassign">lassign</h3>
4632 <div class="paragraph"><p><tt><strong>lassign</strong> <em>list varName ?varName ...?</em></tt></p></div>
4633 <div class="paragraph"><p>This command treats the value <tt><em>list</em></tt> as a list and assigns successive elements from that list to
4634 the variables given by the <tt><em>varName</em></tt> arguments in order. If there are more variable names than
4635 list elements, the remaining variables are set to the empty string. If there are more list ele-
4636 ments than variables, a list of unassigned elements is returned.</p></div>
4637 <div class="literalblock">
4638 <div class="content">
4639 <pre><tt>jim&gt; lassign {1 2 3} a b; puts a=$a,b=$b
4641 a=1,b=2</tt></pre>
4642 </div></div>
4643 </div>
4644 <div class="sect2">
4645 <h3 id="_local">local</h3>
4646 <div class="paragraph"><p><tt><strong>local</strong> <em>args</em></tt></p></div>
4647 <div class="paragraph"><p>Executes it&#8217;s arguments as a command (per <a href="#_eval"><strong><tt>eval</tt></strong></a>) and considers the return
4648 value to be a procedure name, which is marked as having local scope.
4649 This means that when the current procedure exits, the specified
4650 procedure is deleted. This can be useful with <a href="#_lambda"><strong><tt>lambda</tt></strong></a> or simply
4651 local procedures.</p></div>
4652 <div class="paragraph"><p>In addition, if a command already exists with the same name,
4653 the existing command will be kept rather than deleted, and may be called
4654 via <a href="#_upcall"><strong><tt>upcall</tt></strong></a>. The previous command will be restored when the current
4655 command is deleted. See <a href="#_upcall"><strong><tt>upcall</tt></strong></a> for more details.</p></div>
4656 <div class="paragraph"><p>In this example, a local procedure is created. Note that the procedure
4657 continues to have global scope while it is active.</p></div>
4658 <div class="literalblock">
4659 <div class="content">
4660 <pre><tt>proc outer {} {
4661 # proc ... returns "inner" which is marked local
4662 local proc inner {} {
4663 # will be deleted when 'outer' exits
4664 }</tt></pre>
4665 </div></div>
4666 <div class="literalblock">
4667 <div class="content">
4668 <pre><tt> inner
4670 }</tt></pre>
4671 </div></div>
4672 <div class="paragraph"><p>In this example, the lambda is deleted at the end of the procedure rather
4673 than waiting until garbage collection.</p></div>
4674 <div class="literalblock">
4675 <div class="content">
4676 <pre><tt>proc outer {} {
4677 set x [lambda inner {args} {
4678 # will be deleted when 'outer' exits
4680 # Use 'function' here which simply returns $x
4681 local function $x</tt></pre>
4682 </div></div>
4683 <div class="literalblock">
4684 <div class="content">
4685 <pre><tt> $x ...
4687 }</tt></pre>
4688 </div></div>
4689 </div>
4690 <div class="sect2">
4691 <h3 id="_loop">loop</h3>
4692 <div class="paragraph"><p><tt><strong>loop</strong> <em>var first limit ?incr? body</em></tt></p></div>
4693 <div class="paragraph"><p>Similar to <a href="#_for"><strong><tt>for</tt></strong></a> except simpler and possibly more efficient.
4694 With a positive increment, equivalent to:</p></div>
4695 <div class="literalblock">
4696 <div class="content">
4697 <pre><tt>for {set var $first} {$var &lt; $limit} {incr var $incr} $body</tt></pre>
4698 </div></div>
4699 <div class="paragraph"><p>If <tt><em>incr</em></tt> is not specified, 1 is used.
4700 Note that setting the loop variable inside the loop does not
4701 affect the loop count.</p></div>
4702 </div>
4703 <div class="sect2">
4704 <h3 id="_lindex">lindex</h3>
4705 <div class="paragraph"><p><tt><strong>lindex</strong> <em>list index</em></tt></p></div>
4706 <div class="paragraph"><p>Treats <tt><em>list</em></tt> as a Tcl list and returns element <tt><em>index</em></tt> from it
4707 (0 refers to the first element of the list).
4708 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>index</em></tt>.</p></div>
4709 <div class="paragraph"><p>In extracting the element, <tt><em>lindex</em></tt> observes the same rules concerning
4710 braces and quotes and backslashes as the Tcl command interpreter; however,
4711 variable substitution and command substitution do not occur.</p></div>
4712 <div class="paragraph"><p>If <tt><em>index</em></tt> is negative or greater than or equal to the number of elements
4713 in <tt><em>value</em></tt>, then an empty string is returned.</p></div>
4714 </div>
4715 <div class="sect2">
4716 <h3 id="_linsert">linsert</h3>
4717 <div class="paragraph"><p><tt><strong>linsert</strong> <em>list index element ?element element ...?</em></tt></p></div>
4718 <div class="paragraph"><p>This command produces a new list from <tt><em>list</em></tt> by inserting all
4719 of the <tt><em>element</em></tt> arguments just before the element <tt><em>index</em></tt>
4720 of <tt><em>list</em></tt>. Each <tt><em>element</em></tt> argument will become
4721 a separate element of the new list. If <tt><em>index</em></tt> is less than
4722 or equal to zero, then the new elements are inserted at the
4723 beginning of the list. If <tt><em>index</em></tt> is greater than or equal
4724 to the number of elements in the list, then the new elements are
4725 appended to the list.</p></div>
4726 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>index</em></tt>.</p></div>
4727 </div>
4728 <div class="sect2">
4729 <h3 id="_list">list</h3>
4730 <div class="paragraph"><p><tt><strong>list</strong> <em>arg ?arg ...?</em></tt></p></div>
4731 <div class="paragraph"><p>This command returns a list comprised of all the arguments, <tt><em>arg</em></tt>. Braces
4732 and backslashes get added as necessary, so that the <a href="#_lindex"><strong><tt>lindex</tt></strong></a> command
4733 may be used on the result to re-extract the original arguments, and also
4734 so that <a href="#_eval"><strong><tt>eval</tt></strong></a> may be used to execute the resulting list, with
4735 <tt><em>arg1</em></tt> comprising the command&#8217;s name and the other args comprising
4736 its arguments. <a href="#_list"><strong><tt>list</tt></strong></a> produces slightly different results than
4737 <a href="#_concat"><strong><tt>concat</tt></strong></a>: <a href="#_concat"><strong><tt>concat</tt></strong></a> removes one level of grouping before forming
4738 the list, while <a href="#_list"><strong><tt>list</tt></strong></a> works directly from the original arguments.
4739 For example, the command</p></div>
4740 <div class="literalblock">
4741 <div class="content">
4742 <pre><tt>list a b {c d e} {f {g h}}</tt></pre>
4743 </div></div>
4744 <div class="paragraph"><p>will return</p></div>
4745 <div class="literalblock">
4746 <div class="content">
4747 <pre><tt>a b {c d e} {f {g h}}</tt></pre>
4748 </div></div>
4749 <div class="paragraph"><p>while <a href="#_concat"><strong><tt>concat</tt></strong></a> with the same arguments will return</p></div>
4750 <div class="literalblock">
4751 <div class="content">
4752 <pre><tt>a b c d e f {g h}</tt></pre>
4753 </div></div>
4754 </div>
4755 <div class="sect2">
4756 <h3 id="_llength">llength</h3>
4757 <div class="paragraph"><p><tt><strong>llength</strong> <em>list</em></tt></p></div>
4758 <div class="paragraph"><p>Treats <tt><em>list</em></tt> as a list and returns a decimal string giving
4759 the number of elements in it.</p></div>
4760 </div>
4761 <div class="sect2">
4762 <h3 id="_lset">lset</h3>
4763 <div class="paragraph"><p><tt><strong>lset</strong> <em>varName ?index ..? newValue</em></tt></p></div>
4764 <div class="paragraph"><p>Sets an element in a list.</p></div>
4765 <div class="paragraph"><p>The <a href="#_lset"><strong><tt>lset</tt></strong></a> command accepts a parameter, <tt><em>varName</em></tt>, which it interprets
4766 as the name of a variable containing a Tcl list. It also accepts
4767 zero or more indices into the list. Finally, it accepts a new value
4768 for an element of varName. If no indices are presented, the command
4769 takes the form:</p></div>
4770 <div class="literalblock">
4771 <div class="content">
4772 <pre><tt>lset varName newValue</tt></pre>
4773 </div></div>
4774 <div class="paragraph"><p>In this case, newValue replaces the old value of the variable
4775 varName.</p></div>
4776 <div class="paragraph"><p>When presented with a single index, the <a href="#_lset"><strong><tt>lset</tt></strong></a> command
4777 treats the content of the varName variable as a Tcl list. It addresses
4778 the index&#8217;th element in it (0 refers to the first element of the
4779 list). When interpreting the list, <a href="#_lset"><strong><tt>lset</tt></strong></a> observes the same rules
4780 concerning braces and quotes and backslashes as the Tcl command
4781 interpreter; however, variable substitution and command substitution
4782 do not occur. The command constructs a new list in which the
4783 designated element is replaced with newValue. This new list is
4784 stored in the variable varName, and is also the return value from
4785 the <a href="#_lset"><strong><tt>lset</tt></strong></a> command.</p></div>
4786 <div class="paragraph"><p>If index is negative or greater than or equal to the number of
4787 elements in $varName, then an error occurs.</p></div>
4788 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>index</em></tt>.</p></div>
4789 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
4790 used in turn to address an element within a sublist designated by
4791 the previous indexing operation, allowing the script to alter
4792 elements in sublists. The command,</p></div>
4793 <div class="literalblock">
4794 <div class="content">
4795 <pre><tt>lset a 1 2 newValue</tt></pre>
4796 </div></div>
4797 <div class="paragraph"><p>replaces element 2 of sublist 1 with <tt><em>newValue</em></tt>.</p></div>
4798 <div class="paragraph"><p>The integer appearing in each index argument must be greater than
4799 or equal to zero. The integer appearing in each index argument must
4800 be strictly less than the length of the corresponding list. In other
4801 words, the <a href="#_lset"><strong><tt>lset</tt></strong></a> command cannot change the size of a list. If an
4802 index is outside the permitted range, an error is reported.</p></div>
4803 </div>
4804 <div class="sect2">
4805 <h3 id="_lmap">lmap</h3>
4806 <div class="paragraph"><p><tt><strong>lmap</strong> <em>varName list body</em></tt></p></div>
4807 <div class="paragraph"><p><tt><strong>lmap</strong> <em>varList list ?varList2 list2 ...? body</em></tt></p></div>
4808 <div class="paragraph"><p><a href="#_lmap"><strong><tt>lmap</tt></strong></a> is a "collecting" <a href="#_foreach"><strong><tt>foreach</tt></strong></a> which returns a list of its results.</p></div>
4809 <div class="paragraph"><p>For example:</p></div>
4810 <div class="literalblock">
4811 <div class="content">
4812 <pre><tt>jim&gt; lmap i {1 2 3 4 5} {expr $i*$i}
4813 1 4 9 16 25
4814 jim&gt; lmap a {1 2 3} b {A B C} {list $a $b}
4815 {1 A} {2 B} {3 C}</tt></pre>
4816 </div></div>
4817 <div class="paragraph"><p>If the body invokes <a href="#_continue"><strong><tt>continue</tt></strong></a>, no value is added for this iteration.
4818 If the body invokes <a href="#_break"><strong><tt>break</tt></strong></a>, the loop ends and no more values are added.</p></div>
4819 </div>
4820 <div class="sect2">
4821 <h3 id="_load">load</h3>
4822 <div class="paragraph"><p><tt><strong>load</strong> <em>filename</em></tt></p></div>
4823 <div class="paragraph"><p>Loads the dynamic extension, <tt><em>filename</em></tt>. Generally the filename should have
4824 the extension <tt>.so</tt>. The initialisation function for the module must be based
4825 on the name of the file. For example loading <tt>hwaccess.so</tt> will invoke
4826 the initialisation function, <tt>Jim_hwaccessInit</tt>. Normally the <a href="#_load"><strong><tt>load</tt></strong></a> command
4827 should not be used directly. Instead it is invoked automatically by <a href="#_package"><strong><tt>package</tt></strong></a> <tt>require</tt>.</p></div>
4828 </div>
4829 <div class="sect2">
4830 <h3 id="_lrange">lrange</h3>
4831 <div class="paragraph"><p><tt><strong>lrange</strong> <em>list first last</em></tt></p></div>
4832 <div class="paragraph"><p><tt><em>list</em></tt> must be a valid Tcl list. This command will return a new
4833 list consisting of elements <tt><em>first</em></tt> through <tt><em>last</em></tt>, inclusive.</p></div>
4834 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>first</em></tt> and <tt><em>last</em></tt>.</p></div>
4835 <div class="paragraph"><p>If <tt><em>last</em></tt> is greater than or equal to the number of elements
4836 in the list, then it is treated as if it were <tt>end</tt>.</p></div>
4837 <div class="paragraph"><p>If <tt><em>first</em></tt> is greater than <tt><em>last</em></tt> then an empty string
4838 is returned.</p></div>
4839 <div class="paragraph"><p>Note: <tt>"<a href="#_lrange"><strong><tt>lrange</tt></strong></a> <em>list first first</em>"</tt> does not always produce the
4840 same result as <tt>"<a href="#_lindex"><strong><tt>lindex</tt></strong></a> <em>list first</em>"</tt> (although it often does
4841 for simple fields that aren&#8217;t enclosed in braces); it does, however,
4842 produce exactly the same results as <tt>"<a href="#_list"><strong><tt>list</tt></strong></a> [<a href="#_lindex"><strong><tt>lindex</tt></strong></a> <em>list first</em>]"</tt></p></div>
4843 </div>
4844 <div class="sect2">
4845 <h3 id="_lreplace">lreplace</h3>
4846 <div class="paragraph"><p><tt><strong>lreplace</strong> <em>list first last ?element element ...?</em></tt></p></div>
4847 <div class="paragraph"><p>Returns a new list formed by replacing one or more elements of
4848 <tt><em>list</em></tt> with the <tt><em>element</em></tt> arguments.</p></div>
4849 <div class="paragraph"><p><tt><em>first</em></tt> gives the index in <tt><em>list</em></tt> of the first element
4850 to be replaced.</p></div>
4851 <div class="paragraph"><p>If <tt><em>first</em></tt> is less than zero then it refers to the first
4852 element of <tt><em>list</em></tt>; the element indicated by <tt><em>first</em></tt>
4853 must exist in the list.</p></div>
4854 <div class="paragraph"><p><tt><em>last</em></tt> gives the index in <tt><em>list</em></tt> of the last element
4855 to be replaced; it must be greater than or equal to <tt><em>first</em></tt>.</p></div>
4856 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>first</em></tt> and <tt><em>last</em></tt>.</p></div>
4857 <div class="paragraph"><p>The <tt><em>element</em></tt> arguments specify zero or more new arguments to
4858 be added to the list in place of those that were deleted.</p></div>
4859 <div class="paragraph"><p>Each <tt><em>element</em></tt> argument will become a separate element of
4860 the list.</p></div>
4861 <div class="paragraph"><p>If no <tt><em>element</em></tt> arguments are specified, then the elements
4862 between <tt><em>first</em></tt> and <tt><em>last</em></tt> are simply deleted.</p></div>
4863 </div>
4864 <div class="sect2">
4865 <h3 id="_lrepeat">lrepeat</h3>
4866 <div class="paragraph"><p><tt><strong>lrepeat</strong> <em>number element1 ?element2 ...?</em></tt></p></div>
4867 <div class="paragraph"><p>Build a list by repeating elements <tt><em>number</em></tt> times (which must be
4868 a positive integer).</p></div>
4869 <div class="literalblock">
4870 <div class="content">
4871 <pre><tt>jim&gt; lrepeat 3 a b
4872 a b a b a b</tt></pre>
4873 </div></div>
4874 </div>
4875 <div class="sect2">
4876 <h3 id="_lreverse">lreverse</h3>
4877 <div class="paragraph"><p><tt><strong>lreverse</strong> <em>list</em></tt></p></div>
4878 <div class="paragraph"><p>Returns the list in reverse order.</p></div>
4879 <div class="literalblock">
4880 <div class="content">
4881 <pre><tt>jim&gt; lreverse {1 2 3}
4882 3 2 1</tt></pre>
4883 </div></div>
4884 </div>
4885 <div class="sect2">
4886 <h3 id="_lsearch">lsearch</h3>
4887 <div class="paragraph"><p><tt><strong>lsearch</strong> <em>?options? list pattern</em></tt></p></div>
4888 <div class="paragraph"><p>This command searches the elements <tt><em>list</em></tt> to see if one of them matches <tt><em>pattern</em></tt>. If so, the
4889 command returns the index of the first matching element (unless the options -all, -inline or -bool are
4890 specified.) If not, the command returns -1. The option arguments indicates how the elements of
4891 the list are to be matched against pattern and must have one of the values below:</p></div>
4892 <div class="paragraph"><p><strong>Note</strong> that this command is different from Tcl in that default match type is <tt>-exact</tt> rather than <tt>-glob</tt>.</p></div>
4893 <div class="dlist"><dl>
4894 <dt class="hdlist1">
4895 <tt><em>-exact</em></tt>
4896 </dt>
4897 <dd>
4899 <tt><em>pattern</em></tt> is a literal string that is compared for exact equality against each list element.
4900 This is the default.
4901 </p>
4902 </dd>
4903 <dt class="hdlist1">
4904 <tt><em>-glob</em></tt>
4905 </dt>
4906 <dd>
4908 <tt><em>pattern</em></tt> is a glob-style pattern which is matched against each list element using the same
4909 rules as the string match command.
4910 </p>
4911 </dd>
4912 <dt class="hdlist1">
4913 <tt><em>-regexp</em></tt>
4914 </dt>
4915 <dd>
4917 <tt><em>pattern</em></tt> is treated as a regular expression and matched against each list element using
4918 the rules described by <a href="#_regexp"><strong><tt>regexp</tt></strong></a>.
4919 </p>
4920 </dd>
4921 <dt class="hdlist1">
4922 <tt><em>-all</em></tt>
4923 </dt>
4924 <dd>
4926 Changes the result to be the list of all matching indices (or all matching values if
4927 <tt>-inline</tt> is specified as well). If indices are returned, the indices will be in numeric
4928 order. If values are returned, the order of the values will be the order of those values
4929 within the input list.
4930 </p>
4931 </dd>
4932 <dt class="hdlist1">
4933 <tt><em>-inline</em></tt>
4934 </dt>
4935 <dd>
4937 The matching value is returned instead of its index (or an empty string if no value
4938 matches). If <tt>-all</tt> is also specified, then the result of the command is the list of all
4939 values that matched. The <tt>-inline</tt> and +-bool' options are mutually exclusive.
4940 </p>
4941 </dd>
4942 <dt class="hdlist1">
4943 <tt><em>-bool</em></tt>
4944 </dt>
4945 <dd>
4947 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <tt>-all</tt> is also specified,
4948 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
4949 the corresponding element matches. The <tt>-inline</tt> and <tt>-bool</tt> options are mutually exclusive.
4950 </p>
4951 </dd>
4952 <dt class="hdlist1">
4953 <tt><em>-not</em></tt>
4954 </dt>
4955 <dd>
4957 This negates the sense of the match, returning the index (or value
4958 if <tt>-inline</tt> is specified) of the first non-matching value in the
4959 list. If <tt>-bool</tt> is also specified, the <em>0</em> will be returned if a
4960 match is found, or <em>1</em> otherwise. If <tt>-all</tt> is also specified,
4961 non-matches will be returned rather than matches.
4962 </p>
4963 </dd>
4964 <dt class="hdlist1">
4965 <tt><em>-nocase</em></tt>
4966 </dt>
4967 <dd>
4969 Causes comparisons to be handled in a case-insensitive manner.
4970 </p>
4971 </dd>
4972 </dl></div>
4973 </div>
4974 <div class="sect2">
4975 <h3 id="_lsort">lsort</h3>
4976 <div class="paragraph"><p><tt><strong>lsort</strong> ?<strong>-index</strong> <em>listindex</em>? ?<strong>-integer</strong>|<strong>-command</strong> <em>cmdname</em>? ?<strong>-decreasing</strong>|<strong>-increasing</strong>? <em>list</em></tt></p></div>
4977 <div class="paragraph"><p>Sort the elements of <tt><em>list</em></tt>, returning a new list in sorted order.
4978 By default, ASCII sorting is used, with the result in increasing order.</p></div>
4979 <div class="paragraph"><p>If <tt>-integer</tt> is specified, numeric sorting is used.</p></div>
4980 <div class="paragraph"><p>If <tt>-command <em>cmdname</em></tt> is specified, <tt><em>cmdname</em></tt> is treated as a command
4981 name. For each comparison, <tt><em>cmdname $value1 $value2</tt></em> is called which
4982 should compare the values and return an integer less than, equal
4983 to, or greater than zero if the <tt><em>$value1</em></tt> is to be considered less
4984 than, equal to, or greater than <tt><em>$value2</em></tt>, respectively.</p></div>
4985 <div class="paragraph"><p>If <tt>-decreasing</tt> is specified, the resulting list is in the opposite
4986 order to what it would be otherwise. <tt>-increasing</tt> is the default.</p></div>
4987 <div class="paragraph"><p>If <tt>-index <em>listindex</em></tt> is specified, each element of the list is treated as a list and
4988 the given index is extracted from the list for comparison. The list index may
4989 be any valid list index, such as <tt>1</tt>, <tt>end</tt> or <tt>end-2</tt>.</p></div>
4990 <div class="paragraph"><p>If <tt>-index <em>listindex</em></tt> is specified, each element of the list is treated as a list and
4991 the given index is extracted from the list for comparison. The list index may
4992 be any valid list index, such as <tt>1</tt>, <tt>end</tt> or <tt>end-2</tt>.</p></div>
4993 </div>
4994 <div class="sect2">
4995 <h3 id="_open">open</h3>
4996 <div class="paragraph"><p><tt><strong>open</strong> <em>fileName ?access?</em></tt></p></div>
4997 <div class="paragraph"><p><tt><strong>open</strong> <em>|command-pipeline ?access?</em></tt></p></div>
4998 <div class="paragraph"><p>Opens a file and returns an identifier
4999 that may be used in future invocations
5000 of commands like <a href="#_read"><strong><tt>read</tt></strong></a>, <a href="#_puts"><strong><tt>puts</tt></strong></a>, and <a href="#_close"><strong><tt>close</tt></strong></a>.
5001 <tt><em>fileName</em></tt> gives the name of the file to open.</p></div>
5002 <div class="paragraph"><p>The <tt><em>access</em></tt> argument indicates the way in which the file is to be accessed.
5003 It may have any of the following values:</p></div>
5004 <div class="dlist"><dl>
5005 <dt class="hdlist1">
5006 <tt>r</tt>
5007 </dt>
5008 <dd>
5010 Open the file for reading only; the file must already exist.
5011 </p>
5012 </dd>
5013 <dt class="hdlist1">
5014 <tt>r\</tt>+
5015 </dt>
5016 <dd>
5018 Open the file for both reading and writing; the file must
5019 already exist.
5020 </p>
5021 </dd>
5022 <dt class="hdlist1">
5023 <tt>w</tt>
5024 </dt>
5025 <dd>
5027 Open the file for writing only. Truncate it if it exists. If it doesn&#8217;t
5028 exist, create a new file.
5029 </p>
5030 </dd>
5031 <dt class="hdlist1">
5032 <tt>w\</tt>+
5033 </dt>
5034 <dd>
5036 Open the file for reading and writing. Truncate it if it exists.
5037 If it doesn&#8217;t exist, create a new file.
5038 </p>
5039 </dd>
5040 <dt class="hdlist1">
5041 <tt>a</tt>
5042 </dt>
5043 <dd>
5045 Open the file for writing only. The file must already exist, and the file
5046 is positioned so that new data is appended to the file.
5047 </p>
5048 </dd>
5049 <dt class="hdlist1">
5050 <tt>a\</tt>+
5051 </dt>
5052 <dd>
5054 Open the file for reading and writing. If the file doesn&#8217;t
5055 exist, create a new empty file. Set the initial access position
5056 to the end of the file.
5057 </p>
5058 </dd>
5059 </dl></div>
5060 <div class="paragraph"><p><tt><em>access</em></tt> defaults to <em>r</em>.</p></div>
5061 <div class="paragraph"><p>If a file is opened for both reading and writing, then <a href="#_seek"><strong><tt>seek</tt></strong></a>
5062 must be invoked between a read and a write, or vice versa.</p></div>
5063 <div class="paragraph"><p>If the first character of <tt><em>fileName</em></tt> is "|" then the remaining
5064 characters of <tt><em>fileName</em></tt> are treated as a list of arguments that
5065 describe a command pipeline to invoke, in the same style as the
5066 arguments for exec. In this case, the channel identifier returned
5067 by open may be used to write to the command&#8217;s input pipe or read
5068 from its output pipe, depending on the value of <tt><em>access</em></tt>. If write-only
5069 access is used (e.g. <tt><em>access</em></tt> is <em>w</em>), then standard output for the
5070 pipeline is directed to the current standard output unless overridden
5071 by the command. If read-only access is used (e.g. <tt><em>access</em></tt> is r),
5072 standard input for the pipeline is taken from the current standard
5073 input unless overridden by the command.</p></div>
5074 <div class="paragraph"><p>The <a href="#_pid"><strong><tt>pid</tt></strong></a> command may be used to return the process ids of the commands
5075 forming the command pipeline.</p></div>
5076 <div class="paragraph"><p>See also <a href="#_socket"><strong><tt>socket</tt></strong></a>, <a href="#_pid"><strong><tt>pid</tt></strong></a>, <a href="#_exec"><strong><tt>exec</tt></strong></a></p></div>
5077 </div>
5078 <div class="sect2">
5079 <h3 id="_package">package</h3>
5080 <div class="paragraph"><p><tt><strong>package provide</strong> <em>name ?version?</em></tt></p></div>
5081 <div class="paragraph"><p>Indicates that the current script provides the package named <tt><em>name</em></tt>.
5082 If no version is specified, <em>1.0</em> is used.</p></div>
5083 <div class="paragraph"><p>Any script which provides a package may include this statement
5084 as the first statement, although it is not required.</p></div>
5085 <div class="paragraph"><p><tt><strong>package require</strong> <em>name ?version?</em>*</tt></p></div>
5086 <div class="paragraph"><p>Searches for the package with the given <tt><em>name</em></tt> by examining each path
5087 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
5088 or <em>$path/$name.tcl</em> as a script package.</p></div>
5089 <div class="paragraph"><p>The first such file which is found is considered to provide the the package.
5090 (The version number is ignored).</p></div>
5091 <div class="paragraph"><p>If <em>$name.so</em> exists, it is loaded with the <a href="#_load"><strong><tt>load</tt></strong></a> command,
5092 otherwise if <em>$name.tcl</em> exists it is loaded with the <a href="#_source"><strong><tt>source</tt></strong></a> command.</p></div>
5093 <div class="paragraph"><p>If <a href="#_load"><strong><tt>load</tt></strong></a> or <a href="#_source"><strong><tt>source</tt></strong></a> fails, <a href="#_package"><strong><tt>package</tt></strong></a> <tt>require</tt> will fail immediately.
5094 No further attempt will be made to locate the file.</p></div>
5095 </div>
5096 <div class="sect2">
5097 <h3 id="_pid">pid</h3>
5098 <div class="paragraph"><p><tt><strong>pid</strong></tt></p></div>
5099 <div class="paragraph"><p><tt><strong>pid</strong> <em>fileId</em></tt></p></div>
5100 <div class="paragraph"><p>The first form returns the process identifier of the current process.</p></div>
5101 <div class="paragraph"><p>The second form accepts a handle returned by <a href="#_open"><strong><tt>open</tt></strong></a> and returns a list
5102 of the process ids forming the pipeline in the same form as <a href="#_exec"><strong><tt>exec</tt></strong></a> <tt>... &amp;</tt>.
5103 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
5104 the empty string is returned instead.</p></div>
5105 <div class="paragraph"><p>See also <a href="#_open"><strong><tt>open</tt></strong></a>, <a href="#_exec"><strong><tt>exec</tt></strong></a></p></div>
5106 </div>
5107 <div class="sect2">
5108 <h3 id="_proc">proc</h3>
5109 <div class="paragraph"><p><tt><strong>proc</strong> <em>name args ?statics? body</em></tt></p></div>
5110 <div class="paragraph"><p>The <a href="#_proc"><strong><tt>proc</tt></strong></a> command creates a new Tcl command procedure, <tt><em>name</em></tt>.
5111 When the new command is invoked, the contents of <tt><em>body</em></tt> will be executed.
5112 Tcl interpreter. <tt><em>args</em></tt> specifies the formal arguments to the procedure.
5113 If specified, <tt><em>static</em></tt>, declares static variables which are bound to the
5114 procedure.</p></div>
5115 <div class="paragraph"><p>See PROCEDURES for detailed information about Tcl procedures.</p></div>
5116 <div class="paragraph"><p>The <a href="#_proc"><strong><tt>proc</tt></strong></a> command returns <tt><em>name</em></tt> (which is useful with <a href="#_local"><strong><tt>local</tt></strong></a>).</p></div>
5117 <div class="paragraph"><p>When a procedure is invoked, the procedure&#8217;s return value is the
5118 value specified in a <a href="#_return"><strong><tt>return</tt></strong></a> command. If the procedure doesn&#8217;t
5119 execute an explicit <a href="#_return"><strong><tt>return</tt></strong></a>, then its return value is the value
5120 of the last command executed in the procedure&#8217;s body.</p></div>
5121 <div class="paragraph"><p>If an error occurs while executing the procedure body, then the
5122 procedure-as-a-whole will return that same error.</p></div>
5123 </div>
5124 <div class="sect2">
5125 <h3 id="_puts">puts</h3>
5126 <div class="paragraph"><p><tt><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></tt></p></div>
5127 <div class="paragraph"><p><tt><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></tt></p></div>
5128 <div class="paragraph"><p>Writes the characters given by <tt><em>string</em></tt> to the file given
5129 by <tt><em>fileId</em></tt>. <tt><em>fileId</em></tt> must have been the return
5130 value from a previous call to <a href="#_open"><strong><tt>open</tt></strong></a>, or it may be
5131 <tt>stdout</tt> or <tt>stderr</tt> to refer to one of the standard I/O
5132 channels; it must refer to a file that was opened for
5133 writing.</p></div>
5134 <div class="paragraph"><p>In the first form, if no <tt><em>fileId</em></tt> is specified then it defaults to <tt>stdout</tt>.
5135 <a href="#_puts"><strong><tt>puts</tt></strong></a> normally outputs a newline character after <tt><em>string</em></tt>,
5136 but this feature may be suppressed by specifying the <tt>-nonewline</tt>
5137 switch.</p></div>
5138 <div class="paragraph"><p>Output to files is buffered internally by Tcl; the <a href="#_flush"><strong><tt>flush</tt></strong></a>
5139 command may be used to force buffered characters to be output.</p></div>
5140 </div>
5141 <div class="sect2">
5142 <h3 id="_pwd">pwd</h3>
5143 <div class="paragraph"><p><tt><strong>pwd</strong></tt></p></div>
5144 <div class="paragraph"><p>Returns the path name of the current working directory.</p></div>
5145 </div>
5146 <div class="sect2">
5147 <h3 id="_rand">rand</h3>
5148 <div class="paragraph"><p><tt><strong>rand</strong> <em>?min? ?max?</em></tt></p></div>
5149 <div class="paragraph"><p>Returns a random integer between <tt><em>min</em></tt> (defaults to 0) and <tt><em>max</em></tt>
5150 (defaults to the maximum integer).</p></div>
5151 <div class="paragraph"><p>If only one argument is given, it is interpreted as <tt><em>max</em></tt>.</p></div>
5152 </div>
5153 <div class="sect2">
5154 <h3 id="_range">range</h3>
5155 <div class="paragraph"><p><tt><strong>range</strong> <em>?start? end ?step?</em></tt></p></div>
5156 <div class="paragraph"><p>Returns a list of integers starting at <tt><em>start</em></tt> (defaults to 0)
5157 and ranging up to but not including <tt><em>end</em></tt> in steps of <tt><em>step</em></tt> defaults to 1).</p></div>
5158 <div class="literalblock">
5159 <div class="content">
5160 <pre><tt>jim&gt; range 5
5161 0 1 2 3 4
5162 jim&gt; range 2 5
5163 2 3 4
5164 jim&gt; range 2 10 4
5166 jim&gt; range 7 4 -2
5167 7 5</tt></pre>
5168 </div></div>
5169 </div>
5170 <div class="sect2">
5171 <h3 id="_read">read</h3>
5172 <div class="paragraph"><p><tt><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></tt></p></div>
5173 <div class="paragraph"><p><tt><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</tt></p></div>
5174 <div class="paragraph"><p><tt><strong>read</strong> <em>fileId numBytes</em></tt></p></div>
5175 <div class="paragraph"><p><tt><em>fileId</em> <strong>read</strong> <em>numBytes</em></tt></p></div>
5176 <div class="paragraph"><p>In the first form, all of the remaining bytes are read from the file
5177 given by <tt><em>fileId</em></tt>; they are returned as the result of the command.
5178 If the <tt>-nonewline</tt> switch is specified then the last
5179 character of the file is discarded if it is a newline.</p></div>
5180 <div class="paragraph"><p>In the second form, the extra argument specifies how many bytes to read;
5181 exactly this many bytes will be read and returned, unless there are fewer than
5182 <tt><em>numBytes</em></tt> bytes left in the file; in this case, all the remaining
5183 bytes are returned.</p></div>
5184 <div class="paragraph"><p><tt><em>fileId</em></tt> must be <tt>stdin</tt> or the return value from a previous call
5185 to <a href="#_open"><strong><tt>open</tt></strong></a>; it must refer to a file that was opened for reading.</p></div>
5186 </div>
5187 <div class="sect2">
5188 <h3 id="_regexp">regexp</h3>
5189 <div class="paragraph"><p><tt><strong>regexp ?-nocase? ?-line? ?-indices? ?-start</strong> <em>offset</em>? <strong>?-all? ?-inline? ?--?</strong> <em>exp string ?matchVar? ?subMatchVar subMatchVar ...?</em></tt></p></div>
5190 <div class="paragraph"><p>Determines whether the regular expression <tt><em>exp</em></tt> matches part or
5191 all of <tt><em>string</em></tt> and returns 1 if it does, 0 if it doesn&#8217;t.</p></div>
5192 <div class="paragraph"><p>See REGULAR EXPRESSIONS above for complete information on the
5193 syntax of <tt><em>exp</em></tt> and how it is matched against <tt><em>string</em></tt>.</p></div>
5194 <div class="paragraph"><p>If additional arguments are specified after <tt><em>string</em></tt> then they
5195 are treated as the names of variables to use to return
5196 information about which part(s) of <tt><em>string</em></tt> matched <tt><em>exp</em></tt>.
5197 <tt><em>matchVar</em></tt> will be set to the range of <tt><em>string</em></tt> that
5198 matched all of <tt><em>exp</em></tt>. The first <tt><em>subMatchVar</em></tt> will contain
5199 the characters in <tt><em>string</em></tt> that matched the leftmost parenthesized
5200 subexpression within <tt><em>exp</em></tt>, the next <tt><em>subMatchVar</em></tt> will
5201 contain the characters that matched the next parenthesized
5202 subexpression to the right in <tt><em>exp</em></tt>, and so on.</p></div>
5203 <div class="paragraph"><p>Normally, <tt><em>matchVar</em></tt> and the each <tt><em>subMatchVar</em></tt> are set to hold the
5204 matching characters from <a href="#_string"><strong><tt>string</tt></strong></a>, however see <tt>-indices</tt> and
5205 <tt>-inline</tt> below.</p></div>
5206 <div class="paragraph"><p>If there are more values for <tt><em>subMatchVar</em></tt> than parenthesized subexpressions
5207 within <tt><em>exp</em></tt>, or if a particular subexpression in <tt><em>exp</em></tt> doesn&#8217;t
5208 match the string (e.g. because it was in a portion of the expression
5209 that wasn&#8217;t matched), then the corresponding <tt><em>subMatchVar</em></tt> will be
5210 set to <tt>"-1 -1"</tt> if <tt>-indices</tt> has been specified or to an empty
5211 string otherwise.</p></div>
5212 <div class="paragraph"><p>The following switches modify the behaviour of <tt><em>regexp</em></tt></p></div>
5213 <div class="dlist"><dl>
5214 <dt class="hdlist1">
5215 <tt><strong>-nocase</strong></tt>
5216 </dt>
5217 <dd>
5219 Causes upper-case and lower-case characters to be treated as
5220 identical during the matching process.
5221 </p>
5222 </dd>
5223 <dt class="hdlist1">
5224 <tt><strong>-line</strong></tt>
5225 </dt>
5226 <dd>
5228 Use newline-sensitive matching. By default, newline
5229 is a completely ordinary character with no special meaning in
5230 either REs or strings. With this flag, <tt>[<sup></tt> bracket expressions
5231 and <tt>.</tt> never match newline, a <tt></sup></tt> anchor matches the null
5232 string after any newline in the string in addition to its normal
5233 function, and the <tt>$</tt> anchor matches the null string before any
5234 newline in the string in addition to its normal function.
5235 </p>
5236 </dd>
5237 <dt class="hdlist1">
5238 <tt><strong>-indices</strong></tt>
5239 </dt>
5240 <dd>
5242 Changes what is stored in the subMatchVars. Instead of
5243 storing the matching characters from string, each variable
5244 will contain a list of two decimal strings giving the indices
5245 in string of the first and last characters in the matching
5246 range of characters.
5247 </p>
5248 </dd>
5249 <dt class="hdlist1">
5250 <tt><strong>-start</strong> <em>offset</em></tt>
5251 </dt>
5252 <dd>
5254 Specifies a character index offset into the string at which to start
5255 matching the regular expression. If <tt>-indices</tt> is
5256 specified, the indices will be indexed starting from the
5257 absolute beginning of the input string. <tt><em>offset</em></tt> will be
5258 constrained to the bounds of the input string.
5259 </p>
5260 </dd>
5261 <dt class="hdlist1">
5262 <tt><strong>-all</strong></tt>
5263 </dt>
5264 <dd>
5266 Causes the regular expression to be matched as many times as possible
5267 in the string, returning the total number of matches found. If this
5268 is specified with match variables, they will contain information
5269 for the last match only.
5270 </p>
5271 </dd>
5272 <dt class="hdlist1">
5273 <tt><strong>-inline</strong></tt>
5274 </dt>
5275 <dd>
5277 Causes the command to return, as a list, the data that would otherwise
5278 be placed in match variables. When using <tt>-inline</tt>, match variables
5279 may not be specified. If used with <tt>-all</tt>, the list will be concatenated
5280 at each iteration, such that a flat list is always returned. For
5281 each match iteration, the command will append the overall match
5282 data, plus one element for each subexpression in the regular
5283 expression.
5284 </p>
5285 </dd>
5286 <dt class="hdlist1">
5287 <tt><strong>--</strong></tt>
5288 </dt>
5289 <dd>
5291 Marks the end of switches. The argument following this one will be
5292 treated as <tt><em>exp</em></tt> even if it starts with a <tt>-</tt>.
5293 </p>
5294 </dd>
5295 </dl></div>
5296 </div>
5297 <div class="sect2">
5298 <h3 id="_regsub">regsub</h3>
5299 <div class="paragraph"><p><tt><strong>regsub ?-nocase? ?-all? ?-line? ?-start</strong> <em>offset</em>? ?<strong>--</strong>? <em>exp string subSpec ?varName?</em></tt></p></div>
5300 <div class="paragraph"><p>This command matches the regular expression <tt><em>exp</em></tt> against
5301 <tt><em>string</em></tt> using the rules described in REGULAR EXPRESSIONS
5302 above.</p></div>
5303 <div class="paragraph"><p>If <tt><em>varName</em></tt> is specified, the commands stores <tt><em>string</em></tt> to <tt><em>varName</em></tt>
5304 with the substitutions detailed below, and returns the number of
5305 substitutions made (normally 1 unless <tt>-all</tt> is specified).
5306 This is 0 if there were no matches.</p></div>
5307 <div class="paragraph"><p>If <tt><em>varName</em></tt> is not specified, the substituted string will be returned
5308 instead.</p></div>
5309 <div class="paragraph"><p>When copying <tt><em>string</em></tt>, the portion of <tt><em>string</em></tt> that
5310 matched <tt><em>exp</em></tt> is replaced with <tt><em>subSpec</em></tt>.
5311 If <tt><em>subSpec</em></tt> contains a <tt>&amp;</tt> or <tt>\0</tt>, then it is replaced
5312 in the substitution with the portion of <tt><em>string</em></tt> that
5313 matched <tt><em>exp</em></tt>.</p></div>
5314 <div class="paragraph"><p>If <tt><em>subSpec</em></tt> contains a <tt>\n</tt>, where <tt><em>n</em></tt> is a digit
5315 between 1 and 9, then it is replaced in the substitution with
5316 the portion of <tt><em>string</em></tt> that matched the <tt><em>'+n</tt></em>'<tt>-th
5317 parenthesized subexpression of +<em>exp</em></tt>.
5318 Additional backslashes may be used in <tt><em>subSpec</em></tt> to prevent special
5319 interpretation of <tt>&amp;</tt> or <tt>\0</tt> or <tt>\n</tt> or
5320 backslash.</p></div>
5321 <div class="paragraph"><p>The use of backslashes in <tt><em>subSpec</em></tt> tends to interact badly
5322 with the Tcl parser&#8217;s use of backslashes, so it&#8217;s generally
5323 safest to enclose <tt><em>subSpec</em></tt> in braces if it includes
5324 backslashes.</p></div>
5325 <div class="paragraph"><p>The following switches modify the behaviour of <tt><em>regsub</em></tt></p></div>
5326 <div class="dlist"><dl>
5327 <dt class="hdlist1">
5328 <tt><strong>-nocase</strong></tt>
5329 </dt>
5330 <dd>
5332 Upper-case characters in <tt><em>string</em></tt> are converted to lower-case
5333 before matching against <tt><em>exp</em></tt>; however, substitutions
5334 specified by <tt><em>subSpec</em></tt> use the original unconverted form
5335 of <tt><em>string</em></tt>.
5336 </p>
5337 </dd>
5338 <dt class="hdlist1">
5339 <tt><strong>-all</strong></tt>
5340 </dt>
5341 <dd>
5343 All ranges in <tt><em>string</em></tt> that match <tt><em>exp</em></tt> are found and substitution
5344 is performed for each of these ranges, rather than only the
5345 first. The <tt>&amp;</tt> and <tt>\n</tt> sequences are handled for
5346 each substitution using the information from the corresponding
5347 match.
5348 </p>
5349 </dd>
5350 <dt class="hdlist1">
5351 <tt><strong>-line</strong></tt>
5352 </dt>
5353 <dd>
5355 Use newline-sensitive matching. By default, newline
5356 is a completely ordinary character with no special meaning in
5357 either REs or strings. With this flag, <tt>[<sup></tt> bracket expressions
5358 and <tt>.</tt> never match newline, a <tt></sup></tt> anchor matches the null
5359 string after any newline in the string in addition to its normal
5360 function, and the <tt>$</tt> anchor matches the null string before any
5361 newline in the string in addition to its normal function.
5362 </p>
5363 </dd>
5364 <dt class="hdlist1">
5365 <tt><strong>-start</strong> <em>offset</em></tt>
5366 </dt>
5367 <dd>
5369 Specifies a character index offset into the string at which to
5370 start matching the regular expression. <tt><em>offset</em></tt> will be
5371 constrained to the bounds of the input string.
5372 </p>
5373 </dd>
5374 <dt class="hdlist1">
5375 <tt><strong>--</strong></tt>
5376 </dt>
5377 <dd>
5379 Marks the end of switches. The argument following this one will be
5380 treated as <tt><em>exp</em></tt> even if it starts with a <tt>-</tt>.
5381 </p>
5382 </dd>
5383 </dl></div>
5384 </div>
5385 <div class="sect2">
5386 <h3 id="_ref">ref</h3>
5387 <div class="paragraph"><p><tt><strong>ref</strong> <em>string tag ?finalizer?</em></tt></p></div>
5388 <div class="paragraph"><p>Create a new reference containing <tt><em>string</em></tt> of type <tt><em>tag</em></tt>.
5389 If <tt><em>finalizer</em></tt> is specified, it is a command which will be invoked
5390 when the a garbage collection cycle runs and this reference is
5391 no longer accessible.</p></div>
5392 <div class="paragraph"><p>The finalizer is invoked as:</p></div>
5393 <div class="literalblock">
5394 <div class="content">
5395 <pre><tt>+finalizer 'reference string'+</tt></pre>
5396 </div></div>
5397 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5398 </div>
5399 <div class="sect2">
5400 <h3 id="_rename">rename</h3>
5401 <div class="paragraph"><p><tt><strong>rename</strong> <em>oldName newName</em></tt></p></div>
5402 <div class="paragraph"><p>Rename the command that used to be called <tt><em>oldName</em></tt> so that it
5403 is now called <tt><em>newName</em></tt>. If <tt><em>newName</em></tt> is an empty string
5404 (e.g. {}) then <tt><em>oldName</em></tt> is deleted. The <a href="#_rename"><strong><tt>rename</tt></strong></a> command
5405 returns an empty string as result.</p></div>
5406 </div>
5407 <div class="sect2">
5408 <h3 id="_return">return</h3>
5409 <div class="paragraph"><p><tt><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>?</tt></p></div>
5410 <div class="paragraph"><p>Return immediately from the current procedure (or top-level command
5411 or <a href="#_source"><strong><tt>source</tt></strong></a> command), with <tt><em>value</em></tt> as the return value. If <tt><em>value</em></tt>
5412 is not specified, an empty string will be returned as result.</p></div>
5413 <div class="paragraph"><p>If <tt>-code</tt> is specified (as either a number or ok, error, break,
5414 continue, signal, return or exit), this code will be used instead
5415 of <tt>JIM_OK</tt>. This is generally useful when implementing flow of control
5416 commands.</p></div>
5417 <div class="paragraph"><p>If <tt>-level</tt> is specified and greater than 1, it has the effect of delaying
5418 the new return code from <tt>-code</tt>. This is useful when rethrowing an error
5419 from <a href="#_catch"><strong><tt>catch</tt></strong></a>. See the implementation of try/catch in tclcompat.tcl for
5420 an example of how this is done.</p></div>
5421 <div class="paragraph"><p>Note: The following options are only used when <tt>-code</tt> is JIM_ERR.</p></div>
5422 <div class="paragraph"><p>If <tt>-errorinfo</tt> is specified (as returned from <a href="#_info"><strong><tt>info</tt></strong></a> <tt>stacktrace</tt>)
5423 it is used to initialize the stacktrace.</p></div>
5424 <div class="paragraph"><p>If <tt>-errorcode</tt> is specified, it is used to set the global variable $::errorCode.</p></div>
5425 </div>
5426 <div class="sect2">
5427 <h3 id="_scan">scan</h3>
5428 <div class="paragraph"><p><tt><strong>scan</strong> <em>string format varName1 ?varName2 ...?</em></tt></p></div>
5429 <div class="paragraph"><p>This command parses fields from an input string in the same fashion
5430 as the C <em>sscanf</em> procedure. <tt><em>string</em></tt> gives the input to be parsed
5431 and <tt><em>format</em></tt> indicates how to parse it, using <em>%</em> fields as in
5432 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5433 man page for details. Each <tt><em>varName</em></tt> gives the name of a variable;
5434 when a field is scanned from <tt><em>string</em></tt>, the result is converted back
5435 into a string and assigned to the corresponding <tt><em>varName</em></tt>. The
5436 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5437 character value is converted to a decimal string, which is then
5438 assigned to the corresponding <tt><em>varName</em></tt>; no field width may be
5439 specified for this conversion.</p></div>
5440 </div>
5441 <div class="sect2">
5442 <h3 id="_seek">seek</h3>
5443 <div class="paragraph"><p><tt><strong>seek</strong> <em>fileId offset ?origin?</em></tt></p></div>
5444 <div class="paragraph"><p><tt><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></tt></p></div>
5445 <div class="paragraph"><p>Change the current access position for <tt><em>fileId</em></tt>.
5446 The <tt><em>offset</em></tt> and <tt><em>origin</em></tt> arguments specify the position at
5447 which the next read or write will occur for <tt><em>fileId</em></tt>.
5448 <tt><em>offset</em></tt> must be a number (which may be negative) and <tt><em>origin</em></tt>
5449 must be one of the following:</p></div>
5450 <div class="dlist"><dl>
5451 <dt class="hdlist1">
5452 <tt><strong>start</strong></tt>
5453 </dt>
5454 <dd>
5456 The new access position will be <tt><em>offset</em></tt> bytes from the start
5457 of the file.
5458 </p>
5459 </dd>
5460 <dt class="hdlist1">
5461 <tt><strong>current</strong></tt>
5462 </dt>
5463 <dd>
5465 The new access position will be <tt><em>offset</em></tt> bytes from the current
5466 access position; a negative <tt><em>offset</em></tt> moves the access position
5467 backwards in the file.
5468 </p>
5469 </dd>
5470 <dt class="hdlist1">
5471 <tt><strong>end</strong></tt>
5472 </dt>
5473 <dd>
5475 The new access position will be <tt><em>offset</em></tt> bytes from the end of
5476 the file. A negative <tt><em>offset</em></tt> places the access position before
5477 the end-of-file, and a positive <tt><em>offset</em></tt> places the access position
5478 after the end-of-file.
5479 </p>
5480 </dd>
5481 </dl></div>
5482 <div class="paragraph"><p>The <tt><em>origin</em></tt> argument defaults to <tt>start</tt>.</p></div>
5483 <div class="paragraph"><p><tt><em>fileId</em></tt> must have been the return value from a previous call to
5484 <a href="#_open"><strong><tt>open</tt></strong></a>, or it may be <tt>stdin</tt>, <tt>stdout</tt>, or <tt>stderr</tt> to refer to one
5485 of the standard I/O channels.</p></div>
5486 <div class="paragraph"><p>This command returns an empty string.</p></div>
5487 </div>
5488 <div class="sect2">
5489 <h3 id="_set">set</h3>
5490 <div class="paragraph"><p><tt><strong>set</strong> <em>varName ?value?</em></tt></p></div>
5491 <div class="paragraph"><p>Returns the value of variable <tt><em>varName</em></tt>.</p></div>
5492 <div class="paragraph"><p>If <tt><em>value</em></tt> is specified, then set the value of <tt><em>varName</em></tt> to <tt><em>value</em></tt>,
5493 creating a new variable if one doesn&#8217;t already exist, and return
5494 its value.</p></div>
5495 <div class="paragraph"><p>If <tt><em>varName</em></tt> contains an open parenthesis and ends with a
5496 close parenthesis, then it refers to an array element: the characters
5497 before the open parenthesis are the name of the array, and the characters
5498 between the parentheses are the index within the array.
5499 Otherwise <tt><em>varName</em></tt> refers to a scalar variable.</p></div>
5500 <div class="paragraph"><p>If no procedure is active, then <tt><em>varName</em></tt> refers to a global
5501 variable.</p></div>
5502 <div class="paragraph"><p>If a procedure is active, then <tt><em>varName</em></tt> refers to a parameter
5503 or local variable of the procedure, unless the <tt><em>global</em></tt> command
5504 has been invoked to declare <tt><em>varName</em></tt> to be global.</p></div>
5505 <div class="paragraph"><p>The <tt>::</tt> prefix may also be used to explicitly reference a variable
5506 in the global scope.</p></div>
5507 </div>
5508 <div class="sect2">
5509 <h3 id="_setref">setref</h3>
5510 <div class="paragraph"><p><tt><strong>setref</strong> <em>reference string</em></tt></p></div>
5511 <div class="paragraph"><p>Store a new string in <tt><em>reference</em></tt>, replacing the existing string.
5512 The reference must be a valid reference create with the <a href="#_ref"><strong><tt>ref</tt></strong></a>
5513 command.</p></div>
5514 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5515 </div>
5516 <div class="sect2">
5517 <h3 id="_signal">signal</h3>
5518 <div class="paragraph"><p>Command for signal handling.</p></div>
5519 <div class="paragraph"><p>See <a href="#_kill"><strong><tt>kill</tt></strong></a> for the different forms which may be used to specify signals.</p></div>
5520 <div class="paragraph"><p>Commands which return a list of signal names do so using the canonical form:
5521 "<tt>SIGINT SIGTERM</tt>".</p></div>
5522 <div class="dlist"><dl>
5523 <dt class="hdlist1">
5524 <tt><strong>signal handle</strong> ?<em>signals ...</em>?</tt>
5525 </dt>
5526 <dd>
5528 If no signals are given, returns a list of all signals which are currently
5529 being handled.
5530 If signals are specified, these are added to the list of signals currently
5531 being handled.
5532 </p>
5533 </dd>
5534 <dt class="hdlist1">
5535 <tt><strong>signal ignore</strong> ?<em>signals ...</em>?</tt>
5536 </dt>
5537 <dd>
5539 If no signals are given, returns a lists all signals which are currently
5540 being ignored.
5541 If signals are specified, these are added to the list of signals
5542 currently being ignored. These signals are still delivered, but
5543 are not considered by <a href="#_catch"><strong><tt>catch</tt></strong></a> <tt>-signal</tt> or <a href="#_try"><strong><tt>try</tt></strong></a> <tt>-signal</tt>. Use
5544 <a href="#_signal"><strong><tt>signal</tt></strong></a> <tt>check</tt> to determine which signals have occurred but
5545 been ignored.
5546 </p>
5547 </dd>
5548 <dt class="hdlist1">
5549 <tt><strong>signal default</strong> ?<em>signals ...</em>?</tt>
5550 </dt>
5551 <dd>
5553 If no signals are given, returns a lists all signals which are currently have
5554 the default behaviour.
5555 If signals are specified, these are added to the list of signals which have
5556 the default behaviour.
5557 </p>
5558 </dd>
5559 <dt class="hdlist1">
5560 <tt><strong>signal check ?-clear?</strong> ?<em>signals ...</em>?</tt>
5561 </dt>
5562 <dd>
5564 Returns a list of signals which have been delivered to the process
5565 but are <em>ignored</em>. If signals are specified, only that set of signals will
5566 be checked, otherwise all signals will be checked.
5567 If <tt>-clear</tt> is specified, any signals returned are removed and will not be
5568 returned by subsequent calls to <a href="#_signal"><strong><tt>signal</tt></strong></a> <tt>check</tt> unless delivered again.
5569 </p>
5570 </dd>
5571 <dt class="hdlist1">
5572 <tt><strong>signal throw</strong> ?<em>signal</em>?</tt>
5573 </dt>
5574 <dd>
5576 Raises the given signal, which defaults to <tt>SIGINT</tt> if not specified.
5577 The behaviour is identical to:
5578 </p>
5579 <div class="literalblock">
5580 <div class="content">
5581 <pre><tt>kill signal [pid]</tt></pre>
5582 </div></div>
5583 </dd>
5584 </dl></div>
5585 <div class="paragraph"><p>Note that <a href="#_signal"><strong><tt>signal</tt></strong></a> <tt>handle</tt> and <a href="#_signal"><strong><tt>signal</tt></strong></a> <tt>ignore</tt> represent two forms of signal
5586 handling. <a href="#_signal"><strong><tt>signal</tt></strong></a> <tt>handle</tt> is used in conjunction with <a href="#_catch"><strong><tt>catch</tt></strong></a> <tt>-signal</tt> or <a href="#_try"><strong><tt>try</tt></strong></a> <tt>-signal</tt>
5587 to immediately abort execution when the signal is delivered. Alternatively, <a href="#_signal"><strong><tt>signal</tt></strong></a> <tt>ignore</tt>
5588 is used in conjunction with <a href="#_signal"><strong><tt>signal</tt></strong></a> <tt>check</tt> to handle signal synchronously. Consider the
5589 two examples below.</p></div>
5590 <div class="paragraph"><p>Prevent a processing from taking too long</p></div>
5591 <div class="literalblock">
5592 <div class="content">
5593 <pre><tt>signal handle SIGALRM
5594 alarm 20
5595 try -signal {
5596 .. possibly long running process ..
5597 alarm 0
5598 } on signal {sig} {
5599 puts stderr "Process took too long"
5600 }</tt></pre>
5601 </div></div>
5602 <div class="paragraph"><p>Handle SIGHUP to reconfigure:</p></div>
5603 <div class="literalblock">
5604 <div class="content">
5605 <pre><tt>signal ignore SIGHUP
5606 while {1} {
5607 ... handle configuration/reconfiguration ...
5608 while {[signal check -clear SIGHUP] eq ""} {
5609 ... do processing ..
5611 # Received SIGHUP, so reconfigure
5612 }</tt></pre>
5613 </div></div>
5614 </div>
5615 <div class="sect2">
5616 <h3 id="_sleep">sleep</h3>
5617 <div class="paragraph"><p><tt><strong>sleep</strong> <em>seconds</em></tt></p></div>
5618 <div class="paragraph"><p>Pauses for the given number of seconds, which may be a floating
5619 point value less than one to sleep for less than a second, or an
5620 integer to sleep for one or more seconds.</p></div>
5621 </div>
5622 <div class="sect2">
5623 <h3 id="_source">source</h3>
5624 <div class="paragraph"><p><tt><strong>source</strong> <em>fileName</em></tt></p></div>
5625 <div class="paragraph"><p>Read file <tt><em>fileName</em></tt> and pass the contents to the Tcl interpreter
5626 as a sequence of commands to execute in the normal fashion. The return
5627 value of <a href="#_source"><strong><tt>source</tt></strong></a> is the return value of the last command executed
5628 from the file. If an error occurs in executing the contents of the
5629 file, then the <a href="#_source"><strong><tt>source</tt></strong></a> command will return that error.</p></div>
5630 <div class="paragraph"><p>If a <a href="#_return"><strong><tt>return</tt></strong></a> command is invoked from within the file, the remainder of
5631 the file will be skipped and the <a href="#_source"><strong><tt>source</tt></strong></a> command will return
5632 normally with the result from the <a href="#_return"><strong><tt>return</tt></strong></a> command.</p></div>
5633 </div>
5634 <div class="sect2">
5635 <h3 id="_split">split</h3>
5636 <div class="paragraph"><p><tt><strong>split</strong> <em>string ?splitChars?</em></tt></p></div>
5637 <div class="paragraph"><p>Returns a list created by splitting <tt><em>string</em></tt> at each character
5638 that is in the <tt><em>splitChars</em></tt> argument.</p></div>
5639 <div class="paragraph"><p>Each element of the result list will consist of the
5640 characters from <tt><em>string</em></tt> between instances of the
5641 characters in <tt><em>splitChars</em></tt>.</p></div>
5642 <div class="paragraph"><p>Empty list elements will be generated if <tt><em>string</em></tt> contains
5643 adjacent characters in <tt><em>splitChars</em></tt>, or if the first or last
5644 character of <tt><em>string</em></tt> is in <tt><em>splitChars</em></tt>.</p></div>
5645 <div class="paragraph"><p>If <tt><em>splitChars</em></tt> is an empty string then each character of
5646 <tt><em>string</em></tt> becomes a separate element of the result list.</p></div>
5647 <div class="paragraph"><p><tt><em>splitChars</em></tt> defaults to the standard white-space characters.
5648 For example,</p></div>
5649 <div class="literalblock">
5650 <div class="content">
5651 <pre><tt>split "comp.unix.misc" .</tt></pre>
5652 </div></div>
5653 <div class="paragraph"><p>returns <tt><em>"comp unix misc"</em></tt> and</p></div>
5654 <div class="literalblock">
5655 <div class="content">
5656 <pre><tt>split "Hello world" {}</tt></pre>
5657 </div></div>
5658 <div class="paragraph"><p>returns <tt><em>"H e l l o { } w o r l d"</em></tt>.</p></div>
5659 </div>
5660 <div class="sect2">
5661 <h3 id="_stackdump">stackdump</h3>
5662 <div class="paragraph"><p><tt><strong>stackdump</strong> <em>stacktrace</em></tt></p></div>
5663 <div class="paragraph"><p>Creates a human readable representation of a stack trace.</p></div>
5664 </div>
5665 <div class="sect2">
5666 <h3 id="_stacktrace">stacktrace</h3>
5667 <div class="paragraph"><p><tt><strong>stacktrace</strong></tt></p></div>
5668 <div class="paragraph"><p>Returns a live stack trace as a list of <tt>proc file line proc file line ...</tt>.
5669 Iteratively uses <a href="#_info"><strong><tt>info</tt></strong></a> <tt>frame</tt> to create the stack trace. This stack trace is in the
5670 same form as produced by <a href="#_catch"><strong><tt>catch</tt></strong></a> and <a href="#_info"><strong><tt>info</tt></strong></a> <tt>stacktrace</tt></p></div>
5671 <div class="paragraph"><p>See also <a href="#_stackdump"><strong><tt>stackdump</tt></strong></a>.</p></div>
5672 </div>
5673 <div class="sect2">
5674 <h3 id="_string">string</h3>
5675 <div class="paragraph"><p><tt><strong>string</strong> <em>option arg ?arg ...?</em></tt></p></div>
5676 <div class="paragraph"><p>Perform one of several string operations, depending on <tt><em>option</em></tt>.
5677 The legal options (which may be abbreviated) are:</p></div>
5678 <div class="dlist"><dl>
5679 <dt class="hdlist1">
5680 <tt><strong>string bytelength</strong> <em>string</em></tt>
5681 </dt>
5682 <dd>
5684 Returns the length of the string in bytes. This will return
5685 the same value as <a href="#_string"><strong><tt>string</tt></strong></a> <tt>length</tt> if UTF-8 support is not enabled,
5686 or if the string is composed entirely of ASCII characters.
5687 See UTF-8 AND UNICODE.
5688 </p>
5689 </dd>
5690 <dt class="hdlist1">
5691 <tt><strong>string byterange</strong> <em>string first last</em></tt>
5692 </dt>
5693 <dd>
5695 Like <a href="#_string"><strong><tt>string</tt></strong></a> <tt>range</tt> except works on bytes rather than characters.
5696 These commands are identical if UTF-8 support is not enabled.
5697 </p>
5698 </dd>
5699 <dt class="hdlist1">
5700 <tt><strong>string compare ?-nocase?</strong> <em>string1 string2</em></tt>
5701 </dt>
5702 <dd>
5704 Perform a character-by-character comparison of strings <tt><em>string1</em></tt> and
5705 <tt><em>string2</em></tt> in the same way as the C <em>strcmp</em> procedure. Return
5706 -1, 0, or 1, depending on whether <tt><em>string1</em></tt> is lexicographically
5707 less than, equal to, or greater than <tt><em>string2</em></tt>.
5708 Performs a case-insensitive comparison if <tt>-nocase</tt> is specified.
5709 </p>
5710 </dd>
5711 <dt class="hdlist1">
5712 <tt><strong>string equal ?-nocase?</strong> <em>string1 string2</em></tt>
5713 </dt>
5714 <dd>
5716 Returns 1 if the strings are equal, or 0 otherwise.
5717 Performs a case-insensitive comparison if <tt>-nocase</tt> is specified.
5718 </p>
5719 </dd>
5720 <dt class="hdlist1">
5721 <tt><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></tt>
5722 </dt>
5723 <dd>
5725 Search <tt><em>string2</em></tt> for a sequence of characters that exactly match
5726 the characters in <tt><em>string1</em></tt>. If found, return the index of the
5727 first character in the first such match within <tt><em>string2</em></tt>. If not
5728 found, return -1. If <tt><em>firstIndex</em></tt> is specified, matching will start
5729 from <tt><em>firstIndex</em></tt> of <tt><em>string1</em></tt>.
5730 </p>
5731 </dd>
5732 <dt class="hdlist1">
5734 </dt>
5735 <dd>
5737 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>firstIndex</em></tt>.
5738 </p>
5739 </dd>
5740 <dt class="hdlist1">
5741 <tt><strong>string index</strong> <em>string charIndex</em></tt>
5742 </dt>
5743 <dd>
5745 Returns the <tt><em>charIndex</em></tt><em>th character of the <tt>'string</em></tt>
5746 argument. A <tt><em>charIndex</em></tt> of 0 corresponds to the first
5747 character of the string.
5748 If <tt><em>charIndex</em></tt> is less than 0 or greater than
5749 or equal to the length of the string then an empty string is
5750 returned.
5751 </p>
5752 </dd>
5753 <dt class="hdlist1">
5755 </dt>
5756 <dd>
5758 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>charIndex</em></tt>.
5759 </p>
5760 </dd>
5761 <dt class="hdlist1">
5762 <tt><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></tt>
5763 </dt>
5764 <dd>
5766 Returns 1 if <tt><em>string</em></tt> is a valid member of the specified character
5767 class, otherwise returns 0. If <tt>-strict</tt> is specified, then an
5768 empty string returns 0, otherwise an empty string will return 1
5769 on any class. The following character classes are recognized
5770 (the class name can be abbreviated):
5771 </p>
5772 </dd>
5773 <dt class="hdlist1">
5775 </dt>
5776 <dd>
5777 <div class="dlist"><dl>
5778 <dt class="hdlist1">
5779 <tt>alnum</tt>
5780 </dt>
5781 <dd>
5783 Any alphabet or digit character.
5784 </p>
5785 </dd>
5786 <dt class="hdlist1">
5787 <tt>alpha</tt>
5788 </dt>
5789 <dd>
5791 Any alphabet character.
5792 </p>
5793 </dd>
5794 <dt class="hdlist1">
5795 <tt>ascii</tt>
5796 </dt>
5797 <dd>
5799 Any character with a value less than 128 (those that are in the 7-bit ascii range).
5800 </p>
5801 </dd>
5802 <dt class="hdlist1">
5803 <tt>control</tt>
5804 </dt>
5805 <dd>
5807 Any control character.
5808 </p>
5809 </dd>
5810 <dt class="hdlist1">
5811 <tt>digit</tt>
5812 </dt>
5813 <dd>
5815 Any digit character.
5816 </p>
5817 </dd>
5818 <dt class="hdlist1">
5819 <tt>double</tt>
5820 </dt>
5821 <dd>
5823 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
5824 In case of under/overflow in the value, 0 is returned.
5825 </p>
5826 </dd>
5827 <dt class="hdlist1">
5828 <tt>graph</tt>
5829 </dt>
5830 <dd>
5832 Any printing character, except space.
5833 </p>
5834 </dd>
5835 <dt class="hdlist1">
5836 <tt>integer</tt>
5837 </dt>
5838 <dd>
5840 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
5841 </p>
5842 </dd>
5843 <dt class="hdlist1">
5844 <tt>lower</tt>
5845 </dt>
5846 <dd>
5848 Any lower case alphabet character.
5849 </p>
5850 </dd>
5851 <dt class="hdlist1">
5852 <tt>print</tt>
5853 </dt>
5854 <dd>
5856 Any printing character, including space.
5857 </p>
5858 </dd>
5859 <dt class="hdlist1">
5860 <tt>punct</tt>
5861 </dt>
5862 <dd>
5864 Any punctuation character.
5865 </p>
5866 </dd>
5867 <dt class="hdlist1">
5868 <tt>space</tt>
5869 </dt>
5870 <dd>
5872 Any space character.
5873 </p>
5874 </dd>
5875 <dt class="hdlist1">
5876 <tt>upper</tt>
5877 </dt>
5878 <dd>
5880 Any upper case alphabet character.
5881 </p>
5882 </dd>
5883 <dt class="hdlist1">
5884 <tt>xdigit</tt>
5885 </dt>
5886 <dd>
5888 Any hexadecimal digit character ([0-9A-Fa-f]).
5889 </p>
5890 </dd>
5891 </dl></div>
5892 </dd>
5893 <dt class="hdlist1">
5895 </dt>
5896 <dd>
5898 Note that string classification does <tt><em>not</em></tt> respect UTF-8. See UTF-8 AND UNICODE
5899 </p>
5900 </dd>
5901 <dt class="hdlist1">
5902 <tt><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></tt>
5903 </dt>
5904 <dd>
5906 Search <tt><em>string2</em></tt> for a sequence of characters that exactly match
5907 the characters in <tt><em>string1</em></tt>. If found, return the index of the
5908 first character in the last such match within <tt><em>string2</em></tt>. If there
5909 is no match, then return -1. If <tt><em>lastIndex</em></tt> is specified, only characters
5910 up to <tt><em>lastIndex</em></tt> of <tt><em>string2</em></tt> will be considered in the match.
5911 </p>
5912 </dd>
5913 <dt class="hdlist1">
5915 </dt>
5916 <dd>
5918 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>lastIndex</em></tt>.
5919 </p>
5920 </dd>
5921 <dt class="hdlist1">
5922 <tt><strong>string length</strong> <em>string</em></tt>
5923 </dt>
5924 <dd>
5926 Returns a decimal string giving the number of characters in <tt><em>string</em></tt>.
5927 If UTF-8 support is enabled, this may be different than the number of bytes.
5928 See UTF-8 AND UNICODE
5929 </p>
5930 </dd>
5931 <dt class="hdlist1">
5932 <tt><strong>string map ?-nocase?</strong> <em>mapping string</em></tt>
5933 </dt>
5934 <dd>
5936 Replaces substrings in <tt><em>string</em></tt> based on the key-value pairs in
5937 <tt><em>mapping</em></tt>, which is a list of <tt>key value key value ...</tt> as in the form
5938 returned by <a href="#_array"><strong><tt>array</tt></strong></a> <tt>get</tt>. Each instance of a key in the string will be
5939 replaced with its corresponding value. If <tt>-nocase</tt> is specified, then
5940 matching is done without regard to case differences. Both key and value may
5941 be multiple characters. Replacement is done in an ordered manner, so the
5942 key appearing first in the list will be checked first, and so on. <tt><em>string</em></tt> is
5943 only iterated over once, so earlier key replacements will have no affect for
5944 later key matches. For example,
5945 </p>
5946 <div class="literalblock">
5947 <div class="content">
5948 <pre><tt>string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc</tt></pre>
5949 </div></div>
5950 </dd>
5951 <dt class="hdlist1">
5953 </dt>
5954 <dd>
5956 will return the string <tt>01321221</tt>.
5957 </p>
5958 </dd>
5959 <dt class="hdlist1">
5961 </dt>
5962 <dd>
5964 Note that if an earlier key is a prefix of a later one, it will completely mask the later
5965 one. So if the previous example is reordered like this,
5966 </p>
5967 <div class="literalblock">
5968 <div class="content">
5969 <pre><tt>string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc</tt></pre>
5970 </div></div>
5971 </dd>
5972 <dt class="hdlist1">
5974 </dt>
5975 <dd>
5977 it will return the string <tt>02c322c222c</tt>.
5978 </p>
5979 </dd>
5980 <dt class="hdlist1">
5981 <tt><strong>string match ?-nocase?</strong> <em>pattern string</em></tt>
5982 </dt>
5983 <dd>
5985 See if <tt><em>pattern</em></tt> matches <tt><em>string</em></tt>; return 1 if it does, 0
5986 if it doesn&#8217;t. Matching is done in a fashion similar to that
5987 used by the C-shell. For the two strings to match, their contents
5988 must be identical except that the following special sequences
5989 may appear in <tt><em>pattern</em></tt>:
5990 </p>
5991 <div class="dlist"><dl>
5992 <dt class="hdlist1">
5993 <tt>*</tt>
5994 </dt>
5995 <dd>
5997 Matches any sequence of characters in <tt><em>string</em></tt>,
5998 including a null string.
5999 </p>
6000 </dd>
6001 <dt class="hdlist1">
6002 <tt>?</tt>
6003 </dt>
6004 <dd>
6006 Matches any single character in <tt><em>string</em></tt>.
6007 </p>
6008 </dd>
6009 <dt class="hdlist1">
6010 <tt>[<em>chars</em>]</tt>
6011 </dt>
6012 <dd>
6014 Matches any character in the set given by <tt><em>chars</em></tt>.
6015 If a sequence of the form <tt><em>x-y</em></tt> appears in <tt><em>chars</em></tt>,
6016 then any character between <tt><em>x</em></tt> and <tt><em>y</em></tt>, inclusive,
6017 will match.
6018 </p>
6019 </dd>
6020 <dt class="hdlist1">
6021 <tt>\x</tt>
6022 </dt>
6023 <dd>
6025 Matches the single character <tt><em>x</em></tt>. This provides a way of
6026 avoiding the special interpretation of the characters <tt>\*?[]</tt>
6027 in <tt><em>pattern</em></tt>.
6028 </p>
6029 </dd>
6030 </dl></div>
6031 </dd>
6032 <dt class="hdlist1">
6034 </dt>
6035 <dd>
6037 Performs a case-insensitive comparison if <tt>-nocase</tt> is specified.
6038 </p>
6039 </dd>
6040 <dt class="hdlist1">
6041 <tt><strong>string range</strong> <em>string first last</em></tt>
6042 </dt>
6043 <dd>
6045 Returns a range of consecutive characters from <tt><em>string</em></tt>, starting
6046 with the character whose index is <tt><em>first</em></tt> and ending with the
6047 character whose index is <tt><em>last</em></tt>. An index of 0 refers to the
6048 first character of the string.
6049 </p>
6050 </dd>
6051 <dt class="hdlist1">
6053 </dt>
6054 <dd>
6056 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>first</em></tt> and <tt><em>last</em></tt>.
6057 </p>
6058 </dd>
6059 <dt class="hdlist1">
6061 </dt>
6062 <dd>
6064 If <tt><em>first</em></tt> is less than zero then it is treated as if it were zero, and
6065 if <tt><em>last</em></tt> is greater than or equal to the length of the string then
6066 it is treated as if it were <tt>end</tt>. If <tt><em>first</em></tt> is greater than
6067 <tt><em>last</em></tt> then an empty string is returned.
6068 </p>
6069 </dd>
6070 <dt class="hdlist1">
6071 <tt><strong>string repeat</strong> <em>string count</em></tt>
6072 </dt>
6073 <dd>
6075 Returns a new string consisting of <tt><em>string</em></tt> repeated <tt><em>count</em></tt> times.
6076 </p>
6077 </dd>
6078 <dt class="hdlist1">
6079 <tt><strong>string reverse</strong> <em>string</em></tt>
6080 </dt>
6081 <dd>
6083 Returns a string that is the same length as <tt><em>string</em></tt> but
6084 with its characters in the reverse order.
6085 </p>
6086 </dd>
6087 <dt class="hdlist1">
6088 <tt><strong>string tolower</strong> <em>string</em></tt>
6089 </dt>
6090 <dd>
6092 Returns a value equal to <tt><em>string</em></tt> except that all upper case
6093 letters have been converted to lower case.
6094 </p>
6095 </dd>
6096 <dt class="hdlist1">
6097 <tt><strong>string toupper</strong> <em>string</em></tt>
6098 </dt>
6099 <dd>
6101 Returns a value equal to <tt><em>string</em></tt> except that all lower case
6102 letters have been converted to upper case.
6103 </p>
6104 </dd>
6105 <dt class="hdlist1">
6106 <tt><strong>string trim</strong> <em>string ?chars?</em></tt>
6107 </dt>
6108 <dd>
6110 Returns a value equal to <tt><em>string</em></tt> except that any leading
6111 or trailing characters from the set given by <tt><em>chars</em></tt> are
6112 removed.
6113 If <tt><em>chars</em></tt> is not specified then white space is removed
6114 (spaces, tabs, newlines, and carriage returns).
6115 </p>
6116 </dd>
6117 <dt class="hdlist1">
6118 <tt><strong>string trimleft</strong> <em>string ?chars?</em></tt>
6119 </dt>
6120 <dd>
6122 Returns a value equal to <tt><em>string</em></tt> except that any
6123 leading characters from the set given by <tt><em>chars</em></tt> are
6124 removed.
6125 If <tt><em>chars</em></tt> is not specified then white space is removed
6126 (spaces, tabs, newlines, and carriage returns).
6127 </p>
6128 </dd>
6129 <dt class="hdlist1">
6130 <tt><strong>string trimright</strong> <em>string ?chars?</em></tt>
6131 </dt>
6132 <dd>
6134 Returns a value equal to <tt><em>string</em></tt> except that any
6135 trailing characters from the set given by <tt><em>chars</em></tt> are
6136 removed.
6137 If <tt><em>chars</em></tt> is not specified then white space is removed
6138 (spaces, tabs, newlines, and carriage returns).
6139 Null characters are always removed.
6140 </p>
6141 </dd>
6142 </dl></div>
6143 </div>
6144 <div class="sect2">
6145 <h3 id="_subst">subst</h3>
6146 <div class="paragraph"><p><tt><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></tt></p></div>
6147 <div class="paragraph"><p>This command performs variable substitutions, command substitutions,
6148 and backslash substitutions on its string argument and returns the
6149 fully-substituted result. The substitutions are performed in exactly
6150 the same way as for Tcl commands. As a result, the string argument
6151 is actually substituted twice, once by the Tcl parser in the usual
6152 fashion for Tcl commands, and again by the subst command.</p></div>
6153 <div class="paragraph"><p>If any of the <tt>-nobackslashes</tt>, <tt>-nocommands</tt>, or <tt>-novariables</tt> are
6154 specified, then the corresponding substitutions are not performed.
6155 For example, if <tt>-nocommands</tt> is specified, no command substitution
6156 is performed: open and close brackets are treated as ordinary
6157 characters with no special interpretation.</p></div>
6158 <div class="paragraph"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
6159 special treatment to double quotes or curly braces. For example,
6160 the following script returns <tt>xyz {44}</tt>, not <tt>xyz {$a}</tt>.</p></div>
6161 <div class="literalblock">
6162 <div class="content">
6163 <pre><tt>set a 44
6164 subst {xyz {$a}}</tt></pre>
6165 </div></div>
6166 </div>
6167 <div class="sect2">
6168 <h3 id="_switch">switch</h3>
6169 <div class="paragraph"><p><tt><strong>switch</strong> <em>?options? string pattern body ?pattern body ...?</em></tt></p></div>
6170 <div class="paragraph"><p><tt><strong>switch</strong> <em>?options? string {pattern body ?pattern body ...?}</em></tt></p></div>
6171 <div class="paragraph"><p>The <a href="#_switch"><strong><tt>switch</tt></strong></a> command matches its string argument against each of
6172 the pattern arguments in order. As soon as it finds a pattern that
6173 matches string it evaluates the following body and returns the
6174 result of that evaluation. If the last pattern argument is default
6175 then it matches anything. If no pattern argument matches string and
6176 no default is given, then the <a href="#_switch"><strong><tt>switch</tt></strong></a> command returns an empty string.
6177 If the initial arguments to switch start with - then they are treated
6178 as options. The following options are currently supported:</p></div>
6179 <div class="dlist"><dl>
6180 <dt class="hdlist1">
6181 <tt>-exact</tt>
6182 </dt>
6183 <dd>
6185 Use exact matching when comparing string to a
6186 pattern. This is the default.
6187 </p>
6188 </dd>
6189 <dt class="hdlist1">
6190 <tt>-glob</tt>
6191 </dt>
6192 <dd>
6194 When matching string to the patterns, use glob-style
6195 matching (i.e. the same as implemented by the string
6196 match command).
6197 </p>
6198 </dd>
6199 <dt class="hdlist1">
6200 <tt>-regexp</tt>
6201 </dt>
6202 <dd>
6204 When matching string to the patterns, use regular
6205 expression matching (i.e. the same as implemented
6206 by the regexp command).
6207 </p>
6208 </dd>
6209 <dt class="hdlist1">
6210 <tt>-command <em>commandname</em></tt>
6211 </dt>
6212 <dd>
6214 When matching string to the patterns, use the given command, which
6215 must be a single word. The command is invoked as
6216 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
6217 and must return 1 if matched, or 0 if not.
6218 </p>
6219 </dd>
6220 <dt class="hdlist1">
6221 <tt>--</tt>
6222 </dt>
6223 <dd>
6225 Marks the end of options. The argument following
6226 this one will be treated as string even if it starts
6227 with a <tt>-</tt>.
6228 </p>
6229 </dd>
6230 </dl></div>
6231 <div class="paragraph"><p>Two syntaxes are provided for the pattern and body arguments. The
6232 first uses a separate argument for each of the patterns and commands;
6233 this form is convenient if substitutions are desired on some of the
6234 patterns or commands. The second form places all of the patterns
6235 and commands together into a single argument; the argument must
6236 have proper list structure, with the elements of the list being the
6237 patterns and commands. The second form makes it easy to construct
6238 multi-line <a href="#_switch"><strong><tt>switch</tt></strong></a> commands, since the braces around the whole list
6239 make it unnecessary to include a backslash at the end of each line.
6240 Since the pattern arguments are in braces in the second form, no
6241 command or variable substitutions are performed on them; this makes
6242 the behaviour of the second form different than the first form in
6243 some cases.</p></div>
6244 <div class="paragraph"><p>If a body is specified as <tt>-</tt> it means that the body for the next
6245 pattern should also be used as the body for this pattern (if the
6246 next pattern also has a body of <tt>-</tt> then the body after that is
6247 used, and so on). This feature makes it possible to share a single
6248 body among several patterns.</p></div>
6249 <div class="paragraph"><p>Below are some examples of <a href="#_switch"><strong><tt>switch</tt></strong></a> commands:</p></div>
6250 <div class="literalblock">
6251 <div class="content">
6252 <pre><tt>switch abc a - b {format 1} abc {format 2} default {format 3}</tt></pre>
6253 </div></div>
6254 <div class="paragraph"><p>will return 2,</p></div>
6255 <div class="literalblock">
6256 <div class="content">
6257 <pre><tt>switch -regexp aaab {
6258 ^a.*b$ -
6259 b {format 1}
6260 a* {format 2}
6261 default {format 3}
6262 }</tt></pre>
6263 </div></div>
6264 <div class="paragraph"><p>will return 1, and</p></div>
6265 <div class="literalblock">
6266 <div class="content">
6267 <pre><tt>switch xyz {
6269 b {format 1}
6270 a* {format 2}
6271 default {format 3}
6272 }</tt></pre>
6273 </div></div>
6274 <div class="paragraph"><p>will return 3.</p></div>
6275 </div>
6276 <div class="sect2">
6277 <h3 id="_tailcall">tailcall</h3>
6278 <div class="paragraph"><p><tt><strong>tailcall</strong> <em>cmd ?arg...?</em></tt></p></div>
6279 <div class="paragraph"><p>The <a href="#_tailcall"><strong><tt>tailcall</tt></strong></a> command provides an optimised way of invoking a command whilst replacing
6280 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
6281 <div class="paragraph"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
6282 <div class="literalblock">
6283 <div class="content">
6284 <pre><tt>tailcall a b c</tt></pre>
6285 </div></div>
6286 <div class="literalblock">
6287 <div class="content">
6288 <pre><tt>return [uplevel 1 a b c]</tt></pre>
6289 </div></div>
6290 <div class="paragraph"><p><a href="#_tailcall"><strong><tt>tailcall</tt></strong></a> is useful for a dispatch mechanism:</p></div>
6291 <div class="literalblock">
6292 <div class="content">
6293 <pre><tt>proc a {cmd args} {
6294 tailcall sub_$cmd {*}$args
6296 proc sub_cmd1 ...
6297 proc sub_cmd2 ...</tt></pre>
6298 </div></div>
6299 </div>
6300 <div class="sect2">
6301 <h3 id="_tell">tell</h3>
6302 <div class="paragraph"><p><tt><strong>tell</strong> <em>fileId</em></tt></p></div>
6303 <div class="paragraph"><p><tt><em>fileId</em> <strong>tell</strong></tt></p></div>
6304 <div class="paragraph"><p>Returns a decimal string giving the current access position in
6305 <tt><em>fileId</em></tt>.</p></div>
6306 <div class="paragraph"><p><tt><em>fileId</em></tt> must have been the return value from a previous call to
6307 <a href="#_open"><strong><tt>open</tt></strong></a>, or it may be <tt>stdin</tt>, <tt>stdout</tt>, or <tt>stderr</tt> to refer to one
6308 of the standard I/O channels.</p></div>
6309 </div>
6310 <div class="sect2">
6311 <h3 id="_throw">throw</h3>
6312 <div class="paragraph"><p><tt><strong>throw</strong> <em>code ?msg?</em></tt></p></div>
6313 <div class="paragraph"><p>This command throws an exception (return) code along with an optional message.
6314 This command is mostly for convenient usage with <a href="#_try"><strong><tt>try</tt></strong></a>.</p></div>
6315 <div class="paragraph"><p>The command <tt>throw break</tt> is equivalent to <tt>break</tt>.
6316 The command <tt>throw 20 message</tt> can be caught with an <tt>on 20 ...</tt> clause to <a href="#_try"><strong><tt>try</tt></strong></a>.</p></div>
6317 </div>
6318 <div class="sect2">
6319 <h3 id="_time">time</h3>
6320 <div class="paragraph"><p><tt><strong>time</strong> <em>command ?count?</em></tt></p></div>
6321 <div class="paragraph"><p>This command will call the Tcl interpreter <tt><em>count</em></tt>
6322 times to execute <tt><em>command</em></tt> (or once if <tt><em>count</em></tt> isn&#8217;t
6323 specified). It will then return a string of the form</p></div>
6324 <div class="literalblock">
6325 <div class="content">
6326 <pre><tt>503 microseconds per iteration</tt></pre>
6327 </div></div>
6328 <div class="paragraph"><p>which indicates the average amount of time required per iteration,
6329 in microseconds.</p></div>
6330 <div class="paragraph"><p>Time is measured in elapsed time, not CPU time.</p></div>
6331 </div>
6332 <div class="sect2">
6333 <h3 id="_try">try</h3>
6334 <div class="paragraph"><p><tt><strong>try</strong> <em>?catchopts? tryscript</em> ?<strong>on</strong> <em>returncodes {?resultvar? ?optsvar?} handlerscript ...</em>? ?<strong>finally</strong> <em>finalscript</em>?</tt></p></div>
6335 <div class="paragraph"><p>The <a href="#_try"><strong><tt>try</tt></strong></a> command is provided as a convenience for exception handling.</p></div>
6336 <div class="paragraph"><p>This interpeter first evaluates <tt><em>tryscript</em></tt> under the effect of the catch
6337 options <tt><em>catchopts</em></tt> (e.g. <tt>-signal -noexit --</tt>, see <a href="#_catch"><strong><tt>catch</tt></strong></a>).</p></div>
6338 <div class="paragraph"><p>It then evaluates the script for the first matching <em>on</em> handler
6339 (there many be zero or more) based on the return code from the <a href="#_try"><strong><tt>try</tt></strong></a>
6340 section. For example a normal <tt>JIM_ERR</tt> error will be matched by
6341 an <em>on error</em> handler.</p></div>
6342 <div class="paragraph"><p>Finally, any <tt><em>finalscript</em></tt> is evaluated.</p></div>
6343 <div class="paragraph"><p>The result of this command is the result of <tt><em>tryscript</em></tt>, except in the
6344 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
6345 in which case the result is this new exception.</p></div>
6346 <div class="paragraph"><p>The specified <tt><em>returncodes</em></tt> is a list of return codes either as names (<em>ok</em>, <em>error</em>, <em>break</em>, etc.)
6347 or as integers.</p></div>
6348 <div class="paragraph"><p>If <tt><em>resultvar</em></tt> and <tt><em>optsvar</em></tt> are specified, they are set as for <a href="#_catch"><strong><tt>catch</tt></strong></a> before evaluating
6349 the matching handler.</p></div>
6350 <div class="paragraph"><p>For example:</p></div>
6351 <div class="literalblock">
6352 <div class="content">
6353 <pre><tt>set f [open input]
6354 try -signal {
6355 process $f
6356 } on {continue break} {} {
6357 error "Unexpected break/continue"
6358 } on error {msg opts} {
6359 puts "Dealing with error"
6360 return {*}$opts $msg
6361 } on signal sig {
6362 puts "Got signal: $sig"
6363 } finally {
6364 $f close
6365 }</tt></pre>
6366 </div></div>
6367 <div class="paragraph"><p>If break, continue or error are raised, they are dealt with by the matching
6368 handler.</p></div>
6369 <div class="paragraph"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6370 <div class="paragraph"><p>See also <a href="#_throw"><strong><tt>throw</tt></strong></a>, <a href="#_catch"><strong><tt>catch</tt></strong></a>, <a href="#_return"><strong><tt>return</tt></strong></a>, <a href="#_error"><strong><tt>error</tt></strong></a>.</p></div>
6371 </div>
6372 <div class="sect2">
6373 <h3 id="_unknown">unknown</h3>
6374 <div class="paragraph"><p><tt><strong>unknown</strong> <em>cmdName ?arg arg &#8230;?</em></tt></p></div>
6375 <div class="paragraph"><p>This command doesn&#8217;t actually exist as part of Tcl, but Tcl will
6376 invoke it if it does exist.</p></div>
6377 <div class="paragraph"><p>If the Tcl interpreter encounters a command name for which there
6378 is not a defined command, then Tcl checks for the existence of
6379 a command named <a href="#_unknown"><strong><tt>unknown</tt></strong></a>.</p></div>
6380 <div class="paragraph"><p>If there is no such command, then the interpreter returns an
6381 error.</p></div>
6382 <div class="paragraph"><p>If the <a href="#_unknown"><strong><tt>unknown</tt></strong></a> command exists, then it is invoked with
6383 arguments consisting of the fully-substituted name and arguments
6384 for the original non-existent command.</p></div>
6385 <div class="paragraph"><p>The <a href="#_unknown"><strong><tt>unknown</tt></strong></a> command typically does things like searching
6386 through library directories for a command procedure with the name
6387 <tt><em>cmdName</em></tt>, or expanding abbreviated command names to full-length,
6388 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6389 <div class="paragraph"><p>In some cases (such as expanding abbreviations) <a href="#_unknown"><strong><tt>unknown</tt></strong></a> will
6390 change the original command slightly and then (re-)execute it.
6391 The result of the <a href="#_unknown"><strong><tt>unknown</tt></strong></a> command is used as the result for
6392 the original non-existent command.</p></div>
6393 </div>
6394 <div class="sect2">
6395 <h3 id="_unset">unset</h3>
6396 <div class="paragraph"><p><tt><strong>unset ?-nocomplain? ?--?</strong> <em>?name name &#8230;?</em></tt></p></div>
6397 <div class="paragraph"><p>Remove variables.
6398 Each <tt><em>name</em></tt> is a variable name, specified in any of the
6399 ways acceptable to the <a href="#_set"><strong><tt>set</tt></strong></a> command.</p></div>
6400 <div class="paragraph"><p>If a <tt><em>name</em></tt> refers to an element of an array, then that
6401 element is removed without affecting the rest of the array.</p></div>
6402 <div class="paragraph"><p>If a <tt><em>name</em></tt> consists of an array name with no parenthesized
6403 index, then the entire array is deleted.</p></div>
6404 <div class="paragraph"><p>The <a href="#_unset"><strong><tt>unset</tt></strong></a> command returns an empty string as result.</p></div>
6405 <div class="paragraph"><p>An error occurs if any of the variables doesn&#8217;t exist, unless <em>-nocomplain</em>
6406 is specified. The <em>--</em> argument may be specified to stop option processing
6407 in case the variable name may be <em>-nocomplain</em>.</p></div>
6408 </div>
6409 <div class="sect2">
6410 <h3 id="_upcall">upcall</h3>
6411 <div class="paragraph"><p><tt><strong>upcall</strong> <em>command ?args &#8230;?</em></tt></p></div>
6412 <div class="paragraph"><p>May be used from within a proc defined as <a href="#_local"><strong><tt>local</tt></strong></a> <a href="#_proc"><strong><tt>proc</tt></strong></a> in order to call
6413 the previous, hidden version of the same command.</p></div>
6414 <div class="paragraph"><p>If there is no previous definition of the command, an error is returned.</p></div>
6415 </div>
6416 <div class="sect2">
6417 <h3 id="_uplevel">uplevel</h3>
6418 <div class="paragraph"><p><tt><strong>uplevel</strong> <em>?level? command ?command &#8230;?</em></tt></p></div>
6419 <div class="paragraph"><p>All of the <tt><em>command</em></tt> arguments are concatenated as if they had
6420 been passed to <a href="#_concat"><strong><tt>concat</tt></strong></a>; the result is then evaluated in the
6421 variable context indicated by <tt><em>level</em></tt>. <a href="#_uplevel"><strong><tt>uplevel</tt></strong></a> returns
6422 the result of that evaluation. If <tt><em>level</em></tt> is an integer, then
6423 it gives a distance (up the procedure calling stack) to move before
6424 executing the command. If <tt><em>level</em></tt> consists of <tt>#</tt> followed by
6425 a number then the number gives an absolute level number. If <tt><em>level</em></tt>
6426 is omitted then it defaults to <tt>1</tt>. <tt><em>level</em></tt> cannot be
6427 defaulted if the first <tt><em>command</em></tt> argument starts with a digit or <tt>#</tt>.</p></div>
6428 <div class="paragraph"><p>For example, suppose that procedure <em>a</em> was invoked
6429 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6430 Suppose that <em>c</em> invokes the <a href="#_uplevel"><strong><tt>uplevel</tt></strong></a> command. If <tt><em>level</em></tt>
6431 is <tt>1</tt> or <tt>#2</tt> or omitted, then the command will be executed
6432 in the variable context of <em>b</em>. If <tt><em>level</em></tt> is <tt>2</tt> or <tt>#1</tt>
6433 then the command will be executed in the variable context of <em>a</em>.</p></div>
6434 <div class="paragraph"><p>If <tt><em>level</em></tt> is <em>3</em> or <tt>#0</tt> then the command will be executed
6435 at top-level (only global variables will be visible).
6436 The <a href="#_uplevel"><strong><tt>uplevel</tt></strong></a> command causes the invoking procedure to disappear
6437 from the procedure calling stack while the command is being executed.
6438 In the above example, suppose <em>c</em> invokes the command</p></div>
6439 <div class="literalblock">
6440 <div class="content">
6441 <pre><tt>uplevel 1 {set x 43; d}</tt></pre>
6442 </div></div>
6443 <div class="paragraph"><p>where <em>d</em> is another Tcl procedure. The <a href="#_set"><strong><tt>set</tt></strong></a> command will
6444 modify the variable <em>x</em> in <em>b&#8217;s context, and 'd</em> will execute
6445 at level 3, as if called from <em>b</em>. If it in turn executes
6446 the command</p></div>
6447 <div class="literalblock">
6448 <div class="content">
6449 <pre><tt>uplevel {set x 42}</tt></pre>
6450 </div></div>
6451 <div class="paragraph"><p>then the <a href="#_set"><strong><tt>set</tt></strong></a> command will modify the same variable <em>x</em> in <em>b&#8217;s
6452 context: the procedure 'c</em> does not appear to be on the call stack
6453 when <em>d</em> is executing. The command <a href="#_info"><strong><tt>info</tt></strong></a> <tt>level</tt> may
6454 be used to obtain the level of the current procedure.</p></div>
6455 <div class="paragraph"><p><a href="#_uplevel"><strong><tt>uplevel</tt></strong></a> makes it possible to implement new control
6456 constructs as Tcl procedures (for example, <a href="#_uplevel"><strong><tt>uplevel</tt></strong></a> could
6457 be used to implement the <a href="#_while"><strong><tt>while</tt></strong></a> construct as a Tcl procedure).</p></div>
6458 </div>
6459 <div class="sect2">
6460 <h3 id="_upvar">upvar</h3>
6461 <div class="paragraph"><p><tt><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar &#8230;?</em></tt></p></div>
6462 <div class="paragraph"><p>This command arranges for one or more local variables in the current
6463 procedure to refer to variables in an enclosing procedure call or
6464 to global variables.</p></div>
6465 <div class="paragraph"><p><tt><em>level</em></tt> may have any of the forms permitted for the <a href="#_uplevel"><strong><tt>uplevel</tt></strong></a>
6466 command, and may be omitted if the first letter of the first <tt><em>otherVar</em></tt>
6467 isn&#8217;t <tt>#</tt> or a digit (it defaults to <em>1</em>).</p></div>
6468 <div class="paragraph"><p>For each <tt><em>otherVar</em></tt> argument, <a href="#_upvar"><strong><tt>upvar</tt></strong></a> makes the variable
6469 by that name in the procedure frame given by <tt><em>level</em></tt> (or at
6470 global level, if <tt><em>level</em></tt> is <tt>#0</tt>) accessible
6471 in the current procedure by the name given in the corresponding
6472 <tt><em>myVar</em></tt> argument.</p></div>
6473 <div class="paragraph"><p>The variable named by <tt><em>otherVar</em></tt> need not exist at the time of the
6474 call; it will be created the first time <tt><em>myVar</em></tt> is referenced, just like
6475 an ordinary variable.</p></div>
6476 <div class="paragraph"><p><a href="#_upvar"><strong><tt>upvar</tt></strong></a> may only be invoked from within procedures.</p></div>
6477 <div class="paragraph"><p><a href="#_upvar"><strong><tt>upvar</tt></strong></a> returns an empty string.</p></div>
6478 <div class="paragraph"><p>The <a href="#_upvar"><strong><tt>upvar</tt></strong></a> command simplifies the implementation of call-by-name
6479 procedure calling and also makes it easier to build new control constructs
6480 as Tcl procedures.
6481 For example, consider the following procedure:</p></div>
6482 <div class="literalblock">
6483 <div class="content">
6484 <pre><tt>proc add2 name {
6485 upvar $name x
6486 set x [expr $x+2]
6487 }</tt></pre>
6488 </div></div>
6489 <div class="paragraph"><p><em>add2</em> is invoked with an argument giving the name of a variable,
6490 and it adds two to the value of that variable.
6491 Although <em>add2</em> could have been implemented using <a href="#_uplevel"><strong><tt>uplevel</tt></strong></a>
6492 instead of <a href="#_upvar"><strong><tt>upvar</tt></strong></a>, <a href="#_upvar"><strong><tt>upvar</tt></strong></a> makes it simpler for <em>add2</em>
6493 to access the variable in the caller&#8217;s procedure frame.</p></div>
6494 </div>
6495 <div class="sect2">
6496 <h3 id="_while">while</h3>
6497 <div class="paragraph"><p><tt><strong>while</strong> <em>test body</em></tt></p></div>
6498 <div class="paragraph"><p>The <tt><em>while</em></tt> command evaluates <tt><em>test</em></tt> as an expression
6499 (in the same way that <a href="#_expr"><strong><tt>expr</tt></strong></a> evaluates its argument).
6500 The value of the expression must be numeric; if it is non-zero
6501 then <tt><em>body</em></tt> is executed by passing it to the Tcl interpreter.</p></div>
6502 <div class="paragraph"><p>Once <tt><em>body</em></tt> has been executed then <tt><em>test</em></tt> is evaluated
6503 again, and the process repeats until eventually <tt><em>test</em></tt>
6504 evaluates to a zero numeric value. <a href="#_continue"><strong><tt>continue</tt></strong></a>
6505 commands may be executed inside <tt><em>body</em></tt> to terminate the current
6506 iteration of the loop, and <a href="#_break"><strong><tt>break</tt></strong></a>
6507 commands may be executed inside <tt><em>body</em></tt> to cause immediate
6508 termination of the <a href="#_while"><strong><tt>while</tt></strong></a> command.</p></div>
6509 <div class="paragraph"><p>The <a href="#_while"><strong><tt>while</tt></strong></a> command always returns an empty string.</p></div>
6510 </div>
6511 </div>
6512 </div>
6513 <div class="sect1">
6514 <h2 id="_optional_extensions">OPTIONAL-EXTENSIONS</h2>
6515 <div class="sectionbody">
6516 <div class="paragraph"><p>The following extensions may or may not be available depending upon
6517 what options were selected when Jim Tcl was built.</p></div>
6518 <div class="sect2">
6519 <h3 id="cmd_1">posix: os.fork, os.wait, os.gethostname, os.getids, os.uptime</h3>
6520 <div class="dlist"><dl>
6521 <dt class="hdlist1">
6522 <tt><strong>os.fork</strong></tt>
6523 </dt>
6524 <dd>
6526 Invokes <em>fork(2)</em> and returns the result.
6527 </p>
6528 </dd>
6529 <dt class="hdlist1">
6530 <tt><strong>os.wait -nohang</strong> <em>pid</em></tt>
6531 </dt>
6532 <dd>
6534 Invokes waitpid(2), with WNOHANG if <tt>-nohang</tt> is specified.
6535 Returns a list of 3 elements.
6536 </p>
6537 <div class="literalblock">
6538 <div class="content">
6539 <pre><tt>{0 none 0} if -nohang is specified, and the process is still alive.</tt></pre>
6540 </div></div>
6541 <div class="literalblock">
6542 <div class="content">
6543 <pre><tt>{-1 error &lt;error-description&gt;} if the process does not exist or has already been waited for.</tt></pre>
6544 </div></div>
6545 <div class="literalblock">
6546 <div class="content">
6547 <pre><tt>{&lt;pid&gt; exit &lt;exit-status&gt;} if the process exited normally.</tt></pre>
6548 </div></div>
6549 <div class="literalblock">
6550 <div class="content">
6551 <pre><tt>{&lt;pid&gt; signal &lt;signal-number&gt;} if the process terminated on a signal.</tt></pre>
6552 </div></div>
6553 <div class="literalblock">
6554 <div class="content">
6555 <pre><tt>{&lt;pid&gt; other 0} otherwise (core dump, stopped, continued, etc.)</tt></pre>
6556 </div></div>
6557 </dd>
6558 <dt class="hdlist1">
6559 <tt><strong>os.gethostname</strong></tt>
6560 </dt>
6561 <dd>
6563 Invokes <em>gethostname(3)</em> and returns the result.
6564 </p>
6565 </dd>
6566 <dt class="hdlist1">
6567 <tt><strong>os.getids</strong></tt>
6568 </dt>
6569 <dd>
6571 Returns the various user/group ids for the current process.
6572 </p>
6573 <div class="literalblock">
6574 <div class="content">
6575 <pre><tt>jim&gt; os.getids
6576 uid 1000 euid 1000 gid 100 egid 100</tt></pre>
6577 </div></div>
6578 </dd>
6579 <dt class="hdlist1">
6580 <tt><strong>os.uptime</strong></tt>
6581 </dt>
6582 <dd>
6584 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
6585 </p>
6586 </dd>
6587 </dl></div>
6588 </div>
6589 </div>
6590 </div>
6591 <div class="sect1">
6592 <h2 id="_ansi_i_o_aio_and_eventloop_api">ANSI I/O (aio) and EVENTLOOP API</h2>
6593 <div class="sectionbody">
6594 <div class="paragraph"><p>Jim provides an alternative object-based API for I/O.</p></div>
6595 <div class="paragraph"><p>See <a href="#_open"><strong><tt>open</tt></strong></a> and <a href="#_socket"><strong><tt>socket</tt></strong></a> for commands which return an I/O handle.</p></div>
6596 <div class="sect2">
6597 <h3 id="_aio">aio</h3>
6598 <div class="dlist"><dl>
6599 <dt class="hdlist1">
6600 <tt>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></tt>
6601 </dt>
6602 <dd>
6604 Read and return bytes from the stream. To eof if no len.
6605 </p>
6606 </dd>
6607 <dt class="hdlist1">
6608 <tt>$handle <strong>gets</strong> <em>?var?</em></tt>
6609 </dt>
6610 <dd>
6612 Read one line and return it or store it in the var
6613 </p>
6614 </dd>
6615 <dt class="hdlist1">
6616 <tt>$handle <strong>puts ?-nonewline?</strong> <em>str</em></tt>
6617 </dt>
6618 <dd>
6620 Write the string, with newline unless -nonewline
6621 </p>
6622 </dd>
6623 <dt class="hdlist1">
6624 <tt>$handle <strong>copyto</strong> <em>tofd ?size?</em></tt>
6625 </dt>
6626 <dd>
6628 Copy bytes to the file descriptor <tt><em>tofd</em></tt>. If <tt><em>size</em></tt> is specified, at most
6629 that many bytes will be copied. Otherwise copying continues until the end
6630 of the input file. Returns the number of bytes actually copied.
6631 </p>
6632 </dd>
6633 <dt class="hdlist1">
6634 <tt>$handle <strong>flush</strong></tt>
6635 </dt>
6636 <dd>
6638 Flush the stream
6639 </p>
6640 </dd>
6641 <dt class="hdlist1">
6642 <tt>$handle <strong>filename</strong></tt>
6643 </dt>
6644 <dd>
6646 Returns the original filename associated with the handle.
6647 Handles returned by <a href="#_socket"><strong><tt>socket</tt></strong></a> give the socket type instead of a filename.
6648 </p>
6649 </dd>
6650 <dt class="hdlist1">
6651 <tt>$handle <strong>eof</strong></tt>
6652 </dt>
6653 <dd>
6655 Returns 1 if stream is at eof
6656 </p>
6657 </dd>
6658 <dt class="hdlist1">
6659 <tt>$handle <strong>close</strong></tt>
6660 </dt>
6661 <dd>
6663 Closes the stream
6664 </p>
6665 </dd>
6666 <dt class="hdlist1">
6667 <tt>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></tt>
6668 </dt>
6669 <dd>
6671 Seeks in the stream (default <em>current</em>)
6672 </p>
6673 </dd>
6674 <dt class="hdlist1">
6675 <tt>$handle <strong>tell</strong></tt>
6676 </dt>
6677 <dd>
6679 Returns the current seek position
6680 </p>
6681 </dd>
6682 <dt class="hdlist1">
6683 <tt>$handle <strong>filename</strong></tt>
6684 </dt>
6685 <dd>
6687 Returns the original filename used when opening the file.
6688 If the handle was returned from <a href="#_socket"><strong><tt>socket</tt></strong></a>, the type of the
6689 handle is returned instead.
6690 </p>
6691 </dd>
6692 <dt class="hdlist1">
6693 <tt>$handle <strong>ndelay ?0|1?</strong></tt>
6694 </dt>
6695 <dd>
6697 Set O_NDELAY (if arg). Returns current/new setting.
6698 Note that in general ANSI I/O interacts badly with non-blocking I/O.
6699 Use with care.
6700 </p>
6701 </dd>
6702 <dt class="hdlist1">
6703 <tt>$handle <strong>buffering none|line|full</strong></tt>
6704 </dt>
6705 <dd>
6707 Sets the buffering mode of the stream.
6708 </p>
6709 </dd>
6710 <dt class="hdlist1">
6711 <tt>$handle <strong>accept</strong></tt>
6712 </dt>
6713 <dd>
6715 Server socket only: Accept a connection and return stream
6716 </p>
6717 </dd>
6718 <dt class="hdlist1">
6719 <tt>$handle <strong>sendto</strong> <em>str ?hostname:?port</em></tt>
6720 </dt>
6721 <dd>
6723 Sends the string, <tt><em>str</em></tt>, to the given address via the socket using sendto(2).
6724 This is intended for udp sockets and may give an error or behave in unintended
6725 ways for other handle types.
6726 Returns the number of bytes written.
6727 </p>
6728 </dd>
6729 <dt class="hdlist1">
6730 <tt>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></tt>
6731 </dt>
6732 <dd>
6734 Receives a message from the handle via recvfrom(2) and returns it.
6735 At most <tt><em>maxlen</em></tt> bytes are read.
6736 If <tt><em>addrvar</em></tt> is specified, the sending address of the message is stored in
6737 the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><tt>socket</tt></strong></a> for details.
6738 </p>
6739 </dd>
6740 </dl></div>
6741 </div>
6742 <div class="sect2">
6743 <h3 id="_fconfigure">fconfigure</h3>
6744 <div class="dlist"><dl>
6745 <dt class="hdlist1">
6746 <tt><strong>fconfigure</strong> <em>handle</em> <strong>?-blocking 0|1? ?-buffering noneline|full? ?-translation</strong> <em>mode</em>?</tt>
6747 </dt>
6748 <dd>
6750 For compatibility with Tcl, a limited form of the <a href="#_fconfigure"><strong><tt>fconfigure</tt></strong></a>
6751 command is supported.
6752 </p>
6753 <div class="ulist"><ul>
6754 <li>
6756 <a href="#_fconfigure"><strong><tt>fconfigure</tt></strong></a> <tt>... -blocking</tt> maps to <a href="#_aio"><strong><tt>aio</tt></strong></a> <tt>ndelay</tt>
6757 </p>
6758 </li>
6759 <li>
6761 <a href="#_fconfigure"><strong><tt>fconfigure</tt></strong></a> <tt>... -buffering</tt> maps to <a href="#_aio"><strong><tt>aio</tt></strong></a> <tt>buffering</tt>
6762 </p>
6763 </li>
6764 <li>
6766 <a href="#_fconfigure"><strong><tt>fconfigure</tt></strong></a> <tt>... -translation</tt> is accepted but ignored
6767 </p>
6768 </li>
6769 </ul></div>
6770 </dd>
6771 </dl></div>
6772 </div>
6773 <div class="sect2">
6774 <h3 id="cmd_2">eventloop: after, vwait, update</h3>
6775 <div class="paragraph"><p>The following commands allow a script to be invoked when the given condition occurs.
6776 If no script is given, returns the current script. If the given script is the empty, the
6777 handler is removed.</p></div>
6778 <div class="dlist"><dl>
6779 <dt class="hdlist1">
6780 <tt>$handle <strong>readable</strong> <em>?readable-script?</em></tt>
6781 </dt>
6782 <dd>
6784 Sets or returns the script for when the socket is readable.
6785 </p>
6786 </dd>
6787 <dt class="hdlist1">
6788 <tt>$handle <strong>writable</strong> <em>?writable-script?</em></tt>
6789 </dt>
6790 <dd>
6792 Sets or returns the script for when the socket is writable.
6793 </p>
6794 </dd>
6795 <dt class="hdlist1">
6796 <tt>$handle <strong>onexception</strong> <em>?exception-script?</em></tt>
6797 </dt>
6798 <dd>
6800 Sets or returns the script for when when oob data received.
6801 </p>
6802 </dd>
6803 </dl></div>
6804 <div class="paragraph"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <tt>fileevent</tt>. e.g.</p></div>
6805 <div class="dlist"><dl>
6806 <dt class="hdlist1">
6808 </dt>
6809 <dd>
6811 <tt>fileevent $handle <strong>readable</strong> <em>...</em></tt>
6812 </p>
6813 </dd>
6814 </dl></div>
6815 <div class="paragraph"><p>Time-based execution is also available via the eventloop API.</p></div>
6816 <div class="dlist"><dl>
6817 <dt class="hdlist1">
6818 <tt><strong>after</strong> <em>ms</em></tt>
6819 </dt>
6820 <dd>
6822 Sleeps for the given number of milliseconds. No events are
6823 processed during this time.
6824 </p>
6825 </dd>
6826 <dt class="hdlist1">
6827 <tt><strong>after</strong> <em>ms</em>|<strong>idle</strong> script ?script ...?'</tt>
6828 </dt>
6829 <dd>
6831 The scripts are concatenated and executed after the given
6832 number of milliseconds have elapsed. If <em>idle</em> is specified,
6833 the script will run the next time the event loop is processed
6834 with <a href="#cmd_2"><strong><tt>vwait</tt></strong></a> or <a href="#cmd_2"><strong><tt>update</tt></strong></a>. The script is only run once and
6835 then removed. Returns an event id.
6836 </p>
6837 </dd>
6838 <dt class="hdlist1">
6839 <tt><strong>after cancel</strong> <em>id|command</em></tt>
6840 </dt>
6841 <dd>
6843 Cancels an <a href="#cmd_2"><strong><tt>after</tt></strong></a> event with the given event id or matching
6844 command (script). Returns the number of milliseconds
6845 remaining until the event would have fired. Returns the
6846 empty string if no matching event is found.
6847 </p>
6848 </dd>
6849 <dt class="hdlist1">
6850 <tt><strong>after info</strong> <em>?id?</em></tt>
6851 </dt>
6852 <dd>
6854 If <tt><em>id</em></tt> is not given, returns a list of current <a href="#cmd_2"><strong><tt>after</tt></strong></a>
6855 events. If <tt><em>id</em></tt> is given, returns a list containing the
6856 associated script and either <em>timer</em> or <em>idle</em> to indicated
6857 the type of the event. An error occurs if <tt><em>id</em></tt> does not
6858 match an event.
6859 </p>
6860 </dd>
6861 <dt class="hdlist1">
6862 <tt><strong>vwait</strong> <em>variable</em></tt>
6863 </dt>
6864 <dd>
6866 A call to <a href="#cmd_2"><strong><tt>vwait</tt></strong></a> is enters the eventloop. <a href="#cmd_2"><strong><tt>vwait</tt></strong></a> processes
6867 events until the named (global) variable changes or all
6868 event handlers are removed. The variable need not exist
6869 beforehand. If there are no event handlers defined, <a href="#cmd_2"><strong><tt>vwait</tt></strong></a>
6870 returns immediately.
6871 </p>
6872 </dd>
6873 <dt class="hdlist1">
6874 <tt><strong>update ?idletasks?</strong></tt>
6875 </dt>
6876 <dd>
6878 A call to <a href="#cmd_2"><strong><tt>update</tt></strong></a> enters the eventloop to process expired events, but
6879 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
6880 not file events.
6881 Returns once handlers have been run for all expired events.
6882 </p>
6883 </dd>
6884 </dl></div>
6885 <div class="paragraph"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
6886 an attempt is made to call (the user-defined command) <tt>bgerror</tt> with the details of the error.
6887 If the <tt>bgerror</tt> commands does not exist, it is printed to stderr instead.</p></div>
6888 <div class="paragraph"><p>If a file event handler script generates an error, the handler is automatically removed
6889 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
6890 <div class="dlist"><dl>
6891 <dt class="hdlist1">
6892 <tt><strong>bgerror</strong> <em>error</em></tt>
6893 </dt>
6894 <dd>
6896 Called when an event handler script generates an error.
6897 </p>
6898 </dd>
6899 </dl></div>
6900 </div>
6901 <div class="sect2">
6902 <h3 id="_socket">socket</h3>
6903 <div class="paragraph"><p>Various socket types may be created.</p></div>
6904 <div class="dlist"><dl>
6905 <dt class="hdlist1">
6906 <tt><strong>socket unix</strong> <em>path</em></tt>
6907 </dt>
6908 <dd>
6910 A unix domain socket client.
6911 </p>
6912 </dd>
6913 <dt class="hdlist1">
6914 <tt><strong>socket unix.server</strong> <em>path</em></tt>
6915 </dt>
6916 <dd>
6918 A unix domain socket server.
6919 </p>
6920 </dd>
6921 <dt class="hdlist1">
6922 <tt><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></tt>
6923 </dt>
6924 <dd>
6926 A TCP socket client.
6927 </p>
6928 </dd>
6929 <dt class="hdlist1">
6930 <tt><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></tt>
6931 </dt>
6932 <dd>
6934 A TCP socket server (<tt><em>addr</em></tt> defaults to <tt>0.0.0.0</tt> for IPv4 or <tt>[::]</tt> for IPv6).
6935 </p>
6936 </dd>
6937 <dt class="hdlist1">
6938 <tt><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</tt>
6939 </dt>
6940 <dd>
6942 A UDP socket client. If the address is not specified,
6943 the client socket will be unbound and <em>sendto</em> must be used
6944 to indicated the destination.
6945 </p>
6946 </dd>
6947 <dt class="hdlist1">
6948 <tt><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></tt>
6949 </dt>
6950 <dd>
6952 A UDP socket server.
6953 </p>
6954 </dd>
6955 <dt class="hdlist1">
6956 <tt><strong>socket pipe</strong></tt>
6957 </dt>
6958 <dd>
6960 A pipe. Note that unlike all other socket types, this command returns
6961 a list of two channels: {read write}
6962 </p>
6963 </dd>
6964 </dl></div>
6965 <div class="paragraph"><p>This command creates a socket connected (client) or bound (server) to the given
6966 address.</p></div>
6967 <div class="paragraph"><p>The returned value is channel and may generally be used with the various file I/O
6968 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
6969 <div class="literalblock">
6970 <div class="content">
6971 <pre><tt>set f [socket stream www.google.com:80]
6972 aio.sockstream1
6973 $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
6974 $f gets
6975 HTTP/1.0 302 Found
6976 $f close</tt></pre>
6977 </div></div>
6978 <div class="paragraph"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
6979 the EVENTLOOP API.</p></div>
6980 <div class="literalblock">
6981 <div class="content">
6982 <pre><tt>set f [socket stream.server 80]
6983 $f readable {
6984 set client [$f accept]
6985 $client gets $buf
6987 $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
6988 $client close
6990 vwait done</tt></pre>
6991 </div></div>
6992 <div class="paragraph"><p>The address, <tt><em>addr</em></tt>, can be given in one of the following forms:</p></div>
6993 <div class="olist arabic"><ol class="arabic">
6994 <li>
6996 For IPv4 socket types, an IPv4 address such as 192.168.1.1
6997 </p>
6998 </li>
6999 <li>
7001 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
7002 </p>
7003 </li>
7004 <li>
7006 A hostname
7007 </p>
7008 </li>
7009 </ol></div>
7010 <div class="paragraph"><p>Note that on many systems, listening on an IPv6 address such as [::] will
7011 also accept requests via IPv4.</p></div>
7012 <div class="paragraph"><p>Where a hostname is specified, the <tt><em>first</em></tt> returned address is used
7013 which matches the socket type is used.</p></div>
7014 <div class="paragraph"><p>The special type <em>pipe</em> isn&#8217;t really a socket.</p></div>
7015 <div class="literalblock">
7016 <div class="content">
7017 <pre><tt>lassign [socket pipe] r w</tt></pre>
7018 </div></div>
7019 <div class="literalblock">
7020 <div class="content">
7021 <pre><tt># Must close $w after exec
7022 exec ps &gt;@$w &amp;
7023 $w close</tt></pre>
7024 </div></div>
7025 <div class="literalblock">
7026 <div class="content">
7027 <pre><tt>$r readable ...</tt></pre>
7028 </div></div>
7029 </div>
7030 <div class="sect2">
7031 <h3 id="_syslog">syslog</h3>
7032 <div class="paragraph"><p><tt><strong>syslog</strong> <em>?options? ?priority? message</em></tt></p></div>
7033 <div class="paragraph"><p>This command sends message to system syslog facility with given
7034 priority. Valid priorities are:</p></div>
7035 <div class="literalblock">
7036 <div class="content">
7037 <pre><tt>emerg, alert, crit, err, error, warning, notice, info, debug</tt></pre>
7038 </div></div>
7039 <div class="paragraph"><p>If a message is specified, but no priority is specified, then a
7040 priority of info is used.</p></div>
7041 <div class="paragraph"><p>By default, facility user is used and the value of global tcl variable
7042 argv0 is used as ident string. However, any of the following options
7043 may be specified before priority to control these parameters:</p></div>
7044 <div class="dlist"><dl>
7045 <dt class="hdlist1">
7046 <tt><strong>-facility</strong> <em>value</em></tt>
7047 </dt>
7048 <dd>
7050 Use specified facility instead of user. The following
7051 values for facility are recognized:
7052 </p>
7053 <div class="literalblock">
7054 <div class="content">
7055 <pre><tt>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
7056 uucp, local0-local7</tt></pre>
7057 </div></div>
7058 </dd>
7059 <dt class="hdlist1">
7060 <tt><strong>-ident</strong> <em>string</em></tt>
7061 </dt>
7062 <dd>
7064 Use given string instead of argv0 variable for ident string.
7065 </p>
7066 </dd>
7067 <dt class="hdlist1">
7068 <tt><strong>-options</strong> <em>integer</em></tt>
7069 </dt>
7070 <dd>
7072 Set syslog options such as <tt>LOG_CONS</tt>, <tt>LOG_NDELAY</tt>. You should
7073 use numeric values of those from your system syslog.h file,
7074 because I haven&#8217;t got time to implement yet another hash
7075 table.
7076 </p>
7077 </dd>
7078 </dl></div>
7079 </div>
7080 <div class="sect2">
7081 <h3 id="cmd_3">pack: pack, unpack</h3>
7082 <div class="paragraph"><p>The optional <em>pack</em> extension provides commands to encode and decode binary strings.</p></div>
7083 <div class="dlist"><dl>
7084 <dt class="hdlist1">
7085 <tt><strong>pack</strong> <em>varName value</em> <strong>-intle|-intbe|-str</strong> <em>bitwidth ?bitoffset?</em></tt>
7086 </dt>
7087 <dd>
7089 Packs the binary representation of <tt><em>value</em></tt> into the variable
7090 <tt><em>varName</em></tt>. The value is packed according to the given type
7091 (integer/string, big-endian/little-endian), width and bit offset.
7092 The variable is created if necessary (like <a href="#_append"><strong><tt>append</tt></strong></a>).
7093 Ihe variable is expanded if necessary.
7094 </p>
7095 </dd>
7096 <dt class="hdlist1">
7097 <tt><strong>unpack</strong> <em>binvalue</em> <strong>-intbe|-intle|-uintbe|-uintle|-str</strong> <em>bitpos bitwidth</em></tt>
7098 </dt>
7099 <dd>
7101 Unpacks bits from <tt><em>binvalue</em></tt> at bit position <tt><em>bitpos</em></tt> and with <tt><em>bitwidth</em></tt>.
7102 Interprets the value according to the type (integer/string, big-endian/little-endian
7103 and signed/unsigned) and returns it. For integer types, <tt><em>bitwidth</em></tt>
7104 may be up to the size of a Jim Tcl integer (typically 64 bits). For the string type,
7105 both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
7106 access outside the length of the value will return 0 for integer types or the empty string
7107 for the string type.
7108 </p>
7109 </dd>
7110 </dl></div>
7111 </div>
7112 <div class="sect2">
7113 <h3 id="_binary">binary</h3>
7114 <div class="paragraph"><p>The optional, pure-Tcl <em>binary</em> extension provides the Tcl-compatible <a href="#_binary"><strong><tt>binary</tt></strong></a> <tt>scan</tt> and <a href="#_binary"><strong><tt>binary</tt></strong></a> <tt>format</tt>
7115 commands based on the low-level <a href="#cmd_3"><strong><tt>pack</tt></strong></a> and <a href="#cmd_3"><strong><tt>unpack</tt></strong></a> commands.</p></div>
7116 <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>
7117 <div class="paragraph"><p>Note that packing and unpacking of floating point values is not supported.</p></div>
7118 </div>
7119 <div class="sect2">
7120 <h3 id="cmd_4">oo: class, super</h3>
7121 <div class="paragraph"><p>The optional, pure-Tcl <em>oo</em> extension provides object-oriented (OO) support for Jim Tcl.</p></div>
7122 <div class="paragraph"><p>See the online documentation (<a href="http://jim.berlios.de/documentation/oo/">http://jim.berlios.de/documentation/oo/</a>) for more details.</p></div>
7123 <div class="dlist"><dl>
7124 <dt class="hdlist1">
7125 <tt><strong>class</strong> <em>classname ?baseclasses? classvars</em></tt>
7126 </dt>
7127 <dd>
7129 Create a new class, <tt><em>classname</em></tt>, with the given dictionary
7130 (<tt><em>classvars</em></tt>) as class variables. These are the initial variables
7131 which all newly created objects of this class are initialised with.
7132 If a list of baseclasses is given, methods and instance variables
7133 are inherited.
7134 </p>
7135 </dd>
7136 <dt class="hdlist1">
7137 <tt><strong>super</strong> <em>method ?args ...?</em></tt>
7138 </dt>
7139 <dd>
7141 From within a method, invokes the given method on the base class.
7142 Note that this will only call the last baseclass given.
7143 </p>
7144 </dd>
7145 </dl></div>
7146 </div>
7147 <div class="sect2">
7148 <h3 id="_tree">tree</h3>
7149 <div class="paragraph"><p>The optional, pure-Tcl <em>tree</em> extension implements an OO, general purpose tree structure
7150 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>
7151 <div class="paragraph"><p>A tree is a collection of nodes, where each node (except the root node) has a single parent
7152 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.</p></div>
7153 <div class="dlist"><dl>
7154 <dt class="hdlist1">
7155 <tt><strong>tree</strong></tt>
7156 </dt>
7157 <dd>
7159 Creates and returns a new tree object with a single node named "root".
7160 All operations on the tree are invoked through this object.
7161 </p>
7162 </dd>
7163 <dt class="hdlist1">
7164 <tt>$tree <strong>destroy</strong></tt>
7165 </dt>
7166 <dd>
7168 Destroy the tree and all it&#8217;s nodes. (Note that the the tree will also
7169 be automatically garbage collected once it goes out of scope).
7170 </p>
7171 </dd>
7172 <dt class="hdlist1">
7173 <tt>$tree <strong>set</strong> <em>nodename key value</em></tt>
7174 </dt>
7175 <dd>
7177 Set the value for the given attribute key.
7178 </p>
7179 </dd>
7180 <dt class="hdlist1">
7181 <tt>$tree <strong>lappend</strong> <em>nodename key value ...</em></tt>
7182 </dt>
7183 <dd>
7185 Append to the (list) value(s) for the given attribute key, or set if not yet set.
7186 </p>
7187 </dd>
7188 <dt class="hdlist1">
7189 <tt>$tree <strong>keyexists</strong> <em>nodename key</em></tt>
7190 </dt>
7191 <dd>
7193 Returns 1 if the given attribute key exists.
7194 </p>
7195 </dd>
7196 <dt class="hdlist1">
7197 <tt>$tree <strong>get</strong> <em>nodename key</em></tt>
7198 </dt>
7199 <dd>
7201 Returns the value associated with the given attribute key.
7202 </p>
7203 </dd>
7204 <dt class="hdlist1">
7205 <tt>$tree <strong>getall</strong> <em>nodename</em></tt>
7206 </dt>
7207 <dd>
7209 Returns the entire attribute dictionary associated with the given key.
7210 </p>
7211 </dd>
7212 <dt class="hdlist1">
7213 <tt>$tree <strong>depth</strong> <em>nodename</em></tt>
7214 </dt>
7215 <dd>
7217 Returns the depth of the given node. The depth of "root" is 0.
7218 </p>
7219 </dd>
7220 <dt class="hdlist1">
7221 <tt>$tree <strong>parent</strong> <em>nodename</em></tt>
7222 </dt>
7223 <dd>
7225 Returns the node name of the parent node, or "" for the root node.
7226 </p>
7227 </dd>
7228 <dt class="hdlist1">
7229 <tt>$tree <strong>numchildren</strong> <em>nodename</em></tt>
7230 </dt>
7231 <dd>
7233 Returns the number of child nodes.
7234 </p>
7235 </dd>
7236 <dt class="hdlist1">
7237 <tt>$tree <strong>children</strong> <em>nodename</em></tt>
7238 </dt>
7239 <dd>
7241 Returns a list of the child nodes.
7242 </p>
7243 </dd>
7244 <dt class="hdlist1">
7245 <tt>$tree <strong>next</strong> <em>nodename</em></tt>
7246 </dt>
7247 <dd>
7249 Returns the next sibling node, or "" if none.
7250 </p>
7251 </dd>
7252 <dt class="hdlist1">
7253 <tt>$tree <strong>insert</strong> <em>nodename ?index?</em></tt>
7254 </dt>
7255 <dd>
7257 Add a new child node to the given node. The index is a list index
7258 such as <tt>3</tt> or <tt>end-2</tt>. The default index is <tt>end</tt>.
7259 Returns the name of the newly added node.
7260 </p>
7261 </dd>
7262 <dt class="hdlist1">
7263 <tt>$tree <strong>walk</strong> <em>nodename</em> <strong>dfs|bfs</strong> {<em>actionvar nodevar</em>} <em>script</em></tt>
7264 </dt>
7265 <dd>
7267 Walks the tree starting from the given node, either breadth first (<tt>bfs</tt>)
7268 depth first (<tt>dfs</tt>).
7269 The value <tt>"enter"</tt> or <tt>"exit"</tt> is stored in variable <tt><em>actionvar</em></tt>.
7270 The name of each node is stored in <tt><em>nodevar</em></tt>.
7271 The script is evaluated twice for each node, on entry and exit.
7272 </p>
7273 </dd>
7274 <dt class="hdlist1">
7275 <tt>$tree <strong>dump</strong></tt>
7276 </dt>
7277 <dd>
7279 Dumps the tree contents to stdout
7280 </p>
7281 </dd>
7282 </dl></div>
7283 </div>
7284 </div>
7285 </div>
7286 <div class="sect1">
7287 <h2 id="BuiltinVariables">BUILT-IN VARIABLES</h2>
7288 <div class="sectionbody">
7289 <div class="paragraph"><p>The following global variables are created automatically
7290 by the Tcl library.</p></div>
7291 <div class="dlist"><dl>
7292 <dt class="hdlist1">
7293 <tt><strong>env</strong></tt>
7294 </dt>
7295 <dd>
7297 This variable is set by Jim as an array
7298 whose elements are the environment variables for the process.
7299 Reading an element will return the value of the corresponding
7300 environment variable.
7301 This array is initialised at startup from the <a href="#_env"><strong><tt>env</tt></strong></a> command.
7302 It may be modified and will affect the environment passed to
7303 commands invoked with <a href="#_exec"><strong><tt>exec</tt></strong></a>.
7304 </p>
7305 </dd>
7306 <dt class="hdlist1">
7307 <tt><strong>platform_tcl</strong></tt>
7308 </dt>
7309 <dd>
7311 This variable is set by Jim as an array containing information
7312 about the platform on which Jim was built. Currently this includes
7313 <em>os</em> and <em>platform</em>.
7314 </p>
7315 </dd>
7316 <dt class="hdlist1">
7317 <tt><strong>auto_path</strong></tt>
7318 </dt>
7319 <dd>
7321 This variable contains a list of paths to search for packages.
7322 It defaults to a location based on where jim is installed
7323 (e.g. <tt>/usr/local/lib/jim</tt>), but may be changed by <tt>jimsh</tt>
7324 or the embedding application. Note that <tt>jimsh</tt> will consider
7325 the environment variable <tt>$JIMLIB</tt> to be a list of colon-separated
7326 list of paths to add to <tt><strong>auto_path</strong></tt>.
7327 </p>
7328 </dd>
7329 <dt class="hdlist1">
7330 <tt><strong>errorCode</strong></tt>
7331 </dt>
7332 <dd>
7334 This variable holds the value of the -errorcode return
7335 option set by the most recent error that occurred in this
7336 interpreter. This list value represents additional information
7337 about the error in a form that is easy to process with
7338 programs. The first element of the list identifies a general
7339 class of errors, and determines the format of the rest of
7340 the list. The following formats for -errorcode return options
7341 are used by the Tcl core; individual applications may define
7342 additional formats. Currently only <a href="#_exec"><strong><tt>exec</tt></strong></a> sets this variable.
7343 Otherwise it will be <tt>NONE</tt>.
7344 </p>
7345 </dd>
7346 </dl></div>
7347 <div class="paragraph"><p>The following global variables are set by jimsh.</p></div>
7348 <div class="dlist"><dl>
7349 <dt class="hdlist1">
7350 <tt><strong>tcl_interactive</strong></tt>
7351 </dt>
7352 <dd>
7354 This variable is set to 1 if jimsh is started in interactive mode
7355 or 0 otherwise.
7356 </p>
7357 </dd>
7358 <dt class="hdlist1">
7359 <tt><strong>tcl_platform</strong></tt>
7360 </dt>
7361 <dd>
7363 This variable is set by Jim as an array containing information
7364 about the platform upon which Jim was built. The following is an
7365 example of the contents of this array.
7366 </p>
7367 <div class="literalblock">
7368 <div class="content">
7369 <pre><tt>tcl_platform(byteOrder) = littleEndian
7370 tcl_platform(os) = Darwin
7371 tcl_platform(platform) = unix
7372 tcl_platform(pointerSize) = 8
7373 tcl_platform(threaded) = 0
7374 tcl_platform(wordSize) = 8
7375 tcl_platform(pathSeparator) = :</tt></pre>
7376 </div></div>
7377 </dd>
7378 <dt class="hdlist1">
7379 <tt><strong>argv0</strong></tt>
7380 </dt>
7381 <dd>
7383 If jimsh is invoked to run a script, this variable contains the name
7384 of the script.
7385 </p>
7386 </dd>
7387 <dt class="hdlist1">
7388 <tt><strong>argv</strong></tt>
7389 </dt>
7390 <dd>
7392 If jimsh is invoked to run a script, this variable contains a list
7393 of any arguments supplied to the script.
7394 </p>
7395 </dd>
7396 <dt class="hdlist1">
7397 <tt><strong>argc</strong></tt>
7398 </dt>
7399 <dd>
7401 If jimsh is invoked to run a script, this variable contains the number
7402 of arguments supplied to the script.
7403 </p>
7404 </dd>
7405 <dt class="hdlist1">
7406 <tt><strong>jim_argv0</strong></tt>
7407 </dt>
7408 <dd>
7410 The value of argv[0] when jimsh was invoked.
7411 </p>
7412 </dd>
7413 </dl></div>
7414 </div>
7415 </div>
7416 <div class="sect1">
7417 <h2 id="_changes_in_previous_releases">CHANGES IN PREVIOUS RELEASES</h2>
7418 <div class="sectionbody">
7419 <div class="sect2">
7420 <h3 id="_in_v0_63">In v0.63</h3>
7421 <div class="olist arabic"><ol class="arabic">
7422 <li>
7424 <a href="#_source"><strong><tt>source</tt></strong></a> now checks that a script is complete (.i.e. not missing a brace)
7425 </p>
7426 </li>
7427 <li>
7429 <em>info complete</em> now uses the real parser and so is 100% accurate
7430 </p>
7431 </li>
7432 <li>
7434 Better access to live stack frames with <em>info frame</em>, <a href="#_stacktrace"><strong><tt>stacktrace</tt></strong></a> and <a href="#_stackdump"><strong><tt>stackdump</tt></strong></a>
7435 </p>
7436 </li>
7437 <li>
7439 <a href="#_tailcall"><strong><tt>tailcall</tt></strong></a> no longer loses stack trace information
7440 </p>
7441 </li>
7442 <li>
7444 Add <a href="#_alias"><strong><tt>alias</tt></strong></a> and <a href="#_curry"><strong><tt>curry</tt></strong></a>
7445 </p>
7446 </li>
7447 <li>
7449 <a href="#_lambda"><strong><tt>lambda</tt></strong></a>, <a href="#_alias"><strong><tt>alias</tt></strong></a> and <a href="#_curry"><strong><tt>curry</tt></strong></a> are implemented via <a href="#_tailcall"><strong><tt>tailcall</tt></strong></a> for efficiency
7450 </p>
7451 </li>
7452 <li>
7454 <a href="#_local"><strong><tt>local</tt></strong></a> allows procedures to be deleted automatically at the end of the current procedure
7455 </p>
7456 </li>
7457 <li>
7459 udp sockets are now supported for both clients and servers.
7460 </p>
7461 </li>
7462 <li>
7464 vfork-based exec is now working correctly
7465 </p>
7466 </li>
7467 <li>
7469 Add <em>file tempfile</em>
7470 </p>
7471 </li>
7472 <li>
7474 Add <em>socket pipe</em>
7475 </p>
7476 </li>
7477 <li>
7479 Enhance <em>try &#8230; on &#8230; finally</em> to be more Tcl 8.6 compatible
7480 </p>
7481 </li>
7482 <li>
7484 It is now possible to <a href="#_return"><strong><tt>return</tt></strong></a> from within <a href="#_try"><strong><tt>try</tt></strong></a>
7485 </p>
7486 </li>
7487 <li>
7489 IPv6 support is now included
7490 </p>
7491 </li>
7492 <li>
7494 Add <em>string is</em>
7495 </p>
7496 </li>
7497 <li>
7499 Event handlers works better if an error occurs. eof handler has been removed.
7500 </p>
7501 </li>
7502 <li>
7504 <a href="#_exec"><strong><tt>exec</tt></strong></a> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
7505 </p>
7506 </li>
7507 <li>
7509 Command pipelines via open "|&#8230;" are now supported
7510 </p>
7511 </li>
7512 <li>
7514 <a href="#_pid"><strong><tt>pid</tt></strong></a> can now return pids of a command pipeline
7515 </p>
7516 </li>
7517 <li>
7519 Add <em>info references</em>
7520 </p>
7521 </li>
7522 <li>
7524 Add support for <em>after <tt>'ms</em></tt><em>, 'after idle</em>, <em>after info</em>, <a href="#cmd_2"><strong><tt>update</tt></strong></a>
7525 </p>
7526 </li>
7527 <li>
7529 <a href="#_exec"><strong><tt>exec</tt></strong></a> now sets environment based on $::env
7530 </p>
7531 </li>
7532 <li>
7534 Add <em>dict keys</em>
7535 </p>
7536 </li>
7537 <li>
7539 Add support for <em>lsort -index</em>
7540 </p>
7541 </li>
7542 </ol></div>
7543 </div>
7544 <div class="sect2">
7545 <h3 id="_in_v0_62">In v0.62</h3>
7546 <div class="olist arabic"><ol class="arabic">
7547 <li>
7549 Add support to <a href="#_exec"><strong><tt>exec</tt></strong></a> for <em>&gt;&amp;</em>, <em>&gt;&gt;&amp;</em>, <em>|&amp;</em>, <em>2&gt;@1</em>
7550 </p>
7551 </li>
7552 <li>
7554 Fix <a href="#_exec"><strong><tt>exec</tt></strong></a> error messages when special token (e.g. <em>&gt;</em>) is the last token
7555 </p>
7556 </li>
7557 <li>
7559 Fix <a href="#_subst"><strong><tt>subst</tt></strong></a> handling of backslash escapes.
7560 </p>
7561 </li>
7562 <li>
7564 Allow abbreviated options for <a href="#_subst"><strong><tt>subst</tt></strong></a>
7565 </p>
7566 </li>
7567 <li>
7569 Add support for <a href="#_return"><strong><tt>return</tt></strong></a>, <a href="#_break"><strong><tt>break</tt></strong></a>, <a href="#_continue"><strong><tt>continue</tt></strong></a> in subst
7570 </p>
7571 </li>
7572 <li>
7574 Many <a href="#_expr"><strong><tt>expr</tt></strong></a> bug fixes
7575 </p>
7576 </li>
7577 <li>
7579 Add support for functions in <a href="#_expr"><strong><tt>expr</tt></strong></a> (e.g. int(), abs()), and also <em>in</em>, <em>ni</em> list operations
7580 </p>
7581 </li>
7582 <li>
7584 The variable name argument to <a href="#_regsub"><strong><tt>regsub</tt></strong></a> is now optional
7585 </p>
7586 </li>
7587 <li>
7589 Add support for <em>unset -nocomplain</em>
7590 </p>
7591 </li>
7592 <li>
7594 Add support for list commands: <a href="#_lassign"><strong><tt>lassign</tt></strong></a>, <a href="#_lrepeat"><strong><tt>lrepeat</tt></strong></a>
7595 </p>
7596 </li>
7597 <li>
7599 Fully-functional <a href="#_lsearch"><strong><tt>lsearch</tt></strong></a> is now implemented
7600 </p>
7601 </li>
7602 <li>
7604 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
7605 </p>
7606 </li>
7607 <li>
7609 Allow <a href="#_catch"><strong><tt>catch</tt></strong></a> to determine what return codes are caught
7610 </p>
7611 </li>
7612 <li>
7614 Allow <a href="#_incr"><strong><tt>incr</tt></strong></a> to increment an unset variable by first setting to 0
7615 </p>
7616 </li>
7617 <li>
7619 Allow <em>args</em> and optional arguments to the left or required arguments in <a href="#_proc"><strong><tt>proc</tt></strong></a>
7620 </p>
7621 </li>
7622 <li>
7624 Add <em>file copy</em>
7625 </p>
7626 </li>
7627 <li>
7629 Add <em>try &#8230; finally</em> command
7630 </p>
7631 </li>
7632 </ol></div>
7633 </div>
7634 </div>
7635 </div>
7636 <div class="sect1">
7637 <h2 id="_licence">LICENCE</h2>
7638 <div class="sectionbody">
7639 <div class="literalblock">
7640 <div class="content">
7641 <pre><tt>Copyright 2005 Salvatore Sanfilippo &lt;antirez@invece.org&gt;
7642 Copyright 2005 Clemens Hintze &lt;c.hintze@gmx.net&gt;
7643 Copyright 2005 patthoyts - Pat Thoyts &lt;patthoyts@users.sf.net&gt;
7644 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
7645 Copyright 2008 Andrew Lunn &lt;andrew@lunn.ch&gt;
7646 Copyright 2008 Duane Ellis &lt;openocd@duaneellis.com&gt;
7647 Copyright 2008 Uwe Klein &lt;uklein@klein-messgeraete.de&gt;
7648 Copyright 2009 Steve Bennett &lt;steveb@workware.net.au&gt;</tt></pre>
7649 </div></div>
7650 <div class="literalblock">
7651 <div class="content">
7652 <pre><tt>Redistribution and use in source and binary forms, with or without
7653 modification, are permitted provided that the following conditions
7654 are met:
7655 1. Redistributions of source code must retain the above copyright
7656 notice, this list of conditions and the following disclaimer.
7657 2. Redistributions in binary form must reproduce the above
7658 copyright notice, this list of conditions and the following
7659 disclaimer in the documentation and/or other materials
7660 provided with the distribution.</tt></pre>
7661 </div></div>
7662 <div class="literalblock">
7663 <div class="content">
7664 <pre><tt>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
7665 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
7666 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
7667 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
7668 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
7669 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7670 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
7671 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
7672 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
7673 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
7674 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
7675 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</tt></pre>
7676 </div></div>
7677 <div class="literalblock">
7678 <div class="content">
7679 <pre><tt>The views and conclusions contained in the software and documentation
7680 are those of the authors and should not be interpreted as representing
7681 official policies, either expressed or implied, of the Jim Tcl Project.</tt></pre>
7682 </div></div>
7683 </div>
7684 </div>
7685 </div>
7686 <div id="footnotes"><hr /></div>
7687 <div id="footer">
7688 <div id="footer-text">
7689 Last updated 2011-10-06 07:52:30 EST
7690 </div>
7691 </div>
7692 </body>
7693 </html>