Open avik-pal opened 1 week ago
Could this work?
struct LoopInitializer end
let
my_dx = LoopInitializer()
if @isdefined dx
my_dx = dx
end
args = (0, my_dx)
cond_fn = (i, my_dx)->begin
local num_iters = 9
i < num_iters + 1
end
body_fn = (i, my_dx)->begin
local step_ = 1
local start_ = 1
begin
dx = 1
end
if !(my_dx isa LoopInitializer)
my_dx = dx
end
(i + 1, my_dx)
end
cond_fn(args...), body_fn(args...)
end
The check at the end of body_fn
should always be optimized away, I believe.
If there's no obvious problems with this approach I can try add it to the macro, unless someone else would like to?
dx
is not necessarily defined outside the forloop