⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x-tclsumm2.html

📁 vxworks相关论文
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<pre class="CodeLeft"><b><a name="84074">lreplace $long 2 4 C D E</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84076"></b><tt class="output">a b C D E f g</tt><b></a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84078"> </a>Replace elements 2 through 4 of list <b class="symbol_lc">long</b>.</div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84080">set V "{c d e} f {h {i j} k}"</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84082"></a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84084"> </a>Define a list of lists.</div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84086">lindex $V 1</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84088"></b><tt class="output">f</tt><b></a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84090"> </a>Some elements of <b class="symbol_lc">V</b> are singletons.</div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84092">lindex $V 0</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84094"></b><tt class="output">c d e</tt><b></a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84096"> </a>Some elements of <b class="symbol_lc">V</b> are lists.</div></td><td width="10">&nbsp;</td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p> </p><dd><p class="Body"><a name="84103"> </a>The last examples use curly braces to delimit list items, yielding "lists of lists." This powerful technique, especially combined with recursive command substitution (see <a href="x-tclsumm2.html#84168"><i class="title">B.2.4&nbsp;Command Substitution</i></a>), can provide a little of the flavor of Lisp in Tcl programs.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84107">B.2.3  &nbsp;&nbsp;Associative Arrays</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84109"> </a>Tcl arrays are all associative arrays, using a parenthesized key to select or define a particular element of an array: <i class="textVariable">arrayName</i><b class="operator">(</b><i class="textVariable">keyString</i><b class="operator">)</b>. The <i class="textVariable">keyString</i> may in fact represent a number, giving the effect of ordinary indexed arrays. The following are some examples of expressions involving Tcl arrays: <p class="table"><h4 class="EntityTitle"><a name="84113"><font face="Helvetica, sans-serif" size="-1" class="sans">Table B-4:&nbsp;&nbsp;Using Tcl Arrays</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84119"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Tcl Expression</font></b></div></th><td width="10">&nbsp;</td><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84121"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Result</font></b></div></th><td width="10">&nbsp;</td><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84123"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Description</font></b></div></th><td width="10">&nbsp;</td></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84131">set taskId(tNetTask)</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84133"></b><tt class="output">0x4f300</tt><b></a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84135"> </a>Get element <b class="symbol_lc">tNetTask</b> of array <b class="symbol_lc">taskId</b>.</div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84137">set cpuFamily(5) m68k</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84139"></b><tt class="output">m68k</tt><b></a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84141"> </a>Define array <b class="symbol_lc">cpuFamily</b> and an  <br>element keyed <b class="symbol_lc">5</b>.</div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84143">set cpuFamily(10) sparc</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84145"></b><tt class="output">sparc</tt><b></a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><div class="CellBody"><a name="84147"> </a>Define element keyed <b class="symbol_lc">10</b> of array  <br><b class="symbol_lc">cpuFamily</b>.</div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84149">set cpuId 10</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84151"></b><tt class="output">10</tt><b></a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=2><div class="CellBody"><a name="84153"> </a>Define <b class="symbol_lc">cpuId</b>, and use it as a key to <b class="symbol_lc">cpuFamily</b>.</div></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84156">set cpuFamily($cpuId)</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84158"></b><tt class="output">sparc</tt><b></a></b></pre></td><td width="10">&nbsp;</td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84168">B.2.4  &nbsp;&nbsp;Command Substitution</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84170"> </a>In Tcl, you can capture the result of the command as text by enclosing the command in square brackets <b class="operator">[</b>  <b class="operator">]</b>. The Tcl interpreter substitutes the command result in the same process that is already running, which makes this an efficient operation.<p class="table"><h4 class="EntityTitle"><a name="84173"><font face="Helvetica, sans-serif" size="-1" class="sans">Table B-5:&nbsp;&nbsp;Examples of Tcl Command Substitution</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84177"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Tcl Expression</font></b></div></th><td width="10">&nbsp;</td><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84179"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Result</font></b></div></th><td width="10">&nbsp;</td></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84185">set m [lrange $long 2 4]</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84187"></b><tt class="output">c d e</tt><b></a></b></pre></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84189">set n [lindex $m 1]</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84191"></b><tt class="output">d</tt><b></a></b></pre></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84193">set o [lindex [lrange $long 2 4] 1]</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84195"></b><tt class="output">d</tt><b></a></b></pre></td><td width="10">&nbsp;</td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84197">set x [lindex [lindex $V 2] 1]</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84199"></b><tt class="output">i j</tt><b></a></b></pre></td><td width="10">&nbsp;</td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p><dd><p class="Body"><a name="84206"> </a>The last example selects from a list of lists (defined among the examples in <a href="x-tclsumm2.html#84025"><i class="title">B.2.2&nbsp;Lists in Tcl</i></a>). This and the previous example show that you can nest Tcl command substitutions readily.  The Tcl interpreter substitutes the most deeply nested command, then continues substituting recursively until it can evaluate the outermost command.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84209">B.2.5  &nbsp;&nbsp;Arithmetic</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84211"> </a>Tcl has an <b class="tclProc">expr</b> command to evaluate arithmetic expressions.  The <b class="tclProc">expr</b> command understands numbers in decimal and hexadecimal, as in the following examples:<p class="table"><h4 class="EntityTitle"><a name="84214"><font face="Helvetica, sans-serif" size="-1" class="sans">Table B-6:&nbsp;&nbsp;Arithmetic in Tcl</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84218"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Tcl Expression</font></b></div></th><td width="10">&nbsp;</td><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="84220"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Result</font></b></div></th><td width="10">&nbsp;</td></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><pre class="CodeLeft"><b><a name="84226">expr (2 &lt;&lt; 2) + 3</a></b></pre></td><td width="10">&nbsp;</td><td colspan=1 rowspan=1>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -