lua-users home
lua-l archive

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


On 17/04/2012 00:37, Vox Timothy wrote:
- New Keyword: funct (like function, but with automatic return; would
require an explicit nil if void)

A good idea in languages returning only one value and with a terse notation for functions, much less useful in Lua which is intendedly "verbose", and which can return several values at once.

Honestly, when I started to code in Scala, I was perplex with this "return is allowed but should be omitted" rule, for stuff like:

def vararg(arrayOfParams: Int*): Int =
{
  var result = 0
  for (arg <- arrayOfParams) result += arg * arg
  result
}

Here, this notation even looks clumsy.
It is more useful when you define anonymous functions like:

someList.filterNot(s => s.length >= 4)

(eliminating string elements of length above 3) but we don't have that in Lua.

- if, while, etc. could also automatically return (be expressions
instead of statements; in case of loop, last iteration)

Idem. What works well in one language cannot work, or in clumsy ways, for another. That's also why we don't have += and even less ++

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  http://PhiLho.deviantART.com
--  --  --  --  --  --  --  --  --  --  --  --  --  --