Manisha Kuhar
Manisha Kuhar

Reputation: 9

How to create an array of lists in Tcl?

I need to store number of lists in array.

I have a command which returns a list:Suppose it is CommandReturninglist

set aa [ CommandReturninglist{0} ]

Clarification: CommandReturninglist is taking input argument 0.

I need to use it ten times and store the lists returned in array.

for {set i 0 } { $i < 10 } { incr i } {
set d($i) [ CommandReturninglist{$i} ]
puts $d($i)
}

I cant store the list as shown in above case. Here $i in CommandReturninglist{$i} is the needed argument.

Please suggest some way.

Upvotes: 0

Views: 510

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137787

You're very close. You just need to put a space between the command name and its argument, and make sure not to put the argument in braces if you want it substituted.

for {set i 0 } { $i < 10 } { incr i } {
    set d($i) [CommandReturninglist $i]
    puts $d($i)
}

It's also possible for commands to (effectively) take variables by reference that they can work with (a way to move whole arrays across procedure boundaries) or to pass around lists of lists (or dictionaries of lists, or…) and use those.

Upvotes: 1

Related Questions