TIP 577: Strict index values

Bounty program for improvements to Tcl and certain Tcl packages.
Author:         Jan Nijtmans <[email protected]>
State:          Draft
Type:           Project
Created:        8-June-2020
Keywords:       Tcl index
Tcl-Version:    8.7
Tcl-Branch:     strict-index


Various commands handle errors in "index" values differently. This TIP attempts to treat the different uses of index values (in both Tcl and Tk) to a more uniform way.


Some examples (Tk):

$ wish8.6
% listbox .l
% menu .m
% .l index 0
% .l index none
bad listbox index "none": must be active, anchor, end, @x,y, or a number
% .m index none
% .m index 0
% .m index foo
bad menu entry index "foo"

More examples (Tcl):

$ tclsh8.6
% lreplace {a b c} -1 -1 d
d a b c
% lreplace {a b c} -2 -2 d
d a b c
% set x {a b c}
a b c
% lset x 0 d
d b c
% lset x -1 d
list index out of range



For Tcl 8.7 this is almost 100% compatible, previous error-situations become valid now: Index value none can now be used in place of -1, just as the empty string "".

Since, starting with Tcl 9.0, some index forms are no longer valid, this is a potential incompatibility. Indices like -2 and end+2 can no longer be used in scripts: they will immediately result in an "index out of range" error, in stead of being silently ignore.


See the strict-index branch.


This document has been placed in the public domain.