TIP #251: Enhance the 'list' Command


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

Abstract

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.

Rationale

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.

Specification

A new command list will be added with the following syntax:

list append

equivalent to lappend

list create

equivalent to list

list index

equivalent to lindex

list insert

equivalent to linsert

list join

equivalent to join

list length

equivalent to llength

list range

equivalent to lrange

list repeat

equivalent to lrepeat (see TIP #136)

list replace

equivalent to lreplace

list search

equivalent to lsearch

list set

equivalent to lset

list sort

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:

Incompatabilities

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...

Copyright

This document has been placed in the public domain.


Powered by Tcl[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