lua-users home
lua-l archive

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

Yes, you are right !
At least this shows that using default values is currently not so easy.
Then the issue is not to provide a syntax sugar but to reuse "or" token
to implement it. Maybe "else' is a better choice.

function f(a else my_default_a, b else my_default_b, c else
to be expanded to
function f(a, b, c)
a = a or (a == nil and my_default_a)
b = b or (b == nil and my_default_b)
c = c or (c == nil and my_default_c)

There is also the possibility to introduce a new default keyword (gasp).
function f(a default my_default_a, b default my_default_b, c default
This could have at least the advantage to make call safer:
f(false, default, 3)
with default expanded to nil in this case

I hope that people are not used to name variables with so poor name, so
that it doesn't break many programs...

-----Original Message-----
[] On Behalf Of mitchell
Sent: Tuesday, September 19, 2006 2:30 PM
Subject: Re: Default value in function parameters?

> function f(a or my_default_a, b or my_default_b, c or my_default_c)
> end

What about passing false intentionally?

function f(flag or true) ... end