Re: Help Please with numbers
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Aug 02, 2005
- 577 views
On Tue, 02 Aug 2005 06:27:35 -0700, Jason Gade <guest at RapidEuphoria.com> wrote: >I think that the programmer would just have to be clear in what he or she >wants. I take it you mean the person who designs, documents, and codes sum(), rather than the person that uses it. > sum(1) makes as much sense as sum("123"). I did say "Holes in this example aside". > >sum("123", 0) should work correctly. So, is the result {49,50,51}, as in {49+0,50+0,51+0}, or 123? The answer is obvious once the statement "sum returns a single atomic value" has been made, but thus far I did not see such. Recall that in Euphoria {1,2,3}+{4,5,6} yields {5,7,9}. >sum("123") would produce 150 because it is ambiguous. The point I was trying to make was that the design and documentation of the sum() function should remove any such ambiguity. If sum("123") compiles cleanly and does not trigger a run-time error, then any result must be valid, unequivocal, and documented. > >I still wonder whether it would be a useful feature. How often is implicit >conversion from string to number needed? It depends where the data came from, and to some extent how useful you would consider a sum function in the first place. If we assume that the main reason anyone would use a sum function rather than inline +'s is because they are in a [nested] sequence of unknown length, then you have to ask what is the most likely source? Personally I suspect text files or web pages will be more common than say results from dir(). Regards, Pete