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

<TIP number='295'>
<header><title>Enhance Arguments to lrange</title><author address="mailto:avl@logic.at">Andreas Leitgeb</author><status type='project' state='draft' tclversion="8.7" vote='prior'>$Revision: 1.7 $</status><history></history><created day='6' month='nov' year='2006' /><keyword>Tcl lrange</keyword></header>
<abstract>This TIP proposes an enhancement to <emph style="bold">lrange</emph> and <emph style="bold">string range</emph> that lets them take more than one start-end index pair.</abstract>
<body><section title="Rationale">
<para>Sometimes you need to extract a non-continuous selection of elements from some list and build a new list from them. This requires the use of multiple calls to <emph style="bold">lrange</emph> and a surrounding <emph style="bold">concat</emph> to build the final list. However, since the following fails with a syntax error:</para>
<verbatim><vline encoding='base64'>ICAgIGxyYW5nZSB7YSBiIGMgZCBlIGZ9ICAxIDMgIDUgNQ==</vline></verbatim>
<para>It would seem a reasonable extension for such a usage of <emph style="bold">lrange</emph> to return &quot;b c d f&quot;. This would also make following pattern of usage feasible:</para>
<verbatim><vline encoding='base64'>IGxhc3NpZ24gW2xyYW5nZSAkc29tZUxpc3QgMCAyICAxMCAxMl0gIHZhcjAgdmFyMSB2YXIyIHZhcjEwIHZhcjExIHZhcjEy</vline></verbatim>
<para>The indices should <emph style="italic">not</emph> be required to be in ascending order. This is meant such that the ranges may be overlapping at will. E.g.:</para>
<verbatim><vline encoding='base64'>IFtscmFuZ2UgJGxpc3QgMCBlbmQgMCBlbmRdID09IFtscmVwZWF0IDIgeyp9JGxpc3Rd</vline></verbatim>
<para>This TIP does NOT change the way each range is interpreted. Reversing lists is not in the scope of this TIP.</para>
</section>
<section title="Proposed Change">
<para>Change the implementation of <emph style="bold">lrange</emph> to accept any odd number of arguments, with semantics (upon supply of a correct number of arguments) equivalent to:</para>
<verbatim><vline encoding='base64'>IHByb2MgbHJhbmdlLW5ldyB7bGlzdCBhcmdzfSB7</vline><vline encoding='base64'>ICAgIHNldCByZXN1bHQgW2xpc3Rd</vline><vline encoding='base64'>ICAgIGZvcmVhY2gge3N0YXJ0IGVuZH0gJGFyZ3Mgew==</vline><vline encoding='base64'>ICAgICAgIGxhcHBlbmQgcmVzdWx0IHsqfVtscmFuZ2UgJGxpc3QgJHN0YXJ0ICRlbmRd</vline><vline encoding='base64'>ICAgIH0=</vline><vline encoding='base64'>ICAgIHJldHVybiAkcmVzdWx0</vline><vline encoding='base64'>IH0=</vline></verbatim>
</section>
<section title="Draft Implementation">
<para>Just the above mentioned procedure, at the moment.</para>
</section>
<section title="Further Thoughts">

</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
