Diagnostics
T435
lambda cannot change its element copy
T435
A lambda parameter is a copy of each element, so a mutating call on it changes data that is thrown away after that element. Use an indexed for loop and write the result back. Changes to a series or collection held inside the element reach the shared object and are allowed.
Failing example
script "conf"
type Zone {
lo: float
hi: float
fn bump() -> float {
self.hi += 1.0
return self.hi
}
}
data chart = subscribe(data.ohlcv)
state zones: Zone[] = Zone[](4)
on chart.update {
let tops = zones.map(|z| z.bump())
}Corrected example
script "fixed"
type Zone {
lo: float
hi: float
fn bump() -> float {
self.hi += 1.0
return self.hi
}
}
data chart = subscribe(data.ohlcv)
state zones: Zone[] = Zone[](4)
on chart.update {
for i, z in zones {
let zone = z
let top = zone.bump()
zones[i] = zone
}
}