[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (alpha-rc2) now available
- From: Nilson <nilson.brazil@...>
- Date: Sat, 20 Nov 2010 14:06:14 -0200
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