From: Neil M. <ne...@Cs...> - 2010-03-04 16:57:00
|
Alexandre Ferrieux wrote: > On 3/4/10, Karl C. Hansen <Kar...@br...> wrote: >> TIP #363: VECTOR MATH IN THE TCL CORE >> ======================================= >> >> With the proposed enhancement, and a vector-math core enhancement, >> given the assignments above, the following would behave identically: >> >> expr $ListA + {4 5 6} >> expr $ListA + $ListB >> expr {1 2 3} + $ListB >> expr {1 2 3} + {4 5 6} > > So basically you're proposing to break just about everything in Tcl > parsing to avoid writing a simple proc for vector/matrix/tensor > computations ? > > proc myexpr {x op y} { > if {[llength $x]==1} {return [expr $x $op $b} > if {[llength $x]!=[llength $y]} {error "Dimension mismatch"} > set z {} > foreach a $x b $y {lappend z [myexpr $a $op $b]} > return $z > } > > # The following four do the same today without breaking anything: > myexpr $ListA + {4 5 6} > myexpr $ListA + $ListB > myexpr {1 2 3} + $ListB > myexpr {1 2 3} + {4 5 6} Or just Brace Your Exprs (TM) and then write a TIP which actually proposes what the title suggests: adding vector versions of operators to [expr], such that [expr {$ListA + {4 5 6}}] does what makes sense. -- Neil |