lua-users home
lua-l archive

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


As long as 'a' doesn't have significant 'nil' elements, the following will work:

function apply(f, a) return f(unpack(a)) end

Of course, it would be easier to just use unpack() in the calling code.

If 'a' does have significant 'nil' elements, then you have to supply explicit limits (5.1 only):

  unpack(a, 1, 7) ==> a[1], ..., a[7]

On 17-Dec-06, at 10:45 AM, Thomas Hafner wrote:

Hello,

is there some function which behaves according to the following
signature and semantics description?

function apply(f, a) {
-- f is a function. a is an array. Depending on the dimension of a,
-- apply shall return
--   f() -- for dimension == 0 (empty array) resp.
--   f(a[1]) -- for dimension == 1 resp.
--   f(a[1], a[2]) -- for dimension == 2 resp.
--   f(a[1], a[2], a[3]) -- for dimension == 3 resp.
--   ...
}

Regards
  Thomas