in reply to Re^2: An iterator for (not "iterating") a recursive data structure.
in thread An iterator for (not "iterating") a recursive data structure.

Should be noted that the initial problem of the OP (short-circuiting a call-back) is easily solved with goto

Not if you wish to have the option of resuming the iteration; which I do. (Admittedly this was not mentioned in the OP.)

In addition, this suffers from all the same problems as throwing an exception to effect the early exit, which is (ab)using the exception mechanism for flow control.

Another reason for wanting an iterator is the ability to have multiple, concurrent, independent iterators; which is key to my application.

Last but not least is the avoidance of the nightmare that is Inversion of Control.

Think about how you'd have to restructure so many of your programs -- and how hard, if not impossible that would be -- if Perl's hashes only provided callback iterators. What a mess!


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
  • Comment on Re^3: An iterator for (not "iterating") a recursive data structure.

Replies are listed 'Best First'.
Re^4: An iterator for (not "iterating") a recursive data structure. (callbacks--)
by tye (Sage) on Feb 13, 2015 at 19:50 UTC

    Amen! Nicely said.

    - tye        

Re^4: An iterator for (not "iterating") a recursive data structure.
by LanX (Saint) on Jul 08, 2019 at 18:17 UTC
    > Not if you wish to have the option of resuming the iteration;

    That's why I said

    > > Thats why Perl6 introduces gather/take and Python has "generators" with yield constructs.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice