CSC/ECE 517 Summer 2008/wiki1 2 itr: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
== Introduction ==
== Introduction ==
One of the beloved feature of '''[http://www.ruby-lang.org/en/ Ruby]''' is the block based '''[http://en.wikipedia.org/wiki/Iterator Iterator]'''. A Ruby Iterator is simply a method that somehow loops over the contents of an object without exposing its underlying representation.  
One of the beloved feature of '''[http://www.ruby-lang.org/en/ Ruby]''' is the block based '''[http://en.wikipedia.org/wiki/Iterator 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. '''[http://en.wikipedia.org/wiki/Generator_%28computer_science%29 Generators]''' are a similar feature in '''[http://www.python.org/ 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.
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 ''[http://www.faqs.org/docs/learnc/x658.html 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. '''[http://en.wikipedia.org/wiki/Generator_%28computer_science%29 Generators]''' are a similar feature in '''[http://www.python.org/ 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===
===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.
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.


== Iterator ==
The word "iterator" means different things in different contexts and programming languages, but it's always got something to do with visiting each one of a set of objects, where "object" doesn't necessarily mean "class instance": Just take "object" to mean "some instance of some data type, somewhere". Iterators may provide additional features or behaves in a different way depending on the languages.
== Numbering ==
== Numbering ==
# A
# A

Revision as of 14:49, 30 May 2008

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.

Iterator

The word "iterator" means different things in different contexts and programming languages, but it's always got something to do with visiting each one of a set of objects, where "object" doesn't necessarily mean "class instance": Just take "object" to mean "some instance of some data type, somewhere". Iterators may provide additional features or behaves in a different way depending on the languages.

Numbering

  1. A
    1. a
  2. B
    1. b

Bullets

  • A
    • a
  • B
    • b

Subsubsection

Webmail [1]