[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntax sugar for default arguments
- From: Enrico Colombini <erix@...>
- Date: Sun, 21 Apr 2013 22:21:09 +0200
By the way... having a default argument for a boolean:
function Show(show=true)
-- ...
end
Show(nil) --> Show(true) -- use default
Show(true) --> Show(true) -- arg not nil, use arg
Show(false) --> Show(false) -- arg not nil, use arg
should behave differently from simply using 'or' on the argument:
function Show(show)
show = show or true -- (not a good idea!)
-- ...
end
Show(nil) --> Show(true) -- use default
Show(true) --> Show(true) -- arg not nil/false, use arg
Show(false) --> Show(true) -- unintentionally use default (oops)
--
Enrico