Allow [lset] to Extend ListsKevin B. Kenny$Revision: 1.5 $
This TIP proposes to modify the lset command to allow it to extend lists.
The lset command shall be modified to allow the index end+1 (or any equivalent index designating the element one beyond the last element of the list). For the simple usage:
ICAgIGxzZXQgbGlzdCBlbmQrMSBmb28=
the effect is the same as if the script had evaluated the command:
ICAgIGxhcHBlbmQgbGlzdCBmb28=
For the usage:
ICAgIGxzZXQgbGlzdCAkbiBlbmQrMSBmb28=
the effect is much the same as if the script had evaluated:
ICAgIHNldCB0ZW1wIFtsaW5kZXggJGxpc3QgJG5dICAgIGxhcHBlbmQgdGVtcCBmb28=ICAgIGxzZXQgbGlzdCAkbiAkdGVtcA==
(except, of course that no temp variable is created)
The usage:
ICAgIGxzZXQgbGlzdCBlbmQrMSAwIGZvbw==
or, equivalently,
ICAgIGxzZXQgbGlzdCBlbmQrMSBlbmQrMSBmb28=
is equivalent to
ICAgIGxhcHBlbmQgbGlzdCBbbGlzdCBmb29d
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 lappend or lset to store a given element.
Explicitly out of scope is the treatment of indices greater than or equal to end+2. Setting non-contiguous elements would raise false expectations of sparse lists, NULL elements, and so on.
Copyright © 2008 by Kevin B. Kenny.
This document may be distributed subject to the terms and conditions set forth in the Open Publication License, version 1.0 [].