[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Another example for syntactically lightweight closures
- From: Jean-Claude Wippler <jcw@...>
- Date: Fri, 8 Feb 2008 23:10:19 +0100
On 8 Feb 2008, at 22:25, Fabien wrote:
Another track you might want to experiment, to get rid of
parentheses around functions-as-params, is Haskell's $ operator.
It's simply a binary __call operator with a very low priority. It
would let you write "table.map(t) (function(x) ... end)" as:
table.map(f) $ function(x)
...
end
The $ operator has a certain elegance and simplicity which I find
not incompatible with the Lua way, actually. [...]
While it does indeed appear to fit in, it's not exactly the same logic
as what Ruby does (and which I think is also useful):
t.sort { |a,b| a > b }
In Ruby, it adds the {...} as hidden special arg *into* the preceding
call. The point being that "t.sort" by itself is also a call to the
sort method (Ruby allows dropping parens when there are no args), so
the {...} is optional here. And it allows for writing "obj.meth(arg)
{...}", all being a single call.
I'm not advocating that Lua be changed to become Ruby, of course -
just adding details which may help a potential implementer find the
best fit for Lua.
So far, I think Miles Bader's proposal comes closest:
t:sort(|a,b|( a > b )) and t:each(|x|{ print x })
My only suggestion with this would to consider allowing the |... to
optionally *follow* the call, i.e.
t:sort() |a,b|( a > b )
or perhaps even
t:sort |a,b|( a > b )
But I'm way out of my league now on whether it is even possible to fit
something along these lines into the syntax.
Let alone convince the right people that all this is worth it :)
To generalize about syntax discussions, my experience is that you
need to actually try a syntax for a couple of weeks before forming a
useful advice about it.
Good point (and thanks for pointing out the problem with "... >
7 :sort ...").
-jcw