[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntax sugar for default arguments
- From: Coda Highland <chighland@...>
- Date: Sun, 21 Apr 2013 18:47:48 -0700
On Sun, Apr 21, 2013 at 6:31 PM, Tim Hill <drtimhill@gmail.com> wrote:
> Why can't you just use a wrapper function? Trivial to do, and doesn't need any patching:
>
> function g(x, y)
> f(x, y or 0)
> end
>
> And of course, it's easy to wrap transparently:
>
> do
> local fo = f
> function f(x, y)
> fo(x, y or 0)
> end
> end
>
> --Tim
>
> On Apr 20, 2013, at 11:41 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>
>> function f(x,y=0)
>> function f(x,y or 0)
>>
>> to mean
>>
>> function f(x,y) y=y or 0
>>
>> Neither would break existing code.
>>
>> Which of the above should I choose to implement as a patch?
>>
>
>
I'd rather do it in the language instead of in script, because you may
still care about the difference between nil and not having passed a
parameter at all.
/s/ Adam