From: Tobias G. <ga...@un...> - 2016-12-23 20:41:16
|
Hi Oleksiy, tcl arrays cannot be elements of dicts afaik, but You can rather try nested dicts. I'm not quite sure why You want/need the tcl array there. If You just want hierarchical structure, maybe nested dicts (or nested lists), or arrays of dicts could solve Your problem. To use nested dicts, please try changing Your code to the following % set Var [dict create \ Var1 [dict create SubVar1 {1 {1 2 3 4} 2 {1 2 3 4}}\ ] \ ] Var1 {SubVar1 {1 {1 2 3 4} 2 {1 2 3 4}}} % which is a nested dict (and can also be treated as nested list). If for some technical reason you absolutely need the contents of SubVar1 to reside in a tcl array at runtime, You could create an array variable at runtime and populate it (using array set) with SubVar1 Wile arrays cannot be key or value of a dict, a tcl array of dicts is possible, there is an example on http://wiki.tcl.tk/5042 about using dicts as values of a tcl array: array set U { tom { Name {Tom Brown} Sex M Age 19 Class {4 5} } mary { Name {Mary Brown} Sex F Age 16 Class {5} } sam { Name {Sam Spade} Sex M Age 19 Class {3 4} } } dict set U(tom) Sex F dict append U(sam) Name { Jr} dict lappend U(sam) Class 5 dict incr U(mary) Age dict set U(tom) Sax Y; # Creates a new key. dict set U(bill) Sax N; # Creates a new entry. regards, Tobi Am 23.12.2016 um 14:35 schrieb Oleksiy Bondarenko: > Dear all, > > Is there any way to assign array to a key of a dict? > > For example I would like to do something as below: > > set Var [dict create \ > Var1 [dict create SubVar1 [array set data {1 {1 2 3 4} 2 {1 2 3 4}}]\ > ] \ > ] > > but it outputs: > > Var1 {SubVar1 {} } > > :-( > > > Looking forward for suggestions > > > > ------------------------------------------------------------------------------ > Developer Access Program for Intel Xeon Phi Processors > Access to Intel Xeon Phi processor-based developer platforms. > With one year of Intel Parallel Studio XE. > Training and support from Colfax. > Order your platform today.http://sdm.link/intel > > > > _______________________________________________ > Tcl-win mailing list > Tc...@li... > https://lists.sourceforge.net/lists/listinfo/tcl-win > -- ----------------------- Tobias Gabele |