lua-users home
lua-l archive

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


On Sat, Dec 5, 2009 at 12:30 PM, Bulat Ziganshin
<bulat.ziganshin@gmail.com> > numbers .filter odd .map (^2)
>
> looks much better and easier to understand

Most of us like to read from left to right, as a chain of operations.
Functional people have a larger stack than most, so they're used to
everything being prefix ;)

In a more Lua-ish form:

numbers:filter(odd):map(square)

To do this without little functions like odd and square is awkward:

numbers:filter(function(n) return math.mod(n,2)==1
end):map(function(x) return x*x end)

Wow! OK,

numbers:filter(|n|math.mod(n,2)==1):map(|x| x*x)

That's basically the argument for the short form ;)

Sometimes in this discussion the word 'convenience' has been used as
if it could be a bad thing, as if it would lead to some kind of moral
degeneracy.  Also, there is an assumption that the aim is to make Lua
look like Haskell or Lua. Well, I don't use these languages, I just
like the functional style when it is _appropriate_ and the short form
makes it more pleasant.

steve d.