Forum Discussion
How - and when - does the accumulator of SCAN get reset?
- Jan 05, 2025
I think your question is really about how the accumulator in SCAN works and the answer is that it is NOT a good term at all. The "accumulator" is really just the previous resulting value and althought the term "accumulator" is technically correct, it can be confusing. I prefer to use "p" and "q" as in SCAN( _init, _array, LAMBDA( p, q, ...)) because "p" is the prior or previous value (and on the first iteration it will use the _init value you give it) and the "q" is the qth value in the _array. so it will iterate through the _array and at the end give a final answer (and because it is SCAN instead of REDUCE it will also give you every iteration on the way) based on the formula you give. The term "accumulator" is technically correct because when it goes into the 7th iteration it will pass the result from the 6th iteration but that result from the 6th iteration is technically the accumulated result from ALL the previous iterations. Hope that help.
I think your question is really about how the accumulator in SCAN works and the answer is that it is NOT a good term at all. The "accumulator" is really just the previous resulting value and althought the term "accumulator" is technically correct, it can be confusing. I prefer to use "p" and "q" as in SCAN( _init, _array, LAMBDA( p, q, ...)) because "p" is the prior or previous value (and on the first iteration it will use the _init value you give it) and the "q" is the qth value in the _array. so it will iterate through the _array and at the end give a final answer (and because it is SCAN instead of REDUCE it will also give you every iteration on the way) based on the formula you give. The term "accumulator" is technically correct because when it goes into the 7th iteration it will pass the result from the 6th iteration but that result from the 6th iteration is technically the accumulated result from ALL the previous iterations. Hope that help.