dict lappend2

jbr - 2013-07-16

This idea first appeared on c.l.t[L1 ] a while back.

Here is a slightly different implementation that silently creates deeply nested dicts without complaint.

 proc ::tcl::dict::lappend2 {dict args} {
    upvar 1 $dict d

    if { ![dict exists $d {*}[lrange $args 0 end-1]] } {
        dict set d {*}[lrange $args 0 end-1] [list [lindex $args end]]
    } else {
        ::set list [dict get $d {*}[lrange $args 0 end-1]]
        ::lappend list [lindex $args end]
        dict set d {*}[lrange $args 0 end-1] $list
 namespace ensemble configure dict -map [dict merge [namespace ensemble configure dict -map] {lappend2 ::tcl::dict::lappend2}]

This inspired the ensemble implementation of string chunk

See Also: