lua-users home
lua-l archive

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


steve donovan wrote:
Can be a little suprising if the function takes multiple values ;)

map(print,10,20,30)
10 20 30 20 30 30

Yes, but the function choice are the programmer's :)

If we want to make it "idiot-proof" (to safeguard against ourselves :) ), we can add an extra pair of parentheses:

  function map(func, ...)
    if select("#", ...) > 0 then
      return func((...)), map(func, select(2,...))
    end
  end
--
Shmuel