: '''dict update''' ''dictionaryVariable'' ''key'' ''varName'' ?''key varName'' ''...''? ''body'' Execute the [Tcl] script in body with the value for each key (as found by reading the [dict]ionary value in dictionaryVariable) mapped to the variable varName. There may be multiple key/varName pairs. If a key does not have a mapping, that corresponds to an unset varName. When body terminates, any changes made to the varNames is reflected back to the dictionary within dictionaryVariable (unless dictionaryVariable itself becomes unreadable, when all updates are silently discarded), even if the result of body is an error or some other kind of exceptional exit. The result of dict update is (unless some kind of error occurs) the result of the evaluation of body. Each varName is mapped in the scope enclosing the dict update; it is recommended that this command only be used in a local scope (procedure, lambda term for apply, or method). Because of this, the variables set by dict update will continue to exist after the command finishes (unless explicitly unset). Note that the mapping of values to variables does not use [trace]s; changes to the dictionaryVariable's contents only happen when body terminates. --- <> Example [HaO] 2012-07-20: As I did not understand what it does, I try an example: Dict update is like a dict set with a proc: ====== % set d {key1 value1 key2 value2} key1 value1 key2 value2 % dict update d key1 varKey1 { append varKey1 new } value1new % set d key1 value1new key2 value2 ====== There might be multiple keys updated simultaneously: ====== % set d {key1 value1 key2 value2} key1 value1 key2 value2 % dict update d key1 varKey1 key2 varKey2 { append varKey1 new append varKey2 new } value2new % set d key1 value1new key2 value2new ====== Keys might be checked for existence and set if they don't exist: ====== % set d {key1 value1 key2 value2} key1 value1 key2 value2 % dict update d key3 varKey3 { if {![info exists varKey3]} { set varKey3 new } } new % set d key1 value1 key2 value2 key3 new ====== Keys might be deleted: ====== % set d {key1 value1 key2 value2} key1 value1 key2 value2 % dict update d key1 varKey1 { unset varKey1 } % set d key2 value2 ====== Application idea by [George Petasis] on clt: lappend for sublist: ====== % set d {key1 {subkey11 value11}} key1 {subkey11 value11} % dict update d key1 varKey1 { dict lappend varKey1 subkey11 new } subkey11 {value11 new} % set d key1 {subkey11 {value11 new}} ====== Try to put this in a proc: ====== proc lasubdict {dictname key subkey value} { upvar 1 $dictname dictvar dict update dictvar $key subdict [list dict lappend subdict $subkey $value] } % set d {key1 {subkey11 value11}} % lasubdict d key1 subkey11 new subkey11 {value11 new} % set d key1 {subkey11 {value11 new}} ====== Maybe, this is implemented in a more efficient manner with [dict with] or just: ====== proc lasubdict {dictname key subkey value} { upvar 1 $dictname dictvar dict set dictvar $key $subkey [lappend [dict get $dictvar $key $subkey] $value] } ====== <> <> Command | Data Structure