I'm having a little trouble with the following. I've implemented a functional fold method in my custom list class that overrides Array() and []. I won't post that code here, except for the method itself. I think this is the fairly standard fold algorithm:
Code: Select all
fold(ini, opr) { ; fold list beginning with ini; applying operation opr sequentially to result of prior
acu := ini ; accumulator gets initial value
for idx, itm in this ; loop list
acu := opr.call(acu, itm) ; operation on prior acu and item
return acu ; return final state of accumulator
}
Code: Select all
lst := [20,30,10]
fnc := (a,i) => a+=i
msgbox lst.fold(5, fnc)
Code: Select all
lst := [20,30,10]
msgbox lst.fold(5, ((a,i) => a+=i))
Am I violating a syntax rule by putting the lambda in the fold call directly?
EDIT: msgbox lst.fold(5, (fnc(a,i) => a+=i)) works too...