lua-users home
lua-l archive

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


>  for kk, vv in pairs(tt) do
>   for k, v in pairs(t) do
>     if condition1 then break end    -- same as `break :k:`
>     if condition2 then break :continue: end
>     if condition3 then break :redo: end
>     if condition4 then break :kk: end
>   end
>  end

One thing that stood out to me here is that :redo: can't be expected
to work as advertised for stateful iterators, in the general case.
With __pairs metamethods, for example, this would apply even in the
above example. Does Perl have such gotchas?

The best workaround I can think of is consulting a weak table for a
redo handler, using the iterator function as key, and calling that if
available. But this is a bit of effort for something that looks like
it should just work. (And even then, rewinding a coroutine-based
iterator is non-trivial...)

An alternative workaround, of course, is "don't mix stateful iterators
and :redo:". :) Anyhow, food for thought.