lua-users home
lua-l archive

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

On Nov 26, 2010, at 2:49 PM, Doug Lua wrote:

> If the form is to be limited to an expression, I think LHF's syntax is the best I've seen so far - even with the '\' being in two different places on two keyboards in my house!
>  \x,y,z(x*y+z)    --> function(x,y,z) return x*y+z end
> It's concise and seems to have the fewest (zero?) ambiguities.

My issues with this syntax:

1. It looks weird if I like to use a little more whitespace:

	\ x, y, z ( x * y + z )

Something about the form makes it want to clench more tightly than other forms.

2. It inverts the meaning of () with respect to multiple value return. In particular, if we call a function within the lambda and only want one result, we need to write:


With the parentheses meaning from the outside in: results, single value, call.

Without multiple returns from short functions, the following would work:

	\( x, y, z ) => x * y + z

If one wanted multiple returns, then one could abuse square brackets:

	\( x, y, z ) => [ x * y + z, x + y * z ]

And for those who like things tighter, the parentheses around the arguments don't actually make the form more readily parsable though they do make it look more like a function declaration (and resolve my whitespace issues).

If one insists on support for statements, then there is the option to support:

	\( x, y, z ) do
		local a = random()
		=> x * a + y * z

But then win here over traditional syntax seems small and we probably need examples of why statement support is worth it.