lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


ET wrote:

> Roberto Ierusalimschy wrote:
> >
> > Simply like this:
> >
> >   for k, v in tab do
> >     local v = v
> >     actors[k] = function (x) act_on(v, x) end
> >   end

> Just a question: would the line "local v=v" be necessary or would
> you only get a different semantic without it?  (Without it, all v's
> in the function are the same var, with the local line each function
> gets it's own v.)

Yes, that's my interpretation. But the "different semantic" is quite
different, don't you think?

I think this means I have to go through a bunch of my code, adding
local x=x
wherever I find %x.

I actually quite liked the fact that Lua does functional (in the
functional programming sense) closures. I'll miss it -- but I guess
I'm in the minority.

> PS: I'm really curious on how you implement these new scoping
> rules without loosing performance.

Me, too.