|
From: Oleksiy B. <ole...@gm...> - 2016-12-24 08:18:36
|
Thank you, Tobias and John for suggestions.
Actually, what I am seeking for is the way of representing
a multidimensional array of data for easy data store and retrieval.
Precisely speaking, I have the following data structure:
Parameters set 1: ObjF_1: Case1(mxn matrix), Case2(mxn matrix), .....
ObjF_2: Case2(mxn matrix), .....
ObjF_n: .....
Parameters set 2: ObjF1: .......
Parameters set 3: ......
The idea is to store "Parameters set 1" as a dict variable, where ObjF_n is
also dict with keys CaseN, and CaseN in turn is an array where every name
represent a row of the matrix.
So, probably the nested dicts fit my need.
Thank you again for the explanation on dict type variable.
2016-12-24 5:27 GMT+09:00 Tobias Gabele <ga...@un...>:
> 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
>
>
|