Originally created by @bioball on GitHub (Feb 21, 2025).
This code will stack overflow:
class Num {
value: Int
}
local numbers: List<Num> = IntSeq(0, 100000).map((i) -> new Num { value = i })
local adder = (numA: Num, numB: Num) -> new Num { 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.
local adder = (numA: Num, numB: Num) ->
let (result = numA.value + numB.value)
new Num { value = result }
Originally created by @bioball on GitHub (Feb 21, 2025).
This code will stack overflow:
```pkl
class Num {
value: Int
}
local numbers: List<Num> = IntSeq(0, 100000).map((i) -> new Num { value = i })
local adder = (numA: Num, numB: Num) -> new Num { 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.
```pkl
local adder = (numA: Num, numB: Num) ->
let (result = numA.value + numB.value)
new Num { value = result }
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @bioball on GitHub (Feb 21, 2025).
This code will stack overflow:
At the end of each iteration, the returned value from
adderretains a lazyvalue. The resulting object, as a result, has avaluemember 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
letexpression, e.g.