[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Features you would like to see
- From: Rob Kendrick <lua-l@...>
- Date: Fri, 17 Aug 2007 08:50:22 +0100
Patrick Donnelly wrote:
I'd like to see some sort of "default" value for function arguments
added. Something along the lines of:
function foo(a or 5)
...
end;
I'm not sure it's worth complicating the compiler for this, given you
can do a = a or 5.
I suspect this could be done reasonably easily using token filters.
Perhaps Daniel or Asko will curry one up for us.
What features would you like to see added?
There isn't a lot that I want that can't be emulated in another way.
For example, something I find quite useful is array slicing:
a = { 1, 2, 3, 4, 5 }
two, three, four = a[2..4]
But this can easily be done with a simple function, such as this naive
example:
function slice(t, s, e)
local r = {}
for i = s, e do
r[#r+1] = t[i]
end
return unpack(r)
end
two, three, four = slice(a, 2, 4)
Or perhaps even:
a.slice = slice
two, three, four = a:slice(2, 4)
B.