[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Syntax sugar for default arguments
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sun, 21 Apr 2013 19:45:46 +0200
2013/4/21 Steve Litt <firstname.lastname@example.org>:
> By the way, are you going to let the other shoe drop and do the same
> thing in the subroutine *call*?
> function f(x=3, y=4)
> f(y=7) -- no need to articulate x
This is immeasurably harder. The other one is mere syntax sugar, a trivial
modification to the source string before passing it along.
This requires code to examine run-time debugging information. At compile
time it is not known which function object is currently associated with the
name f. Therefore it is not known which parameter of f was called y when
the function was defined. One will have to generate code that repeatedly
calls debug.getlocal and works through all the local variables one by one.
All this, for a simple function call.
What will be easier is default values for entries in keyword-style
This will translate to the equivalent of:
for k,v in pairs(default[f]) do f[k]=f[k] or v end