lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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())