Version 5 of dict tips and tricks

Updated 2007-02-12 01:05:44

dicts are just like name value pair lists

Just like the results of [array get], so you can [array set X [dict filter]]] or (conversely) [dict get [array get X] key].

So, you can define a proc fred {args} and then immediately treat $arg as a dict, if (and only if) the values passed have the form of a dict - no special processing is required (rather, the shimmering occurs in the background.

This is useful for passing named arguments to a proc, sort of like the various options packages: [dict get $args -option] will fetch any value passed as -option value.

[dict with] alters the enclosing scope

So if you have a dict X, [dict with X {}] will construct and initialize variables with the same names and values as X's contents.

This is useful for passing around collections of named values.

You could use it to populate the variables in a namespace (for, say, a collection of defaults) [namespace eval dict with $dv {}]