Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2016-01-15 Thread Max Leske
Ok. So while the “decorator” approach looks fantastic it will obviously have its own drawbacks. Discussing this on the mailing list is very tiering, so I suggest that this should be discussed during the next sprint or Pharo days. Since I will not be able to attend either one, can I ask one of

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2016-01-08 Thread stepharo
Sven may be should do the following: - introduce the best solution (not using your and henrik decomposition) - continue to think about it. I would like to see if Xtreams does not go in the same direction too. But I do not have the code at hand to think about it. Stef

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2016-01-07 Thread Sven Van Caekenberghe
; This inspired me to do something similar, but not quite. I am just thinking >>> out loud by implementation. Here is my result: >>> >>> >>> >>> There are some examples in the class comments. >>> >>> Sven >>> >>>&

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2016-01-07 Thread Denis Kudriashov
2016-01-07 13:14 GMT+01:00 Max Leske : > Very, very cool Sven (and Henrik!)! > > And it even works with exotic objects: { 1@2. 2@3 } numbers sum “—> (3@5)” > I really not understand how it helps with original problem. There was example with colors sum which was stop people to

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2016-01-07 Thread Ben Coman
ationsOnMagnitudes. I guess I fear there is hidden complexity for little gain. Maybe those that like the idea can collaborate on a package they use on their own projects to work out the kinks. cheers -ben >> >> Sven >> >>> Best regards, >>> Henrik >>

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2016-01-07 Thread Guillermo Polito
like Time > >>> "17:28 . 17:29 . 17:31 . 17:32" or Duration "4 minutes . 6 minutes" > >>> I would expect to be able to get 17:30 and 5 minutes as the respective > >>> averages. > >>> But then it doesn't make sense to average other magnitudes

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2016-01-07 Thread Ben Coman
> In this case, you could use #numbers to indicate that you see your objects as > compatible with that (and the time objects mostly are). > > But summing an empty collection of Durations, you would probably want > Duration zero to be the result, and then we are back to our original pro

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2016-01-04 Thread Guillermo Polito
al Message- >> From: Pharo-dev [mailto:pharo-dev-boun...@lists.pharo.org] On Behalf Of >> stepharo >> Sent: Thursday, December 24, 2015 9:58 AM >> To: Pharo Development List <pharo-dev@lists.pharo.org> >> Subject: Re: [Pharo-dev] #sum:, #detectSum:, #sum

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2016-01-04 Thread Tudor Girba
; From: Pharo-dev [mailto:pharo-dev-boun...@lists.pharo.org] On Behalf Of >> stepharo >> Sent: Thursday, December 24, 2015 9:58 AM >> To: Pharo Development List <pharo-dev@lists.pharo.org> >> Subject: Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers: >> >>

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-29 Thread Sven Van Caekenberghe
t; > -Original Message- > From: Pharo-dev [mailto:pharo-dev-boun...@lists.pharo.org] On Behalf Of > stepharo > Sent: Thursday, December 24, 2015 9:58 AM > To: Pharo Development List <pharo-dev@lists.pharo.org> > Subject: Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbe

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-28 Thread Eliot Miranda
> On Dec 27, 2015, at 1:52 PM, Nicolas Cellier > wrote: > > > > 2015-12-27 2:49 GMT+01:00 Ben Coman : >> On Sun, Dec 27, 2015 at 6:13 AM, Nicolas Cellier >> wrote: >> > >> > >> > 2015-12-25 2:03

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-28 Thread Sven Van Caekenberghe
Well, I beg to disagree, #sum on an empty collection should return 0. https://en.wikipedia.org/wiki/Empty_sum We do not need more tricks, the current trick with #anyOne is more than enough, that is not the problem. The problem is that it is impossible to talk about sum (in the general most

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-28 Thread Robert Withers
This is sounding like a type inference situation. On 12/28/2015 03:20 PM, Sven Van Caekenberghe wrote: Well, I beg to disagree, #sum on an empty collection should return 0. https://en.wikipedia.org/wiki/Empty_sum We do not need more tricks, the current trick with #anyOne is more than enough,

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-27 Thread Nicolas Cellier
2015-12-27 2:49 GMT+01:00 Ben Coman : > On Sun, Dec 27, 2015 at 6:13 AM, Nicolas Cellier > wrote: > > > > > > 2015-12-25 2:03 GMT+01:00 Eliot Miranda : > >> > >> Ben, > >> > >> _,,,^..^,,,_ (phone) > >> > >> > On

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-26 Thread Nicolas Cellier
2015-12-25 2:03 GMT+01:00 Eliot Miranda : > Ben, > > _,,,^..^,,,_ (phone) > > > On Dec 4, 2015, at 12:49 AM, Ben Coman wrote: > > > >> On Fri, Dec 4, 2015 at 4:23 AM, Nicolai Hess > wrote: > >> > >> > >> 2015-12-03 14:48

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-26 Thread Ben Coman
On Sun, Dec 27, 2015 at 6:13 AM, Nicolas Cellier wrote: > > > 2015-12-25 2:03 GMT+01:00 Eliot Miranda : >> >> Ben, >> >> _,,,^..^,,,_ (phone) >> >> > On Dec 4, 2015, at 12:49 AM, Ben Coman wrote: >> > >> >> On

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-25 Thread Henrik Nergaard
ct: Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers: Just a remark. I think that we discarded the proposition of having aCol arithmetic sum but I found it nice because there if was clear that you want to get back 0 for #(). Stef

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-25 Thread stepharo
Just a remark. I think that we discarded the proposition of having aCol arithmetic sum but I found it nice because there if was clear that you want to get back 0 for #(). Stef

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-23 Thread stepharo
Just a remark. I think that we discarded the proposition of having aCol arithmetic sum but I found it nice because there if was clear that you want to get back 0 for #(). Stef

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-22 Thread Nicolas Cellier
2015-12-22 10:37 GMT+01:00 Sven Van Caekenberghe : > > > On 22 Dec 2015, at 10:22, Nicolas Cellier < > nicolas.cellier.aka.n...@gmail.com> wrote: > > > > > > > > 2015-12-22 3:46 GMT+01:00 Ben Coman : > > On Wed, Dec 2, 2015 at 3:38 AM, Tudor Girba

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-22 Thread Denis Kudriashov
Hi My vote: > 1. Do you agree to changing #sum and #sum: in the suggested way? > yes but I prefer #sum: return zero too for empty collections > 2. Do you agree to the removal of #detectSum:? > yes > > 3. Do you agree to the removal of #sumNumbers? > yes > > 4. Do you agree that the

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-22 Thread Ferlicot D. Cyril
Le 20/12/2015 12:59, Max Leske a écrit : > I would like to wrap up this discussion. > > > While I think that iterators are an intriguing idea I also believe that > they are beyond the scope of this issue. If anybody wants to follow up > on iterators (or unit types for that matter) please start

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-22 Thread Sven Van Caekenberghe
> On 22 Dec 2015, at 10:22, Nicolas Cellier > wrote: > > > > 2015-12-22 3:46 GMT+01:00 Ben Coman : > On Wed, Dec 2, 2015 at 3:38 AM, Tudor Girba wrote: > > I am saying that if you want sum: to be generic, it

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-22 Thread Nicolai Hess
2015-12-20 12:59 GMT+01:00 Max Leske : > > > I propose to use Sven’s version for #sum:ifEmpty:. The result would be > these three methods: > > sum > ^ self > sum: [ :each | each ] > ifEmpty: [ 0 ] > > sum: aBlock > ^ self > sum: aBlock > ifEmpty: [ self errorEmptyCollection ]

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-22 Thread Nicolas Cellier
2015-12-22 3:46 GMT+01:00 Ben Coman : > On Wed, Dec 2, 2015 at 3:38 AM, Tudor Girba wrote: > > I am saying that if you want sum: to be generic, it cannot assume a > *specific* Zero object. > > And sum: should be generic because of its name. > > This

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers: (Max Leske)

