TIP: | 251 |
Title: | Enhance the 'list' Command |
Version: | $Revision: 1.14 $ |
Authors: |
Brian Schmidt <contact at schmidtsrus dot net> Sérgio Loureiro <srgloureiro at gmail dot com> |
State: | Rejected |
Type: | Project |
Tcl-Version: | 8.6 |
Vote: | Done |
Created: | Tuesday, 28 June 2005 |
This TIP proposes enhancing the existing list command to serve as a top-level command ensemble for all the related list commands that have proliferated over time, as well as making it easier to add future new list-based commands.
There are numerous top-level commands for lists already. This command would centralize them, making it easier for new developers of Tcl scripts to learn all the related list commands, to simplify and reduce the number of top-level commands to learn, etc. The enhanced list would be consistent with the new top-level commands chan TIP #208 and dict TIP #111, as well as the existing string and file commands.
A new command list will be added with the following syntax:
equivalent to lappend
equivalent to list
equivalent to lindex
equivalent to linsert
equivalent to join
equivalent to llength
equivalent to lrange
equivalent to lrepeat (see TIP #136)
equivalent to lreplace
equivalent to lsearch
equivalent to lset
equivalent to lsort
Each represents the existing command that is commented. The arguments to each would remain what the current command takes.
Note that split is not included as it operates on a string and returns a list, and concat is not included because it can operate on both normal strings and lists.
The old commands could then potentially be deprecated:
join
lappend
lindex
linsert
llength
lrange
lrepeat
lreplace
lsearch
lset
lsort
Incompatability with the existing list command could potentially be solved by allowing the list command without one of the defined options to be shorthand for the new list create command option. If the first argument to the new list command is not one of the new known options then list create is assumed by default.
For example,
list {my list}
would be equivalent to:
list set {my list} {}
It appears the only existing scripts that would break would be those that actually utilize the list command, has at least 2 arguments, and have as their first argument one of the new list command's ensemble options. This would likely result in a small minority of scripts being impacted. Only Tcl code with lists defined exactly as follows would break:
list append ?arg... list create ?arg... list index ?arg... list insert ?arg... list join ?arg... list length ?arg... list range ?arg... list repeat ?arg... list replace ?arg... list search ?arg... list set ?arg... list sort ?arg...
This document has been placed in the public domain.
[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]
TIP AutoGenerator - written by Donal K. Fellows