TIP #371: IMPROVEMENTS FOR THE DICT COMMAND ============================================= Version: $Revision: 1.3 $ Author: Thomas Perschak Trevor Davel State: Draft Type: Project Tcl-Version: 8.7 Vote: Pending Created: Thursday, 05 August 2010 URL: https://tip.tcl-lang.org371.html Post-History: ------------------------------------------------------------------------- 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} \ -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} \ {-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. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows