lua-users home
lua-l archive

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


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