0

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.

1
  • I don't quite understand how CommandReturninglist is defined if you're able to call it like that. Could you clarify? Maybe post the proc definition? And also the desired results? Commented Jun 18, 2020 at 14:38

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@ManishaKuhar I'm passing $i as an argument. Arguments are separated from command names by spaces in Tcl.
I got it now, Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.