[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: first class ':'
- From: David Manura <dm.lua@...>
- Date: Mon, 14 Sep 2009 20:45:19 -0400
On Mon, Sep 14, 2009 at 5:00 PM, wrote:
> A proposal for Lua 5.2: Make ':' an operator which creates a function
> with a bound first parameter.
We should decide how stack level behaves under this proposal. Consider:
local o = {}
function o:test()
return debug.getinfo(1, 'f').func, debug.getinfo(2, 'f').func,
debug.getinfo(3, 'f').func
end
-- [1]
local a,b = o.test(o)
assert(a == o.test)
assert(b == debug.getinfo(1,'f').func)
-- [2]
local a,b = o:test()
assert(a == o.test)
assert(b == debug.getinfo(1,'f').func)
-- [3]
local a,b,c = (function(...) return o.test(o, ...) end)()
assert(a == o.test)
assert(b == nil) -- tail call in anonymous function
assert(c == debug.getinfo(1,'f').func)
print 'done' -- passes under Lua 5.1
In Lua 5.1, [1] and [2] execute at the same stack level, but [3]
executes at a deeper stack level.
To preserve the equivalence of [1] and [2] under the proposal, we
would need to make [2] like [3] but not introduce a new stack level.
Currently, Lua lacks a documented way to express that type of currying
operation.