Eve icon indicating copy to clipboard operation
Eve copied to clipboard

Sum should provide an error when used without value

Open edgenard opened this issue 9 years ago • 4 comments

When trying to use the sum function I get this error

  commit
    [#bills name: "Phone", amount: 85]
    [#bills name: "Apple Music", amount: 15]
    [#bills name: "Internet", amount: 100]

search
    [#bills name amount]
    total-bills = sum[given: amount]

bind @browser
     [#h1 text: "Sum error"]
     [#p text: "{{total-bills}}"]
screen shot 2016-10-29 at 12 41 41 pm

edgenard avatar Oct 29 '16 16:10 edgenard

For sum, Eve needs the value to sum over as well:

search
    bill = [#bills name amount]
    total-bills = sum[value: amount, given: bill]

bind @browser
     [#h1 text: "Sum error"]
     [#p text: "{{total-bills}}"]

You probably want to use bill as the given here, otherwise if there are multiple bills with the same amount only one of them would get summed. The way to think of given is kind of like "for each unique one of these." So for each unique bill, sum the value.

We definitely should give you better information here and shouldn't be blowing up, so I'll leave this bug up to track that.

ibdknox avatar Oct 29 '16 17:10 ibdknox

Thanks for explaining!

edgenard avatar Oct 29 '16 18:10 edgenard

Eve needs the value to sum over as well

It could be helpful to add this explanation to the sum docs as well. That was my first attempt at resolving the problem.

mndrix avatar Dec 06 '16 13:12 mndrix

@mndrix Just merged that in actually: https://github.com/witheve/docs/blob/master/handbook/math/sum.md The docs site doesn't update automatically, but I'll do that before I leave the office today.

cmontella avatar Dec 06 '16 22:12 cmontella