• Subject: Re: Lightweight function syntax (again) Re: [ANN] Lua 5.2.0 (alpha-rc2) now available
• From: Nilson <nilson.brazil@...>
• Date: Sun, 21 Nov 2010 22:10:06 -0200

```On Sun, Nov 21, 2010 at 7:27 PM, Lorenzo Donati
<lorenzodonatibz@interfree.it> wrote:
> my 2 cent:
>
> function(x,y,z)
>  dostuff(x,y,z);
>  return x+y, x+z
> end
>
> should be translated to:
>
> @(x,y,z)
>  dostuff(x,y,z);
> @[x+y, x+z]
>
> Pretty compact written on one line, but still readable:
>
> @(x,y,z) dostuff(x,y,z); @[x+y, x+z]
>
> Only 1 new symbol (@) and two new tokens @( and @[
>
> @( will mark the beginning of a parameter list;
> @[ the beginning of a multiple return
>
> cheers
>

And what about the following syntax?

Multiple return
@(a,b) (a+b,c)  <=>  function (a,b) return a+b, c end

Single return
@(a,b) a+b <=> function (a,b) return a+b end
or
@(a,b) (a+b) <=> function (a,b) return (a+b) end

Do statement  - allows complex statements
@(a,b) do ..... end

Only statements initiated by a reserved word
@(a,b) if,while
Seem to be less orthogonal.

Any single statement (harder to compile)
@(a,b) print(a+b) <=> function (a,b) print(a+b) end

With syntactic sugar (???)
@ name (a,b) a + b <=> "name = function(a,b) return a+b end"
In this case the token is the @ , not the @(

Cheers,
Nilson

```

• Follow-Ups: