Monday, September 29, 2025

Creating Tagged Lists From Separate Key - Value Lists

Various Tcl and Gnocl operations will return a list of values. At times, however, it is useful to preserve the lists of values as a tagged list; in other words, as a dict entry. Assuming that the returned value names are keys, the Tcl format command command can be used to complete the operation. For example:

 

set main [gnocl::window -setSize 0.25]

puts [format "x %s y %s width %s height %s" {*}[$main geometry]] 

 

gives:

x 0 y 0 width 480 height 270

Alternatively, a proc can be written using the foreach command:

 

proc tagList {tagnames values} {
    foreach tag $tagnames val $values {
        lappend buff $tag $val
    
    return $buff
}