Destructuring assignment is a mechanism for extracting data from data structures.
Implementations edit
dassign
dbohdan 2015-10-25: Here is a simple implementation of destructuring assignment for nested
dictionaries.
Code
# Destructuring assignment for dictionaries.
# Version 0.0.1
proc dassign {to from {level 1}} {
foreach {key value} $to {
# $value is a variable name.
if {[string match $* $value]} {
uplevel $level [list \
set [string range $value 1 end] [dict get $from $key]]
} else {
dassign $value [dict get $from $key] [expr {$level + 1}]
}
}
}
Sample use
% dassign {foo {bar $five baz $seven}} {foo {bar 5 baz 7}}
% puts $five\ $seven
5 7
See also edit