FACTOID # 127: Costa Rica leads the world in per capita exports of bananas, cassava, melons, and pineapples to the United States. Unsuprisingly, they’re also first in pesticide use.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

FACTS & STATISTICS    Simple view

  1. Select countries to view: (hold down Control key and click to select several)

     

     

    Compare:

     

     

  1. Select fact or statistic: (* = graphable)

     

     

     

  2. (OPTIONAL) Compare to statistic: (both need to be graphable)

     

     

     

  3. View result as:

     

       
(OR) SEARCH ALL encyclopedia, stats & forums:   

Encyclopedia > Generator (computer science)

In computer science, a generator is a special routine that can be used to control the iteration behaviour of a loop. The concept was invented for the Sather programming language but it has also been incorporated in the Python programming language. Wikibooks Wikiversity has more about this subject: School of Computer Science Open Directory Project: Computer Science Collection of Computer Science Bibliographies Belief that title science in computer science is inappropriate Categories: Computer science ... Sather is an object-oriented programming language. ... Python is an interpreted, interactive programming language created by Guido van Rossum in 1990. ...


Generators can only be invoked inside loops. The first time that a generator invocation is reached in a loop, an iterator object is created that encapsulates the state of the generator routine at its beginning, with arguments bound to the corresponding parameters. The generator's body is then executed in the context of that iterator until a special yield action is encountered; at that time, the value provided with the yield action is used as the value of the invocation expression. The next time the same generator invocation is reached in a subsequent iteration, the execution of the generator's body is resumed after the yield action, until a yet another yield action is encountered. In addition to the yield action, execution of the generator body can also be terminated by a finish action, at which time the innermost loop enclosing the generator invocation is terminated.


In the presence of generators, loop constructs of a language can be reduced into a single loop ... end loop construct; all the usual loop constructs can then be comfortably simulated by using suitable generators in the right way.


In the Python programming language, a generator is a special type of continuation that can be used as an iterator. Python is an interpreted, interactive programming language created by Guido van Rossum in 1990. ... In computing, a continuation is a way to represent the execution state (i. ... In object-oriented programming, an iterator is an object allowing one to sequence through all of the elements or parts contained in some other object, typically a container or list. ...


An example Python generator:

 def sums(n, min=1): if n == 0: yield [] elif n >= min: for i in range(min, n+1): for sol in sums(n-min, i): yield [i] + sol 

In Python, a generator can be thought of as an iterator that contains a frozen function call. Whenever the iterator's next() method is called, the frozen function call resumes where it was left off and runs until it reaches a yield statement. Then the function call is frozen again, the iterator spits out the yielded value, and execution continues with the iterator's caller.


Generators can be used to loop through the values of a list lazily. This is useful when only the first few items of the list are likely to be needed, and calculating the entire list would be costly or impractical.


References

  • Stephan Murer, Stephen Omohundro, David Stoutamire and Clemens Szyperski: Iteration abstraction in Sather. ACM Transactions on Programming Languages and Systems, 18(1):1-15 (1996) [1]
  • PEP255 Simple Generators
Stephen Omohundro has had a wide-ranging career as a scientist, university professor, author, software architect, and entrepreneur. ...

  Results from FactBites:
 
generator - Search Results - MSN Encarta (221 words)
Report Generator, in computer science, a type of application, commonly part of a database management program, that uses a report “form” created by...
Generator may refer to: * Electrical generator * Generator (song), a song by The Foo Fighters * Generator (album), an album by punk band Bad Religion, and its opening track * Generator (band), a band...
An electrical generator is a device that moves electrical energy from a mechanical energy source using electromagnetic induction.
  More results at FactBites »


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.