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

Title:Empty index lists for [lindex] and [lset]
Version:$Revision: 1.9 $
Authors: Kevin Kenny <kennykb at acm dot org>
Don Porter <dgp at users dot sourceforge dot net>
Created:Wednesday, 18 July 2001
Discussions To:news:comp.lang.tcl
Discussions To:mailto:[email protected]
Keywords:lindex, lset, multiple arguments, sublists


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.


In the discussion of TIP #33 ([1]), 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 TIP #22 and TIP #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.


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

      lindex list


      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 TIP #33 shall be amended so that the forms:

      lset var value


      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.


Since this proposed change introduces syntax that is expressly forbidden in TIP #22 and TIP #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

TIP #22, TIP #33.


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