From: David S. <Dav...@sy...> - 2010-03-04 17:32:31
|
I added Vector/Matrix/Array operators to Tcl about 19 years ago. In doing so I did it with a handle based approach since textually displaying large vectors and mutli-dimensional arrays is not particularly useful. I also added waveforms for EDA at the same time and that deals with large data sets. The core change was to overload all the operators (plus add a few) to know about the new types. The new operators had to do with defining slices of arrays using a syntactical notation the parser knows about plus some matrix operators. Doing things with lists I think is not a great idea. The underlying data structure does not support an efficient mechanism for defining slices into large datasets that does duplicate storage. The other incompatible syntax changes are also undesirable. I can provide more details on this if anyone is interested. I passed it to John O. and Scriptics a long time ago and they did not see a lot of demand for the functionality. Regards David David W. Smith Synopsys Scientist Synopsys, Inc. Synopsys Technology Park 2025 NW Cornelius Pass Road Hillsboro, OR 97124 Voice: 503.547.6467 Main: 503.547.6000 Cell: 503.560.5389 FAX: 503.547.6906 Email: dav...@sy... http://www.synopsys.com Saber Accelerates Robust Design Predictable. Repeatable. Reliable. Proven. -----Original Message----- From: Neil Madden [mailto:ne...@Cs...] Sent: Thursday, March 04, 2010 8:36 AM To: Alexandre Ferrieux Cc: tcl...@li...; Karl C. Hansen Subject: Re: [TCLCORE] TIP #363: Vector Math in the Tcl Core 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 |