[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Default parameter values
- From: Paige DePol <lual@...>
- Date: Thu, 30 Nov 2017 19:10:00 -0600
Egor Skriptunoff <email@example.com> wrote:
> On Thu, Nov 30, 2017 at 2:37 PM, Dirk Laurie wrote:
>> Does a patch that allows the clumsy idiom
>> a = a or 0
>> c = c or 1
>> to be replaced by
>> already exist?
> At what moment of time those "default expressions" would be evaluated?
> At the moment of definition or at the moment of function invocation?
> function pretty_print_time(unix_time=os.time())
> Are they allowed to refer to each other?
> function string.byte(str, from_pos=1, to_pos=from_pos)
I would have to say at invocation if the values are allowed to be
expressions rather than constant values.
So, essentially function(a=expr1, b, c=expr1) would just become
syntactic sugar for the following:
function(a, b, c)
a = a or expr1
c = c or expr2
This might be difficult to do with the standard Lua parser as there is
no real way to defer the expressions declared in the function parameter
declaration. However, with my patch that adds the ability to store tokens
for playback later this would be a trivial patch to implement. Including
the ability for later parameters to use earlier parameters as defaults.