TIP #371: Improvements for the dict command
_____________________________________________________________________________
TIP:	371
Title:	Improvements for the dict command
Version:	$Revision: 1.3 $
Authors:	Thomas Perschak <tombert@gmx.at>
	Trevor Davel <twylite@crypt.co.za>
State:	Draft
Type:	Project
Tcl-Version:	8.7
Vote:	Pending
Created:	Thu Aug 05 00:00:00 UTC 2010
Abstract
The dict command is limited by allowing manipulation of only the first level of key elements. Not only should the dict get accept a nested key list, but also the other commands like dict replace.
Specification And Example
The following line:
dict get -range -values a b c -base M -name myname \par        -range -base
Results in:
M
But how to change the base? I suggest the following dict syntax extension:
dict replace -range -values a b c -base M -name myname \par        -range -base k
Results in:
-range -values a b c -base k -name myname
Allowing a nested key list would not break any previous code, but substantially improve the dict command.
Rationale
The dict command is the basis for handling database like structures. By allowing nested keys this would give more freedom in organizing these structures like the example above.
_____________________________________________________________________________
Comments
Twylite 2010/08/17: The specification states that "Allowing a nested key list would not break any previous code". This is not correct, for example:
dict replace "Jane Smith" "11 Foo Road" "John Doe" "Address unknown" Jane Smith new_address
-> Jane Smith new_address John Doe Address unknown
Existing code that uses dict replace in conjunction with keys that are valid lists of 2 or more elements would break.
Also, drawing from experience, the nested key approach is a source of subtle bugs. It is natural to write code such as:
dict replace $dict $key $value
but that contains a bug that is often missed during testing. The correct approach would be:
dict replace $dict [list $key] $value
_____________________________________________________________________________
Copyright
This document has been placed in the public domain.
_____________________________________________________________________________
Colophon
TIP AutoGenerator - written by Donal K. Fellows