lua-users home
lua-l archive

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


I see that and how it's different. 

It's the same syntax, and you're suggesting that it be added to the existing function declarations.

I'm suggesting that there is a language symmetry (and simplicity) to be gained by limiting the addition to only named arguments:

myfunc{my_arg = "hello"}

and 

local myfunc = function{my_arg = "howdy", arg2 = "good bye"}
  ---do stuff
end

..just seems like it should be true.

Perhaps it's simpler to apply to every function declaration, as you're suggesting. I think it may be the exact same syntax, other than that.


On Thu, Apr 25, 2013 at 10:46 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
2013/4/25 Andrew Starks <andrew.starks@trms.com>:

> a = function(arg1 = 3, arg2 = {"first value", x = d, } or old_value or
> error("arg2 is required"))

Just to clarify: my original intention was not to provide keyword arguments,
but to provide compile-time default values. For example:

function claim(condition,message="Warning",log=io.stderr)
   if not condition then log:write(where(2),message,'\n') end
end

which might be called as

claim(x>0)
claim(x>0,"This will only work if x>0")
claim(x>0,nil,mylogfile)
claim(nil,"Header for default error log")

And I have by now got an answer: people prefer `=` over `or`.