lua-users home
lua-l archive

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


On Sat, Dec 19, 2009 at 12:28 PM, Fabien <fleutot+lua@gmail.com> wrote:
>> 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.

Amem to that, brother (to quote Larry Wall)

If I could assume that |x,y| x..y was universal, then we would not
need such fallbacks.  Unfortunately, short anonymous function syntax
is a no-starter for vanilla Lua precisely for the reasons you give.

We all agree that map() is an important function which needs to be in
the standard toolkit. But the verbosity of anonymous functions where
the payload is a simple operation makes it less appealing, to the
point when people might quite reasonably say: why not write out the
loop explicitly?

So I'm trying to get a backdoor endorsed, which allows the
application/framework developer to extend the meaning of callable as
used for functions like map() and filter().  E.g. Penlight allows
placeholder expressions to be used as callables:

http://penlight.luaforge.net/#T34

> tablex.map2(_1+_2,{1,2,3},{10,20,30})
{11,22,33}

But placeholder expressions are not perfect (_1 or _2 would not work,
neither would _1 > 0, due to metamethod limitations), involve run-time
compilation and they are a bitch to memoize.

If we get a agreed-upon, standard token-filter mechanism for vanilla
Lua, then of course it would be easy to implement lhf's suggested
lambda notation \x,y(x+y)  That would make the shortists happy, and
the longists can just avoid the extension.

steve d.