lua-users home
lua-l archive

Building recursive argument lists in a shorter way?

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


I have many setter methods that handle properties that represent an
inventory of one or more objects of the same class (to borrow from
OOP).
So that I don't need to write a "set_prop" and "set_props" function, I
write this quite a bit:
local function f(arg, ...)
 if (...) then
 return arg, f(...)
 else
 return arg
 end
end
A more compact variant doesn't work:
local function f2(arg, ...)
 return arg, (...) and f2(...)
end
...for more than two recursions.
It's not a big deal, at all, but if there was some way to get closer
to the second example, and still have it work for n arguments, I'd
like to know it.
:)
-Andrew

AltStyle によって変換されたページ (->オリジナル) /