lua-users home
lua-l archive

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

On Mon, Apr 22, 2013 at 3:47 AM, Coda Highland <> wrote:
I'd rather do it in the language instead of in script, because you may
still care about the difference between nil and not having passed a
parameter at all.

Well, you can always switch to a different dialect ;)  (I've used the 'puzzlement command' ?que to dump out the actual generated Lua)

$ mooni
MoonScript version 0.2.3
Note: use backslash at line end to start a block
> f = (x,y=2) -> print x,y
> ?que
f = function(x, y)
  if y == nil then
    y = 2
  return print(x, y)
> f 10
10      2

Moonscript has become the happy home of many language proposals from lua-l, but this is not a criticism of Lua's minimalism, which generally is a good thing (I only miss short-function forms really)

Although (more seriously) is that important to have this sugar?  Surely it is a documentation issue?  E.g. LDoc supports this style of annotation:

-- A useful function
-- @int x  first!
-- @int [opt=2]  second!
function f (x,y)
   if y == nil then y = 2 end

steve d.