For Programmers: Free Programming Magazines  


Home > Archive > Tcl > January 2008 > array set - list - problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author array set - list - problem
eiji

2008-01-23, 7:25 pm

Hi folks,

I was just wondering, why this is not possible:

array set myarray {
x [list x1 x2 x3]
y [list y1 y2 y3]
}

To make it work, I alway have to:

array set myarray {}
set myarray(x) [list x1 x2 x3]
set myarray(y) [list y1 y2 y3]

To me, this feels kind of "un-tcl-like".

Regards,
eiji
Bryan Oakley

2008-01-23, 7:25 pm

eiji wrote:
> Hi folks,
>
> I was just wondering, why this is not possible:
>
> array set myarray {
> x [list x1 x2 x3]
> y [list y1 y2 y3]
> }


What do we know about curly braces and the effect they have on
substitution? Answer that question and the answer to your question will
be self-evident (I hope!)



--
Bryan Oakley
http://www.tclscripting.com
George Peter Staplin

2008-01-23, 7:25 pm

eiji wrote:
> Hi folks,
>
> I was just wondering, why this is not possible:
>
> array set myarray {
> x [list x1 x2 x3]
> y [list y1 y2 y3]
> }
>
> To make it work, I alway have to:
>
> array set myarray {}
> set myarray(x) [list x1 x2 x3]
> set myarray(y) [list y1 y2 y3]
>
> To me, this feels kind of "un-tcl-like".
>
> Regards,
> eiji


$ tclsh8.5
% array set ar [list x [list x1 x2 x3] y [list y1 y2 y3]]
% parray ar
ar(x) = x1 x2 x3
ar(y) = y1 y2 y3
%

Magic! ;-)

George
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com