You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Num {
value: Int
}
local numbers: List<Num> = IntSeq(0, 100000).map((i) ->newNum { value = i })
localadder = (numA: Num, numB: Num) ->newNum { value = numA.value + numB.value }
sum = numbers.reduce(adder).value
At the end of each iteration, the returned value from adder retains a lazy value. The resulting object, as a result, has a value member that recurses.
This type of code is less performant, and is also vulnerable to stack overflow exceptions. It's also very hard to understand why this is recursive. We should have some way to avoid deep call stacks here.
Note: a workaround is to force the computation with a let expression, e.g.
localadder = (numA: Num, numB: Num) ->let (result = numA.value + numB.value)
newNum { value = result }
The text was updated successfully, but these errors were encountered:
This code will stack overflow:
At the end of each iteration, the returned value from
adder
retains a lazyvalue
. The resulting object, as a result, has avalue
member that recurses.This type of code is less performant, and is also vulnerable to stack overflow exceptions. It's also very hard to understand why this is recursive. We should have some way to avoid deep call stacks here.
Note: a workaround is to force the computation with a
let
expression, e.g.The text was updated successfully, but these errors were encountered: