From: Martin L. <mar...@gm...> - 2005-07-22 15:31:10
|
Hello Jeff, your suggestion to have min and max as expr-function is really good, but the need to convert lists into comma separeted strings is not the right way (loosing internal reps and shimmering effects). Yes - currently this is the only way for the math functions, which are not allowed to have pure tcl list objects as argument! And the need to convert a list before using the values would bring some other difficulties with: % set values [list 1 5 2 3 0 5 3 7] % set csvValues [join $values ","] % set minimum [expr {min([join $values ","])}]; # see the braces around the expression % set minimum [expr {min($csvValues)}]; # see the braces around the expression The expression would be min("1,5,2,3,0,5,3,7") and would fail, because the min-argument is not a number. % set minimum [expr min([join $list ","])]; # see the missing braces around the expression % set minimum [expr min($csvValues)]; # see the missing braces around the expression The expression would be min(1,5,2,3,0,5,3,7) and would succeed, but complex expressions without braces are much slower! You can examine this problem e.g. with the pow function. So your suggestion would require to extend the allowed argument types of math functions with list types like ... TCL_DOUBLE_LIST, TCL_INT_LIST, TCL_WIDE_INT_LIST, and TCL_EITHER_LIST. So ... this could be covered by an extended TIP #254. And if the TIP #254 extends to allow lists as math function arguments, than it will be possible (at last) to use linear algebra functions on matrices and vectors represented by lists of doubles or integers - wow, that would be fine! A standard set of vector and matrix math functions could be implemented into the core! Finally - yes, implement min and max, but only with list arguments! Best regards, Martin Lemburg > -----Original Message----- > From: tcl...@li... > [mailto:tcl...@li...] On Behalf Of Jeff Hobbs > Sent: Thursday, July 21, 2005 11:14 PM > To: tcl...@li... > Cc: Jeff Hobbs > Subject: [TCLCORE] TIP #255: Add 'min' and 'max' [expr] Functions > > > TIP #255: ADD 'MIN' AND 'MAX' [EXPR] FUNCTIONS > ================================================ > Version: $Revision: 1.1 $ > Author: Jeff Hobbs <jeffh_at_activestate.com> > State: Draft > Type: Project > Tcl-Version: 8.5 > Vote: Pending > Created: Thursday, 21 July 2005 > URL: http://purl.org/tcl/tip/255.html > WebEdit: http://purl.org/tcl/tip/edit/255 > Post-History: > > -------------------------------------------------------------- > ----------- > > ABSTRACT > ========== > > This TIP proposes enhancing the Tcl *expr* command with > *min* and *max* > functions. > > RATIONALE > =========== > > Many programs need to find the minimum or maximum of a set > of numbers, > so having functions to do this will make many script > programmers' lives > easier. This will be adopting yet another feature from TclX, > but with > the minor enhancement of being able to handle arbitrary numbers of > arguments. > > SPECIFICATION > =============== > > The *min* and *max* functions shall be created using Tcl > commands (in a > namespace such all namespaces will pick them up by default) > in the new > 8.5 *expr* function style. They will take one or more > numeric arguments > (of any valid numeric type) and return the minimum or > maximum value of > those numbers (depending on which function was invoked). > > EXAMPLES > ========== > > expr {min(0,3,1)} > => 0 > expr {max(4.2, 0xF, wide(1))} > => 15.0 > expr {min(4.2)} > => 4.2 > expr {min()} > => too few arguments for math function > > REFERENCE IMPLEMENTATION > ========================== > > [To be uploaded to SourceForge and URL added to this TIP.] > > COPYRIGHT > =========== > > This document has been placed in the public domain. > > -------------------------------------------------------------- > ----------- > > TIP AutoGenerator - written by Donal K. Fellows > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > Tcl-Core mailing list > Tcl...@li... > https://lists.sourceforge.net/lists/listinfo/tcl-core > > ---------------------------------------------------- > This message has been processed by Firetrust Benign. |