lua-users home
lua-l archive

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


Well,

>
> Considering the later example, a function definition could be seen as
> a syntactic sugar of
>
> "function (...) end " <=>  "@(...) do .... end"

Another possible syntax is:

  @ OptionalName (a,b) a+b

meaning

  OptionalName  = @ (a,b) a+b

which already means

  OptionalName = function (a,b) return a+b end

-------------------
This allows you to write the following code:

local adt = {}

@adt.add(a,b) a+b
@adt.sub(a,b) a-b
@adt.mul(a,b) a*b
@adt.div(a,b) if b = 0 then error('div') else return a/b end

-------------------


-- 
Nilson