[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Map and filter without intermediate tables
- From: Geoff Leyland <geoff_leyland@...>
- Date: Thu, 7 Jun 2012 20:13:18 +1200
On 7/06/2012, at 6:52 PM, Dirk Laurie wrote:
> 2012/6/7 Geoff Leyland <geoff_leyland@fastmail.fm>:
>
>> Is it a dead-end idea, or is it that my implementation [1] is brain dead?
>
> I read the code up to line 34. Five function-valued local variables,
> three of them coded in Lua (not C), had by then been expended to simulate
> (presumably for the sake of compatibility with Lua 5.1) something that
> comes free of charge in Lua 5.2.
>
> So my first suggestion is:
>
> ---
>
> local pairs, ipairs = pairs, ipairs
> if _VERSION~="Lua 5.2" then
> -- put those lines here, changing `local function pairs` to
> -- `pairs = function` etc
> end
>
> ---
>
> and at least under Lua 5.2 you should see some improvement.
5.2 does make a small difference, and it's somewhat positive, but it doesn't make intermediate-free implementations better than ones with intermediate tables.
In the "real" code, pairs takes extra arguments: extended_pairs(table_like_thing, some, context), which it then passes on to the iterator, so I can't use 5.2's pairs anyway.