TCL subst or eval command is not working in my case ..

前端 未结 3 2077
醉酒成梦
醉酒成梦 2021-01-26 10:30
subst or eval command is not working in my case .. 

% proc sum {a b} {
    return [expr $a+$b]
}
%
% set a 1
1
% set b 2
2
% sum $a $b
3

%
% sum {$a} {$b}
can\'t use n         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-26 10:53

    You put the square braces [] to the wrong place (resp. you even don't need them in the eval case). In the way you wrote the commands the sum {$a} {$b}] is evaluated before the subst or eval command could evaluate the contents of $a and $b.

    Correct is:

    eval sum {$a} {$b}
    

    or

    sum [subst {$a}] [subst {$b}]
    

提交回复
热议问题