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

<TIP number='367'>
<header><title>A Command to Remove Elements from a List</title><author address="mailto:dkf@users.sf.net">Donal K. Fellows</author><status type='project' state='draft' tclversion="8.7" vote='prior'>$Revision: 1.1 $</status><history></history><created day='18' month='may' year='2010' /><keyword>Tcl delete item</keyword></header>
<abstract>This TIP proposes a command, <emph style="bold">lremove</emph>, that takes a list value and a collection of indices, and returns a list that is the input list with the elements at those indices removed.</abstract>
<body><section title="Rationale">
<para>Tcl has many operations for working with lists, such as <emph style="bold">list</emph> for building them, <emph style="bold">lappend</emph> for adding to them, <emph style="bold">linsert</emph> for insertion, <emph style="bold">lreplace</emph> for replacement of ranges, and <emph style="bold">lset</emph> for replacement of individual elements, but it has none that is designed to remove elements of a list. While the functionality can be simulated in the simple case with <emph style="bold">lreplace</emph>, this is rather more difficult when multiple indices are present. It is particularly challenging when using a mixture of indices that are defined relative to the start and the end of the list. Since the tools for doing the mapping of indices to list positions are easily available at the C level, I propose to add a command to Tcl to do the removal operation that takes advantage of the capabilities to do this all correctly.</para>
</section>
<section title="Proposed Change">
<para>This TIP proposes adding a command, <emph style="bold">lremove</emph>, with the following syntax:</para>
<quote><emph style="bold">lremove</emph> <emph style="italic">list</emph> ?<emph style="italic">index</emph>? ?<emph style="italic">index...</emph>?</quote>
<para>That is, the command takes one mandatory argument, <emph style="italic">list</emph>, and an arbitrary number of <emph style="italic">index</emph> arguments (including zero). The <emph style="italic">list</emph> argument must be a valid Tcl list, and each of the <emph style="italic">index</emph> arguments must be a valid Tcl index (see <tipref type="text" tip="176"/> for a description) where <emph style="bold">end</emph> will refer to the last element of <emph style="italic">list</emph>. Assuming syntactic validity, the result will be a list that is the same as <emph style="italic">list</emph> except for the removal of the elements at each given <emph style="italic">index</emph>. The result shall be as if all removals happen simultaneously and the order of the <emph style="italic">index</emph> arguments shall be unimportant; if an element is indicated twice (whether through syntactically identical indices or not) then it will be as if it was only indicated once.</para>
</section>
<section title="Examples">
<verbatim><vline encoding='base64'>JSBscmVtb3ZlIHthIGIgYyBkIGV9IDE=</vline><vline encoding='base64'>YSBjIGQgZQ==</vline><vline encoding='base64'>JSBscmVtb3ZlIHthIGIgYyBkIGV9IGVuZC0x</vline><vline encoding='base64'>YSBiIGMgZQ==</vline><vline encoding='base64'>JSBscmVtb3ZlIHthIGIgYyBkIGV9IDEgMw==</vline><vline encoding='base64'>YSBjIGU=</vline><vline encoding='base64'>JSBscmVtb3ZlIHthIGIgYyBkIGV9IDMgMQ==</vline><vline encoding='base64'>YSBjIGU=</vline><vline encoding='base64'>JSBscmVtb3ZlIHthIGIgYyBkIGV9IDIgMg==</vline><vline encoding='base64'>YSBiIGQgZQ==</vline><vline encoding='base64'>JSBscmVtb3ZlIHthIGIgYyBkIGV9IDMgZW5kLTE=</vline><vline encoding='base64'>YSBiIGMgZQ==</vline><vline encoding='base64'>JSBscmVtb3ZlIHthIGIgYyBkIGV9IDEgMyAxIDQgMA==</vline><vline encoding='base64'>Yw==</vline></verbatim>
</section>
<section title="Implementation">
<para><emph style="italic">Pending.</emph></para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
