webppl icon indicating copy to clipboard operation
webppl copied to clipboard

reduce function processes arguments in the wrong order

Open wo opened this issue 1 year ago • 0 comments

The documentation gives this example use of reduce:

reduce(function(x, acc) { return x + acc; }, 0, [1, 2, 3]); // => 6

From this, I would expect that the first argument is a function that takes the current result as first argument and the accumulator as second (as in JS's array.reduce). But it seems to be the other way around. For example, reduce(function(x, acc) { return x - acc; }, 1, [1, 2]) returns 0, where I would expect -2.

(The current reduce function seems to loop over the supplied array [1,2] from right to left, passing each value as x and the present result as acc.)

wo avatar Mar 28 '23 08:03 wo