One of the subcommands of dict. Moves entries from a dictionary into variables, evaluates a script, and moves the (possibly updated) values back from the variables to the dictionary.
set info [dict create forenames "Joe" surname "Schmoe" street "147 Short Street" city "Springfield" phone "555-1234"] dict with info { puts " Name: $forenames $surname" puts " Address: $street, $city" puts " Telephone: $phone" }
The idea comes in part from the with statement of Pascal, which temporarily places the fields of a record into the local scope. A difference is that in Pascal the record fields merely shadow similarly-named variables, whereas dict with really puts the values into ordinary variables. Because of this, one should only use dict with to unpack dictionaries which have a known set of entries (like a Pascal record or C struct).
An alternative technique is to unpack dictionaries into arrays using array set (and repack them with array get). This is safe for dictionaries which may gain new elements.
[ Category Command ]