[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntax sugar for default arguments
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 25 Apr 2013 17:46:52 +0200
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`.