lua-users home
lua-l archive

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


Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require 'metalua.base'
> require 'metalua.table2'

or simply << require 'metalua.runtime' >>

> d(table.imap(function(s1,s2) return s1..s2 end,{'a','b'},{'1','2'}))
{ "a1", "b2" }

It's useful for users of the library to be able to give a fallback for
what 'callable' means. E.g. in Penlight, the string '..' standards for
the concatenation function above.

Such fallback are exceptions to normal rules, and a large part of Lua's appeal come from its regularity, i.e. lack of such exceptions to the (few) normal rules. The ultimate result of accumulating exceptions to rules in language design is Perl; you can like Perl, but it's hard to imagine a more un-lua-ish scripting language.

Besides, the verbosity issue you're trying to address isn't so bad in metalua, since you can at least use :

<< table.imap (|x,y| x..y, {'a', 'b'}, {'1', '2'}) >>

Moreover, the value/ivalue iterators should be made of variable arity, thus allowing: 

<< { x..y for x, y in values({'a', 'b'}, {'1, 2'})} >> (it requires to load an extension, though)

Although my background is rather functional, I agree with GvR that *in an imperative language*, list comprehensions are more idiomatic and clearer than functors (lists by comprehension vs. functors is one of Python's favorite trolls; GvR's famous dislike of lambda is mostly a corollary of this issue).