Code example from Playing with Keyed Lists on Mac OS X Tcl/Tk Aqua 8.4.2

;# Listing 7. Building a Tclx keyed list from the Tcl list

;# load the eXtended Tcl package
package require Tclx

set periodic_table_list {
  {87 {Francium {Fr} {223} {2-8-18-32-18-8-1} } }
  {88 {Radium {Ra} {226} {2-8-18-32-18-8-2} } }
  {104 {Rutherfordium {RF} {261} {2-8-18-32-32-10-2} } }
  {105 {Dubnium {Db} {262} {2-8-18-32-32-11-2} } }
  {106 {Seaborgium {Sg} {263} {2-8-18-32-32-12-2} } }
  {107 {Bohrium {Bh} {262} {2-8-18-32-32-13-2} } }
  {108 {Hassium {Hs} {265} {2-8-18-32-32-14-2} } }
  {109 {Meitnerium {Mt} {266} {2-8-18-32-32-15-2} } }
  {110 {Ununnilium {Uun} {269} {2-8-18-32-32-17-1} } }
  {111 {Unununium {Uuu} {272} {2-8-18-32-32-18-1} } }
  {112 {Ununbium {Uub} {277} {2-8-18-32-32-18-2} } }
  {113 {Ununtrium {Uut} {undiscovered} {undiscovered} } }
  {114 {Ununquadium {Uuq} {285} {2-8-18-32-32-18-4} } }
  {115 {Ununpentium {Uup} {undiscovered} {undiscovered} } }
  {116 {Ununhexium {Uuh} {289} {2-8-18-32-32-18-6} } }
  {117 {Ununseptium {Uus} {undiscovered} {undiscovered} } }
  {118 {Ununoctium {Uuo} {293} {2-8-18-32-32-18-8} } }
}

;# loop through each atom in the Tcl list
foreach atom $periodic_table_list {

    ;# retrieve the atomic number
    set atomic_number [lindex $atom 0]

    ;# extract the nested list, as demonstrated in Listing 3.
    ;# create a Tcl list from the nested list
    set atom_list [lindex $atom 1]

    ;# retrieve data from the Tcl list, atom_list
    set element_name [lindex $atom_list 0]
    set element_symbol [lindex $atom_list 1]
    set atomic_weight [lindex $atom_list 2]
    set electrons [lindex $atom_list 3]
    
    ;# display the data retrieved
    puts \
	"$element_name $element_symbol $atomic_weight $electrons"

    ;# build the keyed list
    keylset periodic_table_info $element_name.symbol \
	$element_symbol
    keylset periodic_table_info \
	$element_name.atomic_weight $atomic_weight
    keylset periodic_table_info $element_name.electrons \
	$electrons
}

;# display the Tclx keyed list
    keylset periodic_table_info $element_name.symbol \
	$element_symbol
    keylset periodic_table_info \
	$element_name.atomic_weight $atomic_weight
    keylset periodic_table_info $element_name.electrons \
	$electrons

;# display the Tclx keyed list
puts $periodic_table_info


;# displaying the values in the keyed list
;# using keylkeys and keylget
foreach atomic_elem [keylkeys periodic_table_info] {
    set atomic_symb [keylget periodic_table_info $atomic_elem.symbol]
    set atomic_weight [keylget periodic_table_info $atomic_elem.atomic_weight]
    set electrons [keylget periodic_table_info $atomic_elem.electrons]
    puts "$atomic_elem $atomic_symb $atomic_weight $electrons"
}