lua-users home
lua-l archive

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


Veli-Pekka Tätilä writes:

> Does anyone use short anonymous functions with Lua ports of higher-order 
> stuff like map, grep (filter), reduce, zip and the rest of the lot?

There's some things like that in these places:

  http://luaforge.net/projects/stdlib/
  http://metalua.luaforge.net/manual005.html#toc11
  http://lua-users.org/wiki/SplitJoin

> The problem to me is the syntax. A map doing nothing looks lie:
> map(function(e) return e end, list)
> Quite a lot of typing...compared to just (Perl):
> map $_, @list;

This is discussed in

  http://lua-users.org/wiki/ShortAnonymousFunctions

For example, to double the numbers in a list you could write

  list2 = map(fn'P1 * 2', list)    -- or
  list2 = map([[P1 * 2]], list)