I'm not quite sure how variable scope works in Io. The docs say it has closures, but I don't seem to be able to see idx
from within the next
and prev
methods. Parent visibility is the key premise of closures, so how can they work?
List iterator := method(
idx := 0
itr := Object clone
itr next := method(
idx = idx + 1
return self at(idx)
)
itr prev := method(
idx = idx - 1
return self at(idx)
)
return itr
)
How should this be achieved?