Generator (computer programming)

In computer science, a generator is a routine that can be used to control the iteration behaviour of a loop. All generators are also iterators. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values. However, instead of building an array containing all the values and returning them all at once, a generator yields the values one at a time, which requires less memory and allows the caller to get started processing the first few values immediately. In short, a generator looks like a function but behaves like an iterator.

Comment
enIn computer science, a generator is a routine that can be used to control the iteration behaviour of a loop. All generators are also iterators. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values. However, instead of building an array containing all the values and returning them all at once, a generator yields the values one at a time, which requires less memory and allows the caller to get started processing the first few values immediately. In short, a generator looks like a function but behaves like an iterator.
Has abstract
enIn computer science, a generator is a routine that can be used to control the iteration behaviour of a loop. All generators are also iterators. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values. However, instead of building an array containing all the values and returning them all at once, a generator yields the values one at a time, which requires less memory and allows the caller to get started processing the first few values immediately. In short, a generator looks like a function but behaves like an iterator. Generators can be implemented in terms of more expressive control flow constructs, such as coroutines or first-class continuations. Generators, also known as semicoroutines, are a special case of (and weaker than) coroutines, in that they always yield control back to the caller (when passing a value back), rather than specifying a coroutine to jump to; see comparison of coroutines with generators.
Hypernym
Routine
Is primary topic of
Generator (computer programming)
Label
enGenerator (computer programming)
Link from a Wikipage to an external page
portal.acm.org/citation.cfm%3Fdoid=225540.225541
metacpan.org/module/Coro
metacpan.org/module/Coro::Generator
wiki.php.net/rfc/generators
www.cs.cmu.edu/Groups/AI/html/cltl/clm/node347.html%23SECTION003400000000000000000
medium.com/concerning-pharo/pharos-hidden-gem-generator-c51ef88aec26
web.archive.org/web/20110723043455/http:/cliki.net/pygen
Link from a Wikipage to another Wikipage
Anonymous pipe
Boilerplate code
C (programming language)
C++11
Category:Articles with example C Sharp code
Category:Articles with example Haskell code
Category:Articles with example Java code
Category:Articles with example Perl code
Category:Articles with example Python (programming language) code
Category:Articles with example Racket code
Category:Articles with example R code
Category:Articles with example Ruby code
Category:Articles with example Tcl code
Category:Iteration in programming
Category:Programming constructs
CLU (programming language)
Common Lisp
Computer science
Concurrency (computer science)
Context switching
Continuation
Control flow
Corecursion
Coroutine
Coroutines
C Sharp (programming language)
ECMAScript
Execution (computers)
Foreach loop
F Sharp (programming language)
F Sharp programming language
Golden ratio
Haskell (programming language)
Icon (programming language)
Iteratee
Iteration
Iterator
Java (programming language)
Java collections framework
Lazy evaluation
List (abstract data type)
List comprehension
Logical disjunction
Non-strict evaluation
Object (computer science)
Parallel computing
Parameter (computer science)
Pharo
PHP
Pthreads
Python (programming language)
Racket (programming language)
Ruby (programming language)
Sather
Sequence expression
Stack frame
Steve Omohundro
Stream (computing)
Subroutine
Tcl
XL (programming language)
SameAs
2QeR1
4129040-9
Generador (informática)
Générateur (informatique)
Generator (computer programming)
Generator (informatica)
Generator (informatika)
Generator (informatyka)
Generátor (programování)
Generatore (informatica)
Gerador (ciência da computação)
m.02rdr9
Q2565187
Генератор (програмування)
Генератор (рачунарство)
פונקציה מחוללת
مولد (برمجة)
مولد (برنامه‌نویسی)
ジェネレータ (プログラミング)
生成器 (计算机编程)
Subject
Category:Articles with example C Sharp code
Category:Articles with example Haskell code
Category:Articles with example Java code
Category:Articles with example Perl code
Category:Articles with example Python (programming language) code
Category:Articles with example Racket code
Category:Articles with example R code
Category:Articles with example Ruby code
Category:Articles with example Tcl code
Category:Iteration in programming
Category:Programming constructs
WasDerivedFrom
Generator (computer programming)?oldid=1123250001&ns=0
WikiPageLength
28896
Wikipage page ID
572997
Wikipage revision ID
1123250001
WikiPageUsesTemplate
Template:Authority control
Template:Further information
Template:Other uses
Template:Refimprove
Template:Script%7D %7B%0A %23 Produce the result of