<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu May 17 04:22:20 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='331'>
<header><title>Allow [lset] to Extend Lists</title><author address="mailto:kennykb@acm.org">Kevin B. Kenny</author><status type='project' state='final' tclversion="8.6" vote='after'>$Revision: 1.5 $</status><history></history><created day='22' month='sep' year='2008' /></header>
<abstract>This TIP proposes to modify the <emph style="bold">lset</emph> command to allow it to extend lists.</abstract>
<body><section title="Proposal">
<para>The <emph style="bold">lset</emph> command shall be modified to allow the index <emph style="italic">end+1</emph> (or any equivalent index designating the element one beyond the last element of the list). For the simple usage:</para>
<verbatim><vline encoding='base64'>ICAgIGxzZXQgbGlzdCBlbmQrMSBmb28=</vline></verbatim>
<para>the effect is the same as if the script had evaluated the command:</para>
<verbatim><vline encoding='base64'>ICAgIGxhcHBlbmQgbGlzdCBmb28=</vline></verbatim>
<para>For the usage:</para>
<verbatim><vline encoding='base64'>ICAgIGxzZXQgbGlzdCAkbiBlbmQrMSBmb28=</vline></verbatim>
<para>the effect is much the same as if the script had evaluated:</para>
<verbatim><vline encoding='base64'>ICAgIHNldCB0ZW1wIFtsaW5kZXggJGxpc3QgJG5d</vline><vline encoding='base64'>ICAgIGxhcHBlbmQgdGVtcCBmb28=</vline><vline encoding='base64'>ICAgIGxzZXQgbGlzdCAkbiAkdGVtcA==</vline></verbatim>
<para>(except, of course that no <emph style="italic">temp</emph> variable is created)</para>
<para>The usage:</para>
<verbatim><vline encoding='base64'>ICAgIGxzZXQgbGlzdCBlbmQrMSAwIGZvbw==</vline></verbatim>
<para>or, equivalently,</para>
<verbatim><vline encoding='base64'>ICAgIGxzZXQgbGlzdCBlbmQrMSBlbmQrMSBmb28=</vline></verbatim>
<para>is equivalent to</para>
<verbatim><vline encoding='base64'>ICAgIGxhcHBlbmQgbGlzdCBbbGlzdCBmb29d</vline></verbatim>
</section>
<section title="Rationale">
<para>Clearly, there are equivalent constructs to all of these usages. Nevertheless, it is convenient not to have to worry about whether a given index is in bounds, particularly when iterating through a vector or matrix. With the proposed change, many of the standard algorithms in linear algebra will just work, without either having to preinitialize a list to a given size or to have a test to determine whether to use <emph style="bold">lappend</emph> or <emph style="bold">lset</emph> to store a given element.</para>
</section>
<section title="Alternatives">
<para>Explicitly out of scope is the treatment of indices greater than or equal to <emph style="italic">end+2</emph>. Setting non-contiguous elements would raise false expectations of sparse lists, <emph style="bold">NULL</emph> elements, and so on.</para>
</section>
<section title="Copyright">
<para>Copyright © 2008 by Kevin B. Kenny.</para>
<para>This document may be distributed subject to the terms and conditions set forth in the Open Publication License, version 1.0 [<url ref="http://www.opencontent.org/openpub/"/>].</para>
</section>
</body></TIP>