2015-12-21 Thread Sven Van Caekenberghe
> On 21 Dec 2015, at 23:48, Richard Uttner wrote: > > This is my first contribution to the DevList and I hope you forgive me that > it sounds more like "I see something we dont need" than the other way round, > but there will be more positive posts of mine concering

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-21 Thread Ben Coman
On Wed, Dec 2, 2015 at 3:38 AM, Tudor Girba wrote: > I am saying that if you want sum: to be generic, it cannot assume a > *specific* Zero object. > And sum: should be generic because of its name. This seems the crux of the disparate viewpoints, which is why I suggested

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-21 Thread Sven Van Caekenberghe
I would suggest not to change anything for now, let's wait for Max's poll or feedback from others. We could also pick this up again when we see each other IRL, like at the Pharo Days, that will certainly make it easier. > On 20 Dec 2015, at 22:09, Tudor Girba wrote: > >

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Tudor Girba
Hi, I cannot seem to agree with the current line of reasoning, so I am withdrawing from this debate. It’s late in the year and I know I need a break, so it is likely that I am missing something obvious or that I am just persisting in some sort of bike-shedding point of view :). Thanks for

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Gabriel Cotelli
Max, sum: aBlock ifEmpty: emptyBlock needs to obtain the sample evaluating the block. sum: aBlock ifEmpty: emptyBlock | sum sample | self isEmpty ifTrue: [ ^ emptyBlock value ]. sample := aBlock value: self anyOne. sum := self inject: sample into: [ :accum :each | accum + (aBlock value: each) ].

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Sven Van Caekenberghe
> On 20 Dec 2015, at 12:59, Max Leske wrote: > > I would like to wrap up this discussion. Good idea. >> On 05 Dec 2015, at 18:14, stepharo wrote: >> >> So what is the conclusion? >> I like the idea of Esteban M to have iterator because it moves some

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Tudor Girba
Hi, Could we not have sum, but sumNumbers instead? So, we would end up with: sum:ifEmpty: sum: (with error) sumNumbers (without error) From the outside, #sum: looks like it should parameterize #sum, but the implementation is actually different. So, given that in this implementation #sum is

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Max Leske
> On 20 Dec 2015, at 13:43, Gabriel Cotelli wrote: > > Max, > > sum: aBlock ifEmpty: emptyBlock needs to obtain the sample evaluating the > block. > > sum: aBlock ifEmpty: emptyBlock > | sum sample | > self isEmpty ifTrue: [ ^ emptyBlock value ]. >

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Max Leske
I would like to wrap up this discussion. > On 05 Dec 2015, at 18:14, stepharo wrote: > > So what is the conclusion? > I like the idea of Esteban M to have iterator because it moves some behavior > out of core classes. > > [[[ > > aCollection arithmetic sum: [...] or

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Max Leske
> On 20 Dec 2015, at 14:10, Tudor Girba wrote: > > Hi, > > Could we not have sum, but sumNumbers instead? So, we would end up with: > > sum:ifEmpty: > sum: (with error) > sumNumbers (without error) > > From the outside, #sum: looks like it should parameterize #sum, but

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Tudor Girba
Hi, > On Dec 20, 2015, at 2:30 PM, Max Leske wrote: > > >> On 20 Dec 2015, at 14:10, Tudor Girba wrote: >> >> Hi, >> >> Could we not have sum, but sumNumbers instead? So, we would end up with: >> >> sum:ifEmpty: >> sum: (with error) >> sumNumbers

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Tudor Girba
Hi, It’s clear that choices we would make would not be the same :). So, let’s drop past discussions and stay with the current situation. Do you agree with the observation that in the proposal of Max #sum and #sum: would not share the same meaning? If yes, do you agree that it would be

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Sven Van Caekenberghe
No means I don't want to start adding Numbers to beautiful unary selectors. I don't understand why you don't understand that point about beauty and simplicity. > On 20 Dec 2015, at 14:54, Tudor Girba wrote: > > Hi, > > I am not sure I understand the meaning of NO in the

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Sven Van Caekenberghe
> On 20 Dec 2015, at 14:57, Tudor Girba wrote: > > Hi, > > It’s clear that choices we would make would not be the same :). So, let’s > drop past discussions and stay with the current situation. Do you agree with > the observation that in the proposal of Max #sum and

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Sven Van Caekenberghe
Doru, For me this whole discussion started because you (the standpoint that you take) hijacked the best selector (#sum) for a use case that is much less common than adding a collection of numbers which should give 0 when empty (you hijack it by not wanting to return 0, which I totally

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Sven Van Caekenberghe
NO > On 20 Dec 2015, at 14:32, Tudor Girba wrote: > > Hi, > >> On Dec 20, 2015, at 2:30 PM, Max Leske wrote: >> >> >>> On 20 Dec 2015, at 14:10, Tudor Girba wrote: >>> >>> Hi, >>> >>> Could we not have sum, but sumNumbers

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Tudor Girba
Hi, I am not sure I understand the meaning of NO in the context of the previous message. Is the NO related to the sumNumbers, or to the min, max? Cheers, Doru > On Dec 20, 2015, at 2:43 PM, Sven Van Caekenberghe wrote: > > NO > >> On 20 Dec 2015, at 14:32, Tudor Girba

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Tudor Girba
Hi, > On Dec 20, 2015, at 3:07 PM, Sven Van Caekenberghe wrote: > > >> On 20 Dec 2015, at 14:57, Tudor Girba wrote: >> >> Hi, >> >> It’s clear that choices we would make would not be the same :). So, let’s >> drop past discussions and stay with the

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Ben Coman
On Mon, Dec 21, 2015 at 12:43 AM, Sven Van Caekenberghe wrote: > Doru, > > For me this whole discussion started because you (the standpoint that you > take) hijacked the best selector (#sum) for a use case that is much less > common than adding a collection of numbers which should

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Max Leske
Updated benchmarks with pre-calculated collection of numbers (as suggested by Sven): Benchmarks of the current versions: [ (1 to: 100) asArray sum ] benchFor: 10 seconds. 124 iterations, 12.389 per second [ (1 to: 100) asArray sum: [ :e | e ] ] benchFor: 10 seconds.

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Max Leske
> On 20 Dec 2015, at 15:26, Ben Coman wrote: > > On Mon, Dec 21, 2015 at 12:43 AM, Sven Van Caekenberghe > wrote: >> Doru, >> >> For me this whole discussion started because you (the standpoint that you >> take) hijacked the best

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-20 Thread Max Leske
I did a pass on all the changes that would be required (whatever the outcome of this discussion). Looks easy enough. One interesting point: FloatArray>>sum is implemented as a primitive in the FloatArrayPlugin and the zero element is explicitly defined as 0.0. The primitive will not fail for an

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-05 Thread stepharo
So what is the conclusion? I like the idea of Esteban M to have iterator because it moves some behavior out of core classes. [[[ aCollection arithmetic sum: [...] or aCollection arithmetic avg. ]]]

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-04 Thread Max Leske
> On 04 Dec 2015, at 01:49, Ben Coman wrote: > > On Fri, Dec 4, 2015 at 4:23 AM, Nicolai Hess > wrote: >> >> >> 2015-12-03 14:48 GMT+01:00 Ben Coman : >>> >>> On Wed, Dec 2, 2015 at 10:45 PM,

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-03 Thread Chris Cunningham
On Thu, Dec 3, 2015 at 4:51 PM, Ben Coman wrote: > On Fri, Dec 4, 2015 at 3:26 AM, Chris Cunningham > wrote: > > > > > > On Thu, Dec 3, 2015 at 5:48 AM, Ben Coman wrote: > >> > >> > >> > >> * Points are summable " { 2@2 .

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-03 Thread Ben Coman
On Wed, Dec 2, 2015 at 10:45 PM, Sven Van Caekenberghe wrote: > >> On 02 Dec 2015, at 15:21, Nicolai Hess wrote: >> >> >> >> 2015-12-02 15:03 GMT+01:00 Ben Coman : >> On Wed, Dec 2, 2015 at 12:38 AM, Tudor Girba

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-03 Thread Chris Cunningham
On Thu, Dec 3, 2015 at 5:48 AM, Ben Coman wrote: > > > * Points are summable " { 2@2 . 3@3 } " --> 5@5. But then " 2@2 + > 1 " --> 3@3 , so " {} sum " returning 0 would seem to not > cause any error in this case. > > > cheers -ben but points aren't

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-03 Thread Nicolai Hess
2015-12-03 14:48 GMT+01:00 Ben Coman : > On Wed, Dec 2, 2015 at 10:45 PM, Sven Van Caekenberghe > wrote: > > > >> On 02 Dec 2015, at 15:21, Nicolai Hess wrote: > >> > >> > >> > >> 2015-12-02 15:03 GMT+01:00 Ben Coman

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-03 Thread Ben Coman
On Fri, Dec 4, 2015 at 4:23 AM, Nicolai Hess wrote: > > > 2015-12-03 14:48 GMT+01:00 Ben Coman : >> >> On Wed, Dec 2, 2015 at 10:45 PM, Sven Van Caekenberghe >> wrote: >> > >> >> On 02 Dec 2015, at 15:21, Nicolai Hess

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-03 Thread Ben Coman
On Fri, Dec 4, 2015 at 3:26 AM, Chris Cunningham wrote: > > > On Thu, Dec 3, 2015 at 5:48 AM, Ben Coman wrote: >> >> >> >> * Points are summable " { 2@2 . 3@3 } " --> 5@5. But then " 2@2 + >> 1 " --> 3@3 , so " {} sum " returning 0

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-02 Thread Sven Van Caekenberghe
> On 02 Dec 2015, at 15:45, Sven Van Caekenberghe wrote: > > The only change would be in the error behaviour. I think that is a reasonable > price to pay. Instead of having #anyOne fail, it will say that #+ cannot add > 0 to some object, and in a comment we can point to the

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-02 Thread Nicolai Hess
2015-12-02 15:03 GMT+01:00 Ben Coman : > On Wed, Dec 2, 2015 at 12:38 AM, Tudor Girba wrote: > > Hi, > > > >> On Dec 1, 2015, at 5:13 PM, Max Leske wrote: > >> > >> @Doru > >> You’re missing the point: #anyOne *fails* for empty

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-02 Thread Sven Van Caekenberghe
> On 02 Dec 2015, at 15:21, Nicolai Hess wrote: > > > > 2015-12-02 15:03 GMT+01:00 Ben Coman : > On Wed, Dec 2, 2015 at 12:38 AM, Tudor Girba wrote: > > Hi, > > > >> On Dec 1, 2015, at 5:13 PM, Max Leske

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-02 Thread Max Leske
Even though we haven’t been able to completely agree on the resolution, I feel we can agree that we need to change something. I’ve opened an issue and copied the messages from this thread into it for documentation. https://pharo.fogbugz.com/f/cases/17174/Unify-sum-sum-sumNumbers-and-detectSum

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-02 Thread Ben Coman
On Wed, Dec 2, 2015 at 12:38 AM, Tudor Girba wrote: > Hi, > >> On Dec 1, 2015, at 5:13 PM, Max Leske wrote: >> >> @Doru >> You’re missing the point: #anyOne *fails* for empty collections. > > I am not missing the point at all. I am saying that if you

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread J.F. Rick
Lovely little discussion which would be great for beginning OO programmers to see. The question of whether to return 0 for an empty collection is interesting. While other things can be summed, we tend to think of sums returning numbers. In that sense, 0 is a great default return. On the other

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Tudor Girba
Hi, > On Dec 1, 2015, at 3:24 PM, Sven Van Caekenberghe wrote: > > Doru, > >> On 01 Dec 2015, at 15:11, Tudor Girba wrote: >> >> Hi, >> >>> On Dec 1, 2015, at 12:52 PM, Sven Van Caekenberghe wrote: >>> >>> On 01 Dec 2015, at 12:45,

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Sven Van Caekenberghe
> On 01 Dec 2015, at 17:43, Tudor Girba wrote: > > Hi, > >> On Dec 1, 2015, at 3:24 PM, Sven Van Caekenberghe wrote: >> >> Doru, >> >>> On 01 Dec 2015, at 15:11, Tudor Girba wrote: >>> >>> Hi, >>> On Dec 1, 2015, at 12:52 PM,

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Thierry Goubier
Note that the sum with #anyOne is wrong. #(1 2 3 4 5) inject: #(1 2 3 4 5) anyOne into: [ :sum :each | sum + each ] returns 16 instead of 15. Thierry 2015-12-01 10:18 GMT+01:00 Ben Coman : > On Tue, Dec 1, 2015 at 4:45 PM, Sven Van Caekenberghe > wrote: >

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Thierry Goubier
Hi Max, Interesting results... replacing the #yourself in newSum: cuts the runtime by a factor of two. using an [:x | x ] block cost 10% compared to a direct version of sum. So the fastest sum is: sum ^ self inject: (self ifEmpty: [ ^ 0 ] ifNotEmpty: [ self anyOne ]) into: [ :sum :each | sum +

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Peter Uhnak
The differences between #sum: and #sumNumbers: are well described in the respective method comments, but I agree that this may be a problem as most people will go for #sum: even for basic numeric collections. (And I personally got bit by this.) So maybe #sum: could adopt #sumNumbers:

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Sven Van Caekenberghe
I am all for a cleanup, the current situation is confusing. The basic #sum should be fast AND work for empty collections with 0 as starting element. I know why the #anyOne is used, and that use case should be preserved, but it is less common IMHO. > On 01 Dec 2015, at 09:38, Thierry Goubier

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Ben Coman
On Tue, Dec 1, 2015 at 4:45 PM, Sven Van Caekenberghe wrote: > I am all for a cleanup, the current situation is confusing. > The basic #sum should be fast AND work for empty collections with 0 as > starting element. > I know why the #anyOne is used, and that use case should be

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Sven Van Caekenberghe
> On 01 Dec 2015, at 10:24, Thierry Goubier wrote: > > Note that the sum with #anyOne is wrong. > > #(1 2 3 4 5) inject: #(1 2 3 4 5) anyOne into: [ :sum :each | sum + each ] > > returns 16 instead of 15. You have subtract the element you picked with #anyOne ! >

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Sven Van Caekenberghe
> On 01 Dec 2015, at 10:18, Ben Coman wrote: > > On Tue, Dec 1, 2015 at 4:45 PM, Sven Van Caekenberghe wrote: >> I am all for a cleanup, the current situation is confusing. >> The basic #sum should be fast AND work for empty collections with 0 as >>

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Nicolai Hess
2015-12-01 10:26 GMT+01:00 Sven Van Caekenberghe : > > > On 01 Dec 2015, at 10:24, Thierry Goubier > wrote: > > > > Note that the sum with #anyOne is wrong. > > > > #(1 2 3 4 5) inject: #(1 2 3 4 5) anyOne into: [ :sum :each | sum + each > ] > > > >

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Nicolai Hess
2015-12-01 10:26 GMT+01:00 Sven Van Caekenberghe : > > > On 01 Dec 2015, at 10:18, Ben Coman wrote: > > > > On Tue, Dec 1, 2015 at 4:45 PM, Sven Van Caekenberghe > wrote: > >> I am all for a cleanup, the current situation is confusing. > >> The

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Thierry Goubier
2015-12-01 10:29 GMT+01:00 Nicolai Hess : > > > 2015-12-01 10:26 GMT+01:00 Sven Van Caekenberghe : > >> >> > On 01 Dec 2015, at 10:24, Thierry Goubier >> wrote: >> > >> > Note that the sum with #anyOne is wrong. >> > >> > #(1 2 3 4

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Sven Van Caekenberghe
The basic question for me is, what should #() sum return. Right now, it is an error, I would very much like that for this common case the result would be 0. There is a lot of power (easy of use) in a unary selector, we should not destroy that with semantics that force a test before using

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Thierry Goubier
2015-12-01 11:46 GMT+01:00 Sven Van Caekenberghe : > The basic question for me is, what should > > #() sum > > return. Right now, it is an error, I would very much like that for this > common case the result would be 0. There is a lot of power (easy of use) in > a unary selector,

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Peter Uhnak
On 12/01, Thierry Goubier wrote: > 2015-12-01 11:46 GMT+01:00 Sven Van Caekenberghe : > > > The basic question for me is, what should > > > > #() sum > > > > return. Right now, it is an error, I would very much like that for this > > common case the result would be 0. There is a

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Stephan Eggermont
On 01-12-15 11:46, Sven Van Caekenberghe wrote: The basic question for me is, what should #() sum return. Right now, it is an error, I would very much like that for this common case the result would be 0. There is a lot of power (easy of use) in a unary selector, we should not destroy

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Sven Van Caekenberghe
> On 01 Dec 2015, at 12:45, Stephan Eggermont wrote: > > On 01-12-15 11:46, Sven Van Caekenberghe wrote: >> The basic question for me is, what should >> >> #() sum >> >> return. Right now, it is an error, I would very much like that for this >> common case the result

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Yuriy Tymchuk
#sum:ifEmpty: looks nice > On 01 Dec 2015, at 12:45, Stephan Eggermont wrote: > > On 01-12-15 11:46, Sven Van Caekenberghe wrote: >> The basic question for me is, what should >> >> #() sum >> >> return. Right now, it is an error, I would very much like that for this >>

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Sven Van Caekenberghe
Doru, > On 01 Dec 2015, at 15:11, Tudor Girba wrote: > > Hi, > >> On Dec 1, 2015, at 12:52 PM, Sven Van Caekenberghe wrote: >> >> >>> On 01 Dec 2015, at 12:45, Stephan Eggermont wrote: >>> >>> On 01-12-15 11:46, Sven Van Caekenberghe

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Esteban A. Maringolo
I don't want to be heretic (or too orthodox), but why not to delegate this behavior to other class (an iterator maybe?). It's too tempting adding these convenience methods to Collection and/or subclasses, but anything that requires an explicit protocol of its elements is wrong, IMO. something

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Tudor Girba
Hi, > On Dec 1, 2015, at 3:21 PM, Yuriy Tymchuk wrote: > >> >> On 01 Dec 2015, at 15:11, Tudor Girba wrote: >> >> Hi, >> >>> On Dec 1, 2015, at 12:52 PM, Sven Van Caekenberghe wrote: >>> >>> On 01 Dec 2015, at 12:45, Stephan

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Max Leske
Well, I’m glad I've struck a nerve there :) I agree that signalling an exception isn’t wrong, it’s just annoying because you have to do the check manually each time. I think I like #sum:ifEmpty:. When you look through the methods in Collection you’ll see #sum, #sum: and #sum:ifEmpty together

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Tudor Girba
Hi, > On Dec 1, 2015, at 12:52 PM, Sven Van Caekenberghe wrote: > > >> On 01 Dec 2015, at 12:45, Stephan Eggermont wrote: >> >> On 01-12-15 11:46, Sven Van Caekenberghe wrote: >>> The basic question for me is, what should >>> >>> #() sum >>> >>> return.

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Yuriy Tymchuk
> On 01 Dec 2015, at 15:11, Tudor Girba wrote: > > Hi, > >> On Dec 1, 2015, at 12:52 PM, Sven Van Caekenberghe wrote: >> >> >>> On 01 Dec 2015, at 12:45, Stephan Eggermont wrote: >>> >>> On 01-12-15 11:46, Sven Van Caekenberghe wrote:

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Max Leske
@Doru You’re missing the point: #anyOne *fails* for empty collections. > On 01 Dec 2015, at 15:31, Esteban A. Maringolo wrote: > > I don't want to be heretic (or too orthodox), but why not to delegate > this behavior to other class (an iterator maybe?). > > It's too

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Ben Coman
On Tue, Dec 1, 2015 at 10:24 PM, Sven Van Caekenberghe wrote: > Doru, > >> On 01 Dec 2015, at 15:11, Tudor Girba wrote: >> >> Hi, >> >>> On Dec 1, 2015, at 12:52 PM, Sven Van Caekenberghe wrote: >>> >>> On 01 Dec 2015, at 12:45, Stephan

Re: [Pharo-dev] #sum:, #detectSum:, #sumNumbers:

2015-12-01 Thread Tudor Girba
Hi, > On Dec 1, 2015, at 5:13 PM, Max Leske wrote: > > @Doru > You’re missing the point: #anyOne *fails* for empty collections. I am not missing the point at all. I am saying that if you want sum: to be generic, it cannot assume a specific Zero object. And sum: should be