CSC/ECE 517 Summer 2008/wiki1 2 itr
Introduction
One of the beloved feature of Ruby is the block based Iterator. A Ruby Iterator is simply a method that somehow loops over the contents of an object without exposing its underlying representation. The verb `iterate' means "do the same thing many times' so `iterator' means "one which does the same thing many times'. It can also be considered as an object that behaves like a generic pointer. The iterator usually reference to one particular element in the object collection and then modify itself so that it points to the next element. Generators are a similar feature in Python. The name came as it is the entity which generate iterators. It allows you to write a function that can return a result and pause, resuming in the same place the next time you call the function.
Problem Definition
Ruby, like Java, has iterators to facilitate doing operations on each member of a set. Python has generators as well. Describe how generators differ from iterators, and find examples of code sequences using generators that would be awkward with iterators.
Numbering
- A
- a
- B
- b
Bullets
- A
- a
- B
- b