Note that there are some explanatory texts on larger screens.

plurals
  1. POstrange behaviour of `eval` in Tcl
    primarykey
    data
    text
    <p>I have encountered a strange behaviour by the <code>eval</code> command that I can't understand. When I try use eval to run a command whose name is stored in a variable I get strange results.</p> <p>The array <code>mCallBackCont</code> has the value <code>::postLayRep1||mainTableView sendToLoads</code> under <code>insert</code>, so that<sup>*</sup>:</p> <pre><code>&gt;&gt;set mCallBackCont(insert) ::postLayRep1||mainTableView sendToLoads </code></pre> <p>Where <code>::postLayRep1||mainTableView</code> is an object of a class that has a <code>sendToLoads</code> public method</p> <p>When I try to do one of the following:</p> <pre><code>eval {::postLayRep1||mainTableView sendToLoads} eval ::postLayRep1||mainTableView sendToLoads eval "::postLayRep1||mainTableView sendToLoads" eval $mCallBackCont(insert) eval "mCallBackCont(insert)" </code></pre> <p>I get the correct behaviour, but When I use</p> <pre><code>eval {$mCallBackCont(insert)} </code></pre> <p>I get the error:</p> <pre><code>invalid command name "::postLayRep1||mainTableView sendToLoads" </code></pre> <p>When I try the same with a regular proc with no argument:</p> <pre><code>&gt;&gt;proc test_proc {} {return} &gt;&gt;set a test_proc &gt;&gt;eval {$a} </code></pre> <p>Everything works, but when I add argument, the same happens:</p> <pre><code>&gt;&gt;proc test_proc {val} {puts $val} &gt;&gt;set a [list test_proc 1] test_proc 1 &gt;&gt;eval {$a} invalid command name "test_proc 1" </code></pre> <p>Since the eval command is part of a code from a library I'm using I can't change it, the only thing I can determine is the value of <code>mCallBackCont(insert)</code>. The code in the library is:</p> <pre><code>if { [catch {eval {$mCallBackCont(insert) [namespace tail $this] $type $name $n $redraw}} e] } { error "Wrong number of arguments for the procedure \"$mCallBackCont(insert)\". Should be \"table type name num redraw\"." } </code></pre> <ul> <li><p>Why does <code>eval {$var}</code> works for procs but not for methods of a class (I guess it somehow relates to the fact that the proc is a 1-word command, while a method is more complicated)?</p></li> <li><p>In what way can I set the value of <code>mCallBackCont(insert)</code> so that it works correctly?</p></li> </ul> <hr> <p><sup>*</sup> - I have tried to put the value in <code>mCallBackCont(insert)</code> both a list and as one string surrounded by <code>""</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload