TIP 45: Empty index lists for [lindex] and [lset]

Login
Author:         Kevin Kenny <[email protected]>
Author:         Don Porter <[email protected]>
State:          Final
Type:           Project
Vote:           Done
Created:        18-Jul-2001
Post-History:   
Discussions-To: news:comp.lang.tcl,mailto:[email protected]
Keywords:       lindex,lset,multiple arguments,sublists
Tcl-Version:    8.4b1

Abstract

TIP's #22 and #33 contain an oversight in specifying the behavior of the multi-argument forms of lset and lindex when an empty index list is specified. The intended behavior is that an empty list of indices designates the entire list.

Rationale

In the discussion of [33] (http://www.geocrawler.com/archives/3/7375/2001/5/0/5784409/ ), Jim Ingham pointed out that the list of indices presented to the multi-argument forms of lindex and lset is analogous to a database cursor. This cursor is conceptually navigating a tree structure; the command:

  lindex $list {1 2 3}

means, "extract the sublist at index 1 in $list, the sublist at index 2 in that list, and the element at index 3 in that list".

When implementing this functionality, the author of this TIP realized that [22] and [33] provide no way to address the root of the tree -- the entire list being manipulated. An empty list of indices is a convenient means of specifying the root.

Specification

  1. The specification of lindex in [22] shall be amended so that the forms:

      lindex list
    

    and

      lindex list {}
    

    will return the value of the entire list. The list parameter is not required to be a well-formed Tcl list when this form is used.

  2. The specification of lset in [33] shall be amended so that the forms:

      lset var value
    

    and

      lset var {} value
    

    will simply store the supplied value into the variable named var. Neither the old nor the new value of var is required to be a well-formed Tcl list when this form is used. The return value of the operation, as with all other uses of lset, is the new value of var.

Reference implementation

Work progresses on implementing this functionality; the currently committed version is on SourceForge in the branch labeled, kennykb-tcl-22-33.

Discussion

Since this proposed change introduces syntax that is expressly forbidden in [22] and [33], it does not have any impact on backward compatibility. For the same reason, the author thought it unwise to proceed with its implementation without a vote of the TCT.

See Also

[22], [33].

Copyright

This document has been placed in the public domain.