~technomancy/fennel#187: 
accumulate accumulator name can clobber iterator binding name

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
Status
RESOLVED CLOSED
Submitter
~rktjmp
Assigned to
No-one
Submitted
1 year, 5 months ago
Updated
1 year, 1 month ago
Labels
No labels applied.

~technomancy 1 year, 5 months ago

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?

~technomancy REPORTED CLOSED 1 year, 1 month ago

I don't think we can fix this but I'm open to revisiting it if anyone has an idea.

Register here or Log in to comment, or comment via email.