[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to clone a table in LJ2-friendly way?
- From: Geoff Leyland <geoff_leyland@...>
- Date: Thu, 1 Sep 2011 10:22:09 +1200
On 31/08/2011, at 5:49 PM, Alexander Gladysh wrote:
> As I understand it, traces are picked at random. A single call of a()
> would not prove a thing.
So with the following code, as far as I can tell, there's a trace that starts in the last third of a(), returns to b(), and then calls a() again and continues (through another trace) to just before the pairs.
That's not what I expected, but it seems pretty clever.
Cheers,
Geoff
local function a()
local t = {}
for i = 1, 1000 do
t[i] = i
end
-- ...and ends here
local s = 0
for _, v in pairs(t) do
s = s + v
end
-- trace starts here...
for _, v in ipairs(t) do
s = s + v
end
return s
-- heads back into b
end
local function b()
local s = 0
for j = 1,1000 do
s = s + a()
end
return s
end
print(b())
- References:
- How to clone a table in LJ2-friendly way?, Alexander Gladysh
- Re: How to clone a table in LJ2-friendly way?, Dimiter "malkia" Stanev
- Re: How to clone a table in LJ2-friendly way?, Dimiter "malkia" Stanev
- Re: How to clone a table in LJ2-friendly way?, Alexander Gladysh
- Re: How to clone a table in LJ2-friendly way?, Dimiter "malkia" Stanev
- Re: How to clone a table in LJ2-friendly way?, Dimiter "malkia" Stanev
- Re: How to clone a table in LJ2-friendly way?, Alexander Gladysh
- Re: How to clone a table in LJ2-friendly way?, Dimiter "malkia" Stanev
- Re: How to clone a table in LJ2-friendly way?, Alexander Gladysh
- Re: How to clone a table in LJ2-friendly way?, Dimiter "malkia" Stanev
- Re: How to clone a table in LJ2-friendly way?, Alexander Gladysh
- Re: How to clone a table in LJ2-friendly way?, Geoff Leyland
- Re: How to clone a table in LJ2-friendly way?, Alexander Gladysh