It seems the below does not compile with 1.8.0 and 1.9.0-alpha14, the same errors appear in both versions.
Proposal: Cache exceptions thrown during lazy-seq realization, to avoid re-running bodyfn which is declared as `^:once`
Prescreened by: Alex Miller
OS X EI Capitan, Java HotSpot(TM) 64-Bit Server VM 1.8.0_101-b13
Comment made by: find_my_way
Maybe I should use take-while instead of filter.
However, can anyone explain why I get ArithmeticException while running
for the first time and get the right result at the second time?
The NPE is caused by the interaction between:
lazy-seq throwing an exception while realizing part of the sequence
lazy-seq internally using ^:once for locals clearing
lazy-seq expects the bodyfn to be run exactly once and then the result to be cached, but if an exception gets thrown during the execution of bodyfn, the function will get run again when the sequence tries to be realized a second time. However if locals clearing has already happened (even partially) this means some locals in bodyfn will now be nil rather than holding their actual value.
Attached patch that fixes this issue