Re: Help Please with numbers

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete Lomax wrote:
> 
> 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.

Okay, assuming the programmer who uses sum understands the design and
documentation of sum then he or she will just have to be clear in what he or she
wants.

> > 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?</font></i>
> 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
> 
> 

sum

Syntax:        x2 = sum(x1)

Description:   Calculate the sum of all top-level elements of x1.

Comments:      This function may be applied to a single level sequence or a
multi-level sequence.  In the case of a mult-level sequence, all elements must be
atoms or sequences with the same length.

This function is useful for adding up a list of numbers of unknown length.

Example 1:}}}
<eucode>x = sum({1, 3, 5, 7, 9})
                  -- x is 25</eucode>
{{{


Example 2:}}}
<eucode>x = sum({1, 2, 3}, 4, {5, 6, 7})
                  -- x is {10, 12, 14}</eucode>
{{{


Example 3:}}}
<eucode>x = sum({49, 50, 51}, {52, 53})
                  -- yields an error</eucode>
{{{


See Also:      rsum (recursive sum)

Anyway, at first ck's suggestion seemed reasonable and I could'nt *completely*
poke a hole in it. I considered your example and I considered ways around it. I
just think that it shouldn't implicitly convert strings to values because

1. The programmer can explicitly do it with value()
2. It could lead to ambiguity
3. It's just not the way things are done.


=====================================
Too many freaks, not enough circuses.

j.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu