[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Short function definition syntax; thoughts on Lua (was Re: [ANN] GSL Shell new beta release...)
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Sun, 6 Dec 2009 03:58:53 +0100
2009/12/5 spir <denis.spir@free.fr>:
> Can we consider simply wrapping the whole expression inside (...)?
> function (x,y,z) (x+y*z)
>
> This avoids the need for both '=' and an 'end' token.
> (I guess "function(...)(...)..." is well a syntax error as of now?)
This is not a syntax error. The following compiles well:
local f = function(...)(...)(...) end
and can even be run (try f(print)).
On the other hand, I don't think any valid expression or statement can
start with a single square bracket. I'm not sure how to declare the
parameter names, but here are some examples with an infix keyword
('with'):
local f = [x + y with x, y]
assert([x + y with x, y](3, 4) == 7)
local t3 = map([x + y with x, y], t1, t2)
foreach(t, [x + y with x, y])
A close form could already be implemented, without upvalues though:
local f = y[[ x + y with x, y ]]
One could imagine having the parameter naming be optionnal, and use
for example $1, $2, etc. as default names:
assert([$1 + $2](3, 4) == 7)
But I'm still not convinced adding such a short function form is a good idea.