This is not necessarily the current version of this TIP.
| TIP: | 176 |
| Title: | Add String Index Values |
| Version: | $Revision: 1.1 $ |
| Author: | Damon Courtney <damon at unreality dot com> |
| State: | Draft |
| Type: | Project |
| Tcl-Version: | 8.5 |
| Vote: | Pending |
| Created: | Tuesday, 16 March 2004 |
This TIP proposes to add small functionality to the standard index (end-1) values acceptable by most Tcl commands.
Most of Tcl's commands that accept an integer index of some kind also accept a string index in the format of end-N. This is an extremely useful feature which I hope to extend just slightly by allowing simple addition to the standard index forms to be done during index processing. The change is mostly just syntactic sugar, but it extends a functionality that is already there and does not change any other syntax.
Under this TIP, the following would all be valid indexes (N and M are integers):
Standard numeric indexing style.
Standard end-relative indexing style.
New offset-to-known-point style.
New past-end style.
This allows for shorthand list and string operations like so:
set x [lsearch $list $elem] set new [lrange $list $x-1 $x+1] set x [string first $string "foo"] set new [string range $string $x $x+5]
And so on...
The code itself is just some simple changes to TclGetIntForIndex() in generic/tclUtil.c. Because the core commands in Tcl and Tk alredy use this private function for index values, the commands which already accept the standard end-N index will now accept the new indexes.
This document has been placed in the public domain.
This is not necessarily the current version of this TIP.