[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Default value in function parameters?
- From: "Grellier, Thierry" <t-grellier@...>
- Date: Tue, 19 Sep 2006 15:56:34 +0200
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
my_default_c)
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
my_default_c)
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-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of mitchell
Sent: Tuesday, September 19, 2006 2:30 PM
To: lua@bazar2.conectiva.com.br
Subject: Re: Default value in function parameters?
Hi,
> 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
f(false)
-Mitchell;