If the accumulator name given to accumulate
is the same as the binding given to the iterator function, the accumulators initial value is passed to the iterator instead.
Not sure if this is an issue, or an intended quirk allowing you to define the iterator target in accumulates bindings.
Eg given:
(let [x [1 2 3]]
(accumulate [x "" _ v (ipairs x)]
(.. x v)))
We get the lua
local x = {1, 2, 3}
local x0 = ""
for _, v in ipairs(x0) do -- calls ipairs("")
x0 = (x0 .. v)
end
return x0
Instead of (?)
local x = {1, 2, 3}
local x0 = ""
for _, v in ipairs(x) do -- calls ipairs({1,2,3})
x0 = (x0 .. v)
end
return x0
I think if that code compiles, it's reasonable to assume that the accumulator binding would happen first, so it's not surprising that it would shadow the table.
I'd prefer to make it a compile error, but I don't think there's actually a way to detect this in the general case?
I don't think we can fix this but I'm open to revisiting it if anyone has an idea.