Generator (computer programming): Difference between revisions

Content deleted Content added
Arto B (talk | contribs)
Added references to Scheme generators.
tone down scheme focus a bit, introduce new-style references
Line 33:
In Python, a generator can be thought of as an iterator that contains a frozen [[stack frame]]. Whenever the iterator's <code>next()</code> method is called, Python resumes the frozen frame, which executes normally until the next <code>yield</code> statement is reached. The generator's frame is then frozen again, and the yielded value is returned to the caller.
 
Generators can be implemented in terms of more expressive [[control flow]] constructs, such as [[coroutine]]s or first-class [[continuation]]s.<ref>{{cite web
In programming languages that support current [[continuation]] capture and resumption, it may be possible to implement generators even if the language itself does not directly provide them. For instance, implementing generators in [[Scheme]] is a [http://xmog.com/scrap/show/5 simple metaprogramming exercise], since the language provides both [[Continuation|call/cc]] and a powerful [[macros]] facility.
| last = Kiselyov
| first = Oleg
| month = January
| year = 2004
| title = General ways to traverse collections in Scheme
**| url = [http://okmij.org/ftp/Scheme/enumerators-callcc.html General ways to traverse collections in Scheme] by Oleg Kiselyov
}}</ref>
 
==See also==
Line 45 ⟶ 52:
 
==References==
 
<references/>
 
* Stephan Murer, [[Steve Omohundro | Stephen Omohundro]], David Stoutamire and Clemens Szyperski: Iteration abstraction in Sather. ''ACM Transactions on Programming Languages and Systems'', 18(1):1-15 (1996) [http://portal.acm.org/citation.cfm?doid=225540.225541]
Line 51 ⟶ 60:
** [http://python.org/peps/pep-0289.html PEP 289: ''Generator Expressions'']
** [http://www.python.org/peps/pep-0342.html PEP 342: ''Coroutines via Enhanced Generators'']
* Generators in [[Scheme]]:
** [http://xmog.com/scrap/show/5 Why Java (and almost every other programming language) sucks] by Ed Watkeys
** [http://wmfarr.blogspot.com/2006/08/one-more-example-of-python-generators.html One more example of Python generators in Scheme] by Will Farr
** [http://okmij.org/ftp/Scheme/enumerators-callcc.html General ways to traverse collections in Scheme] by Oleg Kiselyov
** [http://okmij.org/ftp/Computation/Continuations.html#enumerator-stream Towards the best collection traversal interface] by Oleg Kiselyov
** [http://schemecookbook.org/view/Cookbook/IteratorGenerators Schematics Cookbook: Generating Iterators]
** [http://hkn.eecs.berkeley.edu/~dyoo/plt/generator/ Python/Ruby style generators for PLT Scheme]
 
[[Category:Programming constructs]]