title: Complex number arithmetic in Tcl?
body: <p>Is there an equivalent to the <code>expr</code> command which works for complex numbers (represented lists of two doubles)?</p>
  
  <p><a href="http://tcllib.sourceforge.net/doc/qcomplex.html" rel="noreferrer">This</a> library provides functions for complex number arithmetic, and <a href="http://wiki.tcl.tk/15703" rel="noreferrer">this</a> seems to be a useful utility to define the required <code>cexpr</code> function, but it doesn't work well.</p>
  
  <p>E.g. it doesn't handle properly the brackets.</p>
  
  <pre><code>ParseExpressions::ParseExpr { (1) + ((2) + (3)) } { }
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>+ [+ 1 ((2)] (3))
  </code></pre>
  
  <p>while it should return</p>
  
  <pre><code>+ [+ 1 2] 3
  </code></pre>
  
  <p>Also
  ParseExpressions::ParseExpr { {1 2} + {3 4} } {}</p>
  
  <p>returns</p>
  
  <pre><code>+ 1 2 3 4
  </code></pre>
  
  <p>while it should return</p>
  
  <pre><code>+ {1 2} {3 4}
  </code></pre>
  
  <p>So basically I am asking for a robust version of <a href="http://wiki.tcl.tk/15703" rel="noreferrer">this</a> utility.</p>