2011-01-24 6 views

答えて

2

は、あなたが辞書を使いたい:http://www.tcl.tk/man/tcl8.5/TclCmd/dict.htm

辞書は、ファーストクラスの変数であり、ちょうど他の変数のように周り渡された(とリストに配置)することができます。

% set d1 [dict create a b c d] 
% set d2 [dict create e f g h i j] 
% set lst [list $d1 $d2] 
% set lst ;# ==> {a b c d} {e f g h i j} 
+0

また、 '8.5で辞書を返しGET'配列 –

2

仕事では、まだTcl 8.4を使用しています。私はdictがバックポートされていることを知っていますが、標準パッケージの一部ではありません。 8.4では、Tclxパッケージのキー付きリストを使用します。ここでの例です:

# Problem: I want to create a list of arrays 
# Solution: For 8.5, I can have list of dict, but for 8.4, use 
# keyedlist in place of dict. This script is written for 8.4 

package require Tclx 

# Create individual users and a list 
keylset user1 id 101 alias john; # {{id 101} {alias john}} 
keylset user2 id 102 alias ally; # {{id 102} {alias ally}} 
set users [list $user1 $user2] 

# Show the list 
foreach user $users { 
    puts "ID: [keylget user id]" 
    puts "Alias: [keylget user alias]" 
    puts "" 
} 

出力:

ID: 101 
Alias: john 

ID: 102 
Alias: ally 
関連する問題