[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Challenge] Smallest table copy
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Fri, 9 May 2014 00:57:31 +0200
On Fri, May 9, 2014 at 12:21 AM, Philipp Janda <siffiejoe@gmx.net> wrote:
> Am 08.05.2014 20:11 schröbte Pierre-Yves Gérardy:
>
>> On Thu, May 8, 2014 at 5:35 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
>>>
>>> Am 08.05.2014 17:24 schröbte Pierre-Yves Gérardy:
>>>>
>>>> L="local a,b,c=..."load(L.."")load(L.."")
>>>> function(a,b,c)endfunction(a,b)end
>>>
>>>
>>>
>>> Yes, and we also rely on upvalues, so we would need the `function`
>>> keyword
>>> in there after all ...
>>> But for a moment it was a good idea.
>>
>>
>> No need for upvalues, a Lua chunck really is a vararg function:
>>
>> add = load"local a,b = ... return a + b"
>> add(1,2) --> 3
>
>
> If you want to use the `type` (or `next`) function in there without passing
> it in every call, then you need them as upvalues. E.g.:
>
> add = load[[
> local t = ...
> return function( a, b )
> if t( a ) == t( b ) then
> return a + b
> end
> end]]( type )
>
> Personally, I usually don't localize all globals in toy programs, but the OP
> seems to care. Better safe than sorry, I guess.
Indeed, I hadn't thought about that in this case (I actually use that
technique in two of my libraries).
—Pierre-Yves
- References:
- [Challenge] Smallest table copy, Thiago L.
- Re: [Challenge] Smallest table copy, Daniel Stephens
- Re: [Challenge] Smallest table copy, Hans Hagen
- Re: [Challenge] Smallest table copy, Thiago L.
- Re: [Challenge] Smallest table copy, Paul K
- Re: [Challenge] Smallest table copy, Daniel Stephens
- Re: [Challenge] Smallest table copy, Thiago L.
- Re: [Challenge] Smallest table copy, Philipp Janda
- Re: [Challenge] Smallest table copy, Pierre-Yves Gérardy
- Re: [Challenge] Smallest table copy, Philipp Janda
- Re: [Challenge] Smallest table copy, Pierre-Yves Gérardy
- Re: [Challenge] Smallest table copy, Philipp Janda