Re: Help Please with numbers
- Posted by Jason Gade <jaygade at yahoo.com> Aug 02, 2005
- 618 views
cklester wrote: > > Jason Gade wrote: > > > > I had thought about this case. I think that the programmer would just have > > to be clear > > in what he or she wants. sum(1) makes as much sense as sum("123"). > > > > sum("123", 0) should work correctly. sum("123") would produce 150 because it > > is ambiguous. > > > > I still wonder whether it would be a useful feature. How often is implicit > > conversion > > from string to number needed? > > You could just provide the base functionality of summing only integers/atoms > in a sequence, and if the user wanted more they could wrap it themselves. > > sumi() -- sum a list of integers > suma() -- sum a list of atoms > sum() -- sum a list of atoms and/or integers > > -=ck > "Programming in a state of EUPHORIA." > <a > href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a> > For me, atoms and integers should be the same and should be the default case. If adding a sum() function that took strings as input, it would be the one with a different name because it is the exceptional case. One of my favorite features of Euphoria is its value-based semantics. A large set of numbers can be represented by atoms. Every value in Euphoria is either an atom or a sequence, therefore a number or a list of numbers. It is up to the programmer to interpret them. ===================================== Too many freaks, not enough circuses. j.