<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://tcl.activestate.com/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu Feb 09 08:58:03 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='45'>
<header><title>Empty index lists for [lindex] and [lset]</title><author address="mailto:kennykb@acm.org">Kevin Kenny</author><author address="mailto:dgp@users.sourceforge.net">Don Porter</author><status type='project' state='final' tclversion="8.4b1" vote='after'>$Revision: 1.9 $</status><history></history><created day='18' month='jul' year='2001' /><discussions url='news:comp.lang.tcl'/><discussions url='mailto:kennykb@acm.org'/><keyword>lindex lset {multiple arguments} sublists</keyword></header>
<abstract>TIP&apos;s #22 and #33 contain an oversight in specifying the behavior of the multi-argument forms of <emph style="italic">lset</emph> and <emph style="italic">lindex</emph> when an empty index list is specified. The intended behavior is that an empty list of indices designates the entire list.</abstract>
<body><section title="Rationale">
<para>In the discussion of <tipref type="text" tip="33"/> ([<url ref="http://www.geocrawler.com/archives/3/7375/2001/5/0/5784409/"/>]), Jim Ingham pointed out that the list of indices presented to the multi-argument forms of <emph style="italic">lindex</emph> and <emph style="italic">lset</emph> is analogous to a database cursor. This cursor is conceptually navigating a tree structure; the command:</para>
<verbatim><vline encoding='base64'>ICBsaW5kZXggJGxpc3QgezEgMiAzfQ==</vline></verbatim>
<para>means, &quot;extract the sublist at index 1 in $list, the sublist at index 2 in that list, and the element at index 3 in that list&quot;.</para>
<para>When implementing this functionality, the author of this TIP realized that <tipref type="text" tip="22"/> and <tipref type="text" tip="33"/> provide no way to address the root of the tree -- the entire list being manipulated. An empty list of indices is a convenient means of specifying the root.</para>
</section>
<section title="Specification">
<enumerate><item.e index='1'><para>The specification of <emph style="italic">lindex</emph> in <tipref type="text" tip="22"/> shall be amended so that the forms:</para><verbatim><vline encoding='base64'>ICBsaW5kZXggbGlzdA==</vline></verbatim><para>and</para><verbatim><vline encoding='base64'>ICBsaW5kZXggbGlzdCB7fQ==</vline></verbatim><para>will return the value of the entire list. The <emph style="italic">list</emph> parameter is not required to be a well-formed Tcl list when this form is used.</para></item.e><item.e index='2'><para>The specification of <emph style="italic">lset</emph> in <tipref type="text" tip="33"/> shall be amended so that the forms:</para><verbatim><vline encoding='base64'>ICBsc2V0IHZhciB2YWx1ZQ==</vline></verbatim><para>and</para><verbatim><vline encoding='base64'>ICBsc2V0IHZhciB7fSB2YWx1ZQ==</vline></verbatim><para>will simply store the supplied value into the variable named <emph style="italic">var</emph>. Neither the old nor the new value of <emph style="italic">var</emph> is required to be a well-formed Tcl list when this form is used. The return value of the operation, as with all other uses of <emph style="italic">lset</emph>, is the new value of <emph style="italic">var</emph>.</para></item.e></enumerate>
</section>
<section title="Reference implementation">
<para>Work progresses on implementing this functionality; the currently committed version is on SourceForge in the branch labeled, <emph style="italic">kennykb-tcl-22-33</emph>.</para>
</section>
<section title="Discussion">
<para>Since this proposed change introduces syntax that is expressly forbidden in <tipref type="text" tip="22"/> and <tipref type="text" tip="33"/>, it does not have any impact on backward compatibility. For the same reason, the author thought it unwise to proceed with its implementation without a vote of the TCT.</para>
</section>
<section title="See Also">
<para><tipref type="text" tip="22"/>, <tipref type="text" tip="33"/>.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

