TIP 251: Enhance the 'list' Command

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2017 Conference, Houston/TX, US, Oct 16-20
Send your abstracts to tclconference@googlegroups.com
by Aug 21.
Author:         Brian Schmidt <contact@schmidtsrus.net>
Author:         Sérgio Loureiro <srgloureiro@gmail.com>
State:          Rejected
Type:           Project
Vote:           Done
Created:        28-Jun-2005
Post-History:   
Tcl-Version:    8.6

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 [208] and dict [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 [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.

History