0

This is a very basic question.

I think of TCL as a command line generator. Its purpose is to generate strings for the tool’s command line interpreter. For example, the tcl commands:

set alpha “run”
$alpha
$alpha
$alpha

cause the “run” command to be sent to the tool three times – which makes sense. But:

set alpha “run”
for {set i 0} {$i<3} {incr i} $alpha

does not. So the question is: How do I send commands to the tool from inside a loop?

1
  • Style point: write the loop as for {set i 0} {$i<3} {incr i} {$alpha} to avoid possible issues with quoting. I hope that's not going to fix it for real for you, but maybe… Commented Apr 25, 2016 at 8:11

2 Answers 2

1

Your problem is likely to be with the "funny quotes" in the line

set alpha “run”

To Tcl, those quotes aren't syntactic markers, just text. Try

set alpha "run"

or, even better,

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

Comments

0

Here's a possible way (with output):

% proc foo {count} {
    puts "count = $count"
}
% set alpha foo
foo
% for {set i 0} {$i<3} {incr i} {
    $alpha $i    
}
count = 0
count = 1
count = 2
% 

2 Comments

The use of eval is unnecessary here and can actually break things if any of the arguments has list structure.
@PeterLewerin Agree. Thanks. Updated the snippet above.

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.