经期不能吃什么水果| 甲状腺有什么症状| 胆囊炎吃什么药好得快| 球蛋白适合什么人打| 肛瘘不治疗有什么后果| 双绿生肖是什么生肖| 血管瘤有什么症状| 男人少精弱精吃什么补最好| 流鼻血是什么病的前兆| 染色体xy代表什么| 考试前吃什么| 医院规培是什么意思| 男羊配什么属相最好| 黄瓜和什么一起炒好吃| 头孢和什么药不能一起吃| 痛风忌口不能吃什么东西| 丘疹是什么原因引起的| 同型半胱氨酸高挂什么科| 肝钙化斑是什么意思| 亲嘴为什么要伸舌头| 黄鼻涕是什么感冒| 胎毒是什么意思| 属龙的守护神是什么菩萨| 左胸上方隐痛什么原因| 床虱咬了要擦什么药膏| 吃了火龙果不能吃什么| 什么叫蛋白质| 什么是ts| 花柳病是什么病| 为什么头发会分叉| 淋巴细胞比率偏高是什么原因| 喜欢穿黑色衣服的女人是什么性格| 什么人容易怀葡萄胎| 灵魂摆渡人是什么意思| 掌中宝是什么东西| 女人喝咖啡有什么好处和坏处| 西红柿生吃有什么好处| 格五行属什么| 藏红花和什么一起泡水喝效果好| 大炮是什么| 垂体是什么| 三言两语是什么生肖| 州字五行属什么| 阿胶什么季节吃最好| 梦见被狗追是什么意思| 锡兵是什么意思| 病原体是什么意思| 98年什么命| 万能输血者是什么血型| br是什么意思| 屏气是什么意思| 风起云涌是什么意思| 吃什么子宫肌瘤会消除| 慢性疾病都包括什么病| 适得其反是什么意思| 牙龈流血是什么原因| ep是什么意思| 动不动就出汗是什么原因| 硬不起来是什么原因| 甲流乙流吃什么药| 马赛克是什么| 圆坟是什么意思| 脑供血不足什么原因引起的| 多动症看什么科室| 24k黄金是什么意思| 什么是点映| 心血不足吃什么药| 4月23日什么星座| 苦瓜干泡水喝有什么功效| 梅花是什么颜色| 桦树茸有什么功效| 高什么亮什么成语| 2月16日什么星座| 背部长痘痘是什么原因造成| 吃东西就打嗝是什么原因| 禄蠹是什么意思| 三伏天什么时候开始| 皮脂膜是什么| 女人吃牛油果有什么好处| 肝fnh是什么病| 送男生什么生日礼物好| 一什么毛巾| 早起眼皮肿是什么原因引起的| 太白金星是什么神| 34岁属什么| 不想长胡子有什么办法| 爽字代表什么生肖| 打饱嗝是什么病的前兆| fan是什么意思| 什么动物不喝水| 闹心是什么意思啊| 犒劳自己是什么意思| 血压低吃什么补得快| 早晨嘴苦是什么原因引起的| 钢铁锅含眼泪喊修瓢锅这是什么歌| 精子有点黄是什么原因| 女性肝囊肿要注意什么| 真菌怕什么| 尿道口下裂是什么样子| 大脚趾发黑是什么原因| 怀孕应该注意什么| 情绪上来像发疯一般是什么病| 什么减肥药最管用| 检查尿液能查出什么病| 拍拖什么意思| 哺乳期吃什么下奶| 葡萄是什么茎| 附耳是什么意思| 孕妇可以吃什么水果| 北京为什么叫四九城| 备孕前准备吃什么叶酸| 王维是诗什么| 号外是什么意思| 7点是什么时辰| 把你的心我的心串一串是什么歌| 拔牙后喝酒有什么危害| 烫伤抹什么药膏| 叟是什么意思| 小猫不能吃什么食物| 我俩太不公平这是什么歌| 什么的姑娘| 大便什么颜色是正常的| 戴银首饰对身体有什么好处| 范仲淹是什么朝代的| 真菌涂片检查是查什么| 鱼翅是什么东西| 体测是什么意思| 天空是什么颜色| 补钙过量有什么害处| 蓝色预警是什么级别| 插班生是什么意思| 超导是什么意思| 海胆是什么动物| 黑洞是什么| 文雅是什么意思| 爱吃酸的人是什么体质| 维生素b2吃多了有什么副作用| 晚霞是什么| 来月经小腹痛是什么原因| 右大腿上部疼痛是什么原因| 生命的本质是什么| 甲状腺五类是什么意思| 玉林狗肉节是什么时候| 软组织损伤是什么意思| 十九畏是什么意思| 好老公的标准是什么| 梦见大便是什么预兆| 下面瘙痒是什么原因| 康波是什么意思| 为什么打呼噜| 喜用神是什么| 吃什么可以化掉息肉| 什么是大专| 尿泡沫多吃什么药| teal是什么颜色| bosch是什么牌子| 胃热是什么原因引起的| 痛风能喝什么饮料| 支原体吃什么药| cn是什么意思啊| ecmo是什么| 没必要什么意思| 口干舌燥是什么意思| 老年人腿脚无力是什么原因| 手脚脱皮是什么原因导致的| gpt什么意思| nt是什么币| 半夜惊醒是什么原因| atp是什么| 嘴臭是什么原因引起的| 专情是什么意思| 关节发黑是什么原因| 沈腾和马丽是什么关系| model是什么牌子| 小孩咳嗽吃什么药效果最好| 中药木香的功效与作用是什么| 本钱是什么意思| 海豚用什么呼吸| 北京朝阳医院擅长什么| 日加个立念什么| 20度穿什么衣服| 感冒了不能吃什么食物| 乌托邦是什么| 什么叫提供情绪价值| 晓五行属性是什么| 女人下面 什么味道| 一般炒什么菜放蚝油| 六月二十日是什么日子| RH阳性什么意思| 老婆饼是什么馅| 什么树没有叶| 胃痉挛是什么症状| 什么有成什么| 辣条是什么做的| 苏轼为什么反对王安石变法| hyc是什么牌子| 仙人跳是什么意思啊| 预防老年痴呆吃什么药| 什么的高山填空| 低压高是什么意思| 大于90度的角是什么角| 肚脐周围疼痛是什么原因| 欧了是什么意思| 鸭胗是鸭的什么部位| 什么是梅尼埃综合症| 高是什么意思| 有机蔬菜是什么意思| 逃出生天什么意思| 铅中毒什么症状| 醒酒喝什么饮料| 杜仲有什么作用| 杨梅酒有什么功效| 上呼吸道感染吃什么| 丹毒不能吃什么| 佛系是什么意思啊| 什么洗面奶祛痘| 领袖是什么意思| 晟这个字读什么| 双顶径和头围有什么区别| 三月初九是什么星座| 感同身受什么意思| 饮食男女是什么意思| 南京区委书记什么级别| 吃什么养肝护肝| 什么样的眼睛形容词| 从容不迫是什么意思| 带id是什么意思| 海绵体修复吃什么药| 下饭是什么意思| 不凝血是什么原因| 矢量是什么意思| 光气是什么气体| 孕妇缺钙吃什么食物补充最快| 丑指什么生肖| 护理学和护理有什么区别| zm是什么意思| 面料支数是什么意思| 乳腺纤维瘤是什么原因引起的| 恩爱是什么意思| 经由是什么意思| 急性肠炎吃什么药| 子不教父之过是什么意思| 银手镯发黄是什么原因| 姨妈期可以做什么运动| 中医行业五行属什么| 五音不全是什么意思| 趴着睡觉是什么原因| 梦见好多虫子是什么意思| 前列腺炎中医叫什么病| 精液什么颜色正常| 太多的借口太多的理由是什么歌| 梦见杀牛是什么预兆| 喝鲜牛奶有什么好处和坏处| 开放式耳机是什么意思| hcg值高说明什么| 1995年属什么| 看包皮挂什么科| 羊内腰和外腰分别是什么| 1994是什么年| 牛仔是什么面料| 急性胃肠炎用什么药| yy飞机票是什么| 这是什么颜色| 独是什么生肖| 百度

毛大庆:联合办公的发展离不开国际化和智慧办公

百度 意识转移250年后科技高度发达,人的大脑可以被数字化。

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.[1] 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.[2] Generators, also known as semicoroutines,[3] 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.

Uses

edit

Generators are usually invoked inside loops.[4] 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 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 more complicated situations, a generator may be used manually outside of a loop to create an iterator, which can then be used in various ways.

Because generators compute their yielded values only on demand, they are useful for representing streams, such as sequences that would be expensive or impossible to compute at once. These include e.g. infinite sequences and live data streams.

When eager evaluation is desirable (primarily when the sequence is finite, as otherwise evaluation will never terminate), one can either convert to a list, or use a parallel construction that creates a list instead of a generator. For example, in Python a generator g can be evaluated to a list l via l = list(g), while in F# the sequence expression seq { ... } evaluates lazily (a generator or sequence) but [ ... ] evaluates eagerly (a list).

In the presence of generators, loop constructs of a language – such as for and while – 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. For example, a ranged loop like for x = 1 to 10 can be implemented as iteration through a generator, as in Python's for x in range(1, 10). Further, break can be implemented as sending finish to the generator and then using continue in the loop.

Languages providing generators

edit

Generators first appeared in CLU (1975),[5] were a prominent feature in the string manipulation language Icon (1977) and are now available in Python (2001),[6] C#,[7] Ruby, PHP,[8] ECMAScript (as of ES6/ES2015), and other languages. In CLU and C#, generators are called iterators, and in Ruby, enumerators.

Lisp

edit

The final Common Lisp standard does not natively provide generators, yet various library implementations exist, such as SERIES documented in CLtL2 or pygen.

A yield statement is used to implement iterators over user-defined data abstractions.[9]

string_chars = iter (s: string) yields (char);
  index: int := 1;
  limit: int := string$size (s);
  while index <= limit do
    yield (string$fetch(s, index));
    index := index + 1;
    end;
end string_chars;

for c: char in string_chars(s) do
   ...
end;

Icon

edit

Every expression (including loops) is a generator. The language has many generators built-in and even implements some of the logic semantics using the generator mechanism (logical disjunction or "OR" is done this way).

Printing squares from 0 to 20 can be achieved using a co-routine by writing:

   local squares, j
   squares := create (seq(0) ^ 2)
   every j := |@squares do
      if j <= 20 then
         write(j)
      else
         break

However, most of the time custom generators are implemented with the "suspend" keyword which functions exactly like the "yield" keyword in CLU.

C does not have generator functions as a language construct, but, as they are a subset of coroutines, it is simple to implement them using any framework that implements stackful coroutines, such as libdill.[10] On POSIX platforms, when the cost of context switching per iteration is not a concern, or full parallelism rather than merely concurrency is desired, a very simple generator function framework can be implemented using pthreads and pipes.

It is possible to introduce generators into C++ using pre-processor macros. The resulting code might have aspects that are very different from native C++, but the generator syntax can be very uncluttered.[11] The set of pre-processor macros defined in this source allow generators defined with the syntax as in the following example:

$generator(descent) {
   int i;

   // place the constructor of our generator, e.g. 
   // descent(int minv, int maxv) {...}
   
   // from $emit to $stop is a body of our generator:
    
   $emit(int) // will emit int values. Start of body of the generator.
      for (i = 10; i > 0; --i)
         $yield(i); // similar to yield in Python,
                    // returns next number in [1..10], reversed.
   $stop; // stop, end of sequence. End of body of the generator.
};

This can then be iterated using:

int main(int argc, char* argv[]) {
  descent gen;
  for (int n; gen(n);) // "get next" generator invocation
    printf("next number is %d\n", n);
  return 0;
}

Moreover, C++11 allows foreach loops to be applied to any class that provides the begin and end functions. It's then possible to write generator-like classes by defining both the iterable methods (begin and end) and the iterator methods (operator!=, operator++ and operator*) in the same class. For example, it is possible to write the following program:

#include <iostream>

int main() {
    for (int i: range(10)) {
        std::cout << i << std::endl;
    }
    return 0;
}

A basic range implementation would look like that:

class range {
private:
    int last;
    int iter;

public:
    range(int end):
        last(end),
        iter(0)
    {}

    // Iterable functions
    const range& begin() const { return *this; }
    const range& end() const { return *this; }

    // Iterator functions
    bool operator!=(const range&) const { return iter < last; }
    void operator++() { ++iter; }
    int operator*() const { return iter; }
};

Furthermore, C++20 formally introduced support for coroutines,[12] which can be used to implement generators.[13] C++23 introduced std::generator in the standard library, making it much easier to implement generators. For example, a basic range generator can be implemented as:

#include <generator>

std::generator<int> range(int n) {
    for (int i = 0; i < n; ++i) {
        co_yield i;
    }
}

It can be iterated using foreach loops:

#include <iostream>

int main() {
    for (int i: range(10)) {
        std::cout << i << std::endl;
    }
    return 0;
}

Perl

edit

Perl does not natively provide generators, but support is provided by the Coro::Generator module which uses the Coro co-routine framework. Example usage:

use strict;
use warnings;
# Enable generator { BLOCK } and yield
use Coro::Generator;
# Array reference to iterate over
my $chars = ['A'...'Z'];

# New generator which can be called like a coderef.
my $letters = generator {
    my $i = 0;
    for my $letter (@$chars) {
        # get next letter from $chars
        yield $letter;
    }
};

# Call the generator 15 times.
print $letters->(), "\n" for (0..15);

Raku

edit

Example parallel to Icon uses Raku (formerly/aka Perl 6) Range class as one of several ways to achieve generators with the language.

Printing squares from 0 to 20 can be achieved by writing:

for (0 .. *).map(* ** 2) -> $i {
    last if $i > 20;
    say $i
}

However, most of the time custom generators are implemented with "gather" and "take" keywords in a lazy context.

In Tcl 8.6, the generator mechanism is founded on named coroutines.

proc generator {body} {
    coroutine gen[incr ::disambiguator] apply {{script} {
        # Produce the result of [generator], the name of the generator
        yield [info coroutine]
        # Do the generation
        eval $script
        # Finish the loop of the caller using a 'break' exception
        return -code break
    }} $body
}

# Use a simple 'for' loop to do the actual generation
set count [generator {
    for {set i 10} {$i <= 20} {incr i} {
        yield $i
    }
}]

# Pull values from the generator until it is exhausted
while 1 {
    puts [$count]
}

Haskell

edit

In Haskell, with its lazy evaluation model, every datum created with a non-strict data constructor is generated on demand. For example,

countFrom :: Integer -> [Integer]
countFrom n = n : countFrom (n + 1)

from10to20 :: [Integer]
from10to20 = takeWhile (<= 20) $ countFrom 10

primes :: [Integer]
primes = 2 : 3 : nextPrime 5
  where
    nextPrime n
        | notDivisible n = n : nextPrime (n + 2)
        | otherwise = nextPrime (n + 2)
    notDivisible n =
        all ((/= 0) . (rem n)) $ takeWhile ((<= n) . (^ 2)) $ tail primes

where (:) is a non-strict list constructor, cons, and $ is just a "called-with" operator, used for parenthesization. This uses the standard adaptor function,

takeWhile p [] = []
takeWhile p (x:xs) | p x = x : takeWhile p xs
                   | otherwise = []

which walks down the list and stops on the first element that doesn't satisfy the predicate. If the list has been walked before until that point, it is just a strict data structure, but if any part hadn't been walked through before, it will be generated on demand. List comprehensions can be freely used:

squaresUnder20 = takeWhile (<= 20) [x * x | x <- countFrom 10]
squaresForNumbersUnder20 = [x * x | x <- takeWhile (<= 20) $ countFrom 10]

Racket

edit

Racket provides several related facilities for generators. First, its for-loop forms work with sequences, which are a kind of a producer:

(for ([i (in-range 10 20)])
  (printf "i = ~s\n" i))

and these sequences are also first-class values:

(define 10-to-20 (in-range 10 20))
(for ([i 10-to-20])
  (printf "i = ~s\n" i))

Some sequences are implemented imperatively (with private state variables) and some are implemented as (possibly infinite) lazy lists. Also, new struct definitions can have a property that specifies how they can be used as sequences.

But more directly, Racket comes with a generator library for a more traditional generator specification. For example,

#lang racket
(require racket/generator)
(define (ints-from from)
  (generator ()
    (for ([i (in-naturals from)]) ; infinite sequence of integers from 0
      (yield i))))
(define g (ints-from 10))
(list (g) (g) (g)) ; -> '(10 11 12)

Note that the Racket core implements powerful continuation features, providing general (re-entrant) continuations that are composable, and also delimited continuations. Using this, the generator library is implemented in Racket.

 
UML class diagram depiction of the inheritance chain of the Generator class in PHP

The community of PHP implemented generators in PHP 5.5. Details can be found in the original Request for Comments: Generators.

Infinite Fibonacci sequence:

function fibonacci(): Generator
{
    $last = 0;
    $current = 1;
    yield 1;
    while (true) {
        $current = $last + $current;
        $last = $current - $last;
        yield $current;
    }
}

foreach (fibonacci() as $number) {
    echo $number, "\n";
}

Fibonacci sequence with limit:

function fibonacci(int $limit): Generator 
{
    yield $a = $b = $i = 1;
 
    while (++$i < $limit) {
        yield $a = ($b = $a + $b) - $a;
    }
}

foreach (fibonacci(10) as $number) {
    echo "$number\n";
}

Any function which contains a yield statement is automatically a generator function.

Ruby

edit

Ruby supports generators (starting from version 1.9) in the form of the built-in Enumerator class.

# Generator from an Enumerator object
chars = Enumerator.new(['A', 'B', 'C', 'Z'])

4.times { puts chars.next }

# Generator from a block
count = Enumerator.new do |yielder|
  i = 0
  loop { yielder.yield i += 1 }
end

100.times { puts count.next }

Java

edit

Java has had a standard interface for implementing iterators since its early days, and since Java 5, the "foreach" construction makes it easy to loop over objects that provide the java.lang.Iterable interface. (The Java collections framework and other collections frameworks, typically provide iterators for all collections.)

record Pair(int a, int b) {};

Iterable<Integer> myIterable = Stream.iterate(new Pair(1, 1), p -> new Pair(p.b, p.a + p.b))
        .limit(10)
        .map(p -> p.a)::iterator;

myIterable.forEach(System.out::println);

Or get an Iterator from the Java 8 super-interface BaseStream of Stream interface.

record Pair(int a, int b) {};

// Save the iterator of a stream that generates fib sequence
Iterator<Integer> myGenerator = Stream
        // Generates Fib sequence
        .iterate(new Pair(1, 1), p -> new Pair(p.b, p.a + p.b))
        .map(p -> p.a).iterator();

// Print the first 5 elements
for (int i = 0; i < 5; i++) {
    System.out.println(myGenerator.next());
}

System.out.println("done with first iteration");

// Print the next 5 elements
for (int i = 0; i < 5; i++) {
    System.out.println(myGenerator.next());
}

Output:

1
1
2
3
5
done with first iteration
8
13
21
34
55

An example C# 2.0 generator (the yield is available since C# version 2.0): Both of these examples utilize generics, but this is not required. yield keyword also helps in implementing custom stateful iterations over a collection as discussed in this discussion.[14]

// Method that takes an iterable input (possibly an array)
// and returns all even numbers.
public static IEnumerable<int> GetEven(IEnumerable<int> numbers)
{
    foreach (int number in numbers)
    {
        if ((number % 2) == 0)
        {
            yield return number;
        }
    }
}

It is possible to use multiple yield return statements and they are applied in sequence on each iteration:

public class CityCollection : IEnumerable<string>
{
    public IEnumerator<string> GetEnumerator()
    {
        yield return "New York";
        yield return "Paris";
        yield return "London";
    }
}

In XL, iterators are the basis of 'for' loops:

import IO = XL.UI.CONSOLE

iterator IntegerIterator (var out Counter : integer; Low, High : integer) written Counter in Low..High is
    Counter := Low
    while Counter <= High loop
        yield
        Counter += 1

// Note that I needs not be declared, because declared 'var out' in the iterator
// An implicit declaration of I as an integer is therefore made here
for I in 1..5 loop
    IO.WriteLn "I=", I

F# provides generators via sequence expressions, since version 1.9.1.[15] These can define a sequence (lazily evaluated, sequential access) via seq { ... }, a list (eagerly evaluated, sequential access) via [ ... ] or an array (eagerly evaluated, indexed access) via [| ... |] that contain code that generates values. For example,

seq { for b in 0 .. 25 do
          if b < 15 then
              yield b * b }

forms a sequence of squares of numbers from 0 to 14 by filtering out numbers from the range of numbers from 0 to 25.

Python

edit

Generators were added to Python in version 2.2 in 2001.[6] An example generator:

from typing import Iterator

def countfrom(n: int) -> Iterator[int]:
    while True:
        yield n
        n += 1

# Example use: printing out the integers from 10 to 20.
# Note that this iteration terminates normally, despite
# countfrom() being written as an infinite loop.

for i in countfrom(10):
    if i <= 20:
        print(i)
    else:
        break

# Another generator, which produces prime numbers indefinitely as needed.
import itertools

def primes() -> Iterator[int]:
    """Generate prime numbers indefinitely as needed."""
    yield 2
    n = 3
    p = [2]
    while True:
        # If dividing n by all the numbers in p, up to and including sqrt(n),
        # produces a non-zero remainder then n is prime.
        if all(n % f > 0 for f in itertools.takewhile(lambda f: f * f <= n, p)):
            yield n
            p.append(n)
        n += 2

In Python, a generator can be thought of as an iterator that contains a frozen stack frame. Whenever next() is called on the iterator, Python resumes the frozen frame, which executes normally until the next yield statement is reached. The generator's frame is then frozen again, and the yielded value is returned to the caller.

PEP 380 (implemented in Python 3.3) adds the yield from expression, allowing a generator to delegate part of its operations to another generator or iterable.[16]

Generator expressions

edit

Python has a syntax modeled on that of list comprehensions, called a generator expression that aids in the creation of generators. The following extends the first example above by using a generator expression to compute squares from the countfrom generator function:

squares = (n * n for n in countfrom(2))

for j in squares:
    if j <= 20:
        print(j)
    else:
        break

ECMAScript

edit

ECMAScript 6 (a.k.a. Harmony) introduced generator functions.

An infinite Fibonacci sequence can be written using a function generator:

function* fibonacci(limit) {
    let [prev, curr] = [0, 1];
    while (!limit || curr <= limit) {
        yield curr;
        [prev, curr] = [curr, prev + curr];
    }
}

// bounded by upper limit 10
for (const n of fibonacci(10)) {
    console.log(n);
}

// generator without an upper bound limit
for (const n of fibonacci()) {
    console.log(n);
    if (n > 10000) break;
}

// manually iterating
let fibGen = fibonacci();
console.log(fibGen.next().value); // 1
console.log(fibGen.next().value); // 1
console.log(fibGen.next().value); // 2
console.log(fibGen.next().value); // 3
console.log(fibGen.next().value); // 5
console.log(fibGen.next().value); // 8

// picks up from where you stopped
for (const n of fibGen) {
    console.log(n);
    if (n > 10000) break;
}

The iterators package can be used for this purpose.[17][18]

library(iterators)

# Example ------------------
abc <- iter(c('a','b','c'))
nextElem(abc)

Smalltalk

edit

Example in Pharo Smalltalk:

The Golden ratio generator below returns to each invocation 'goldenRatio next' a better approximation to the Golden Ratio.

goldenRatio := Generator on: [ :g | | x y z r | 
	x := 0.
	y := 1.
	[  
		z := x + y.
		r := (z / y) asFloat.
		x := y.
		y := z.
		g yield: r
	] repeat	
].

goldenRatio next.

The expression below returns the next 10 approximations.

Character cr join: ((1 to: 10) collect: [ :dummy | ratio next ]).

See more in A hidden gem in Pharo: Generator.

See also

edit

Notes

edit
  1. ^ What is the difference between an Iterator and a Generator?
  2. ^ Kiselyov, Oleg (January 2004). "General ways to traverse collections in Scheme".
  3. ^ Anthony Ralston (2000). Encyclopedia of computer science. Nature Pub. Group. ISBN 978-1-56159-248-7. Retrieved 11 May 2013.
  4. ^ The Icon Programming Language utilizes generators to implement its goal directed evaluation. In Icon, generators can be invoked in contexts outside of the normal looping control structures.
  5. ^ Liskov, Barbara (April 1992). "A History of CLU" (PDF). Archived from the original (PDF) on 2025-08-06. Retrieved 2025-08-06.
  6. ^ a b Python Enhancement Proposals: PEP 255: Simple Generators, PEP 289: Generator Expressions, PEP 342: Coroutines via Enhanced Generators
  7. ^ yield (C# Reference)
  8. ^ "PHP: Generators overview - Manual".
  9. ^ Liskov, B.; Snyder, A.; Atkinson, R.; Schaffert, C. (1977). "Abstraction mechanisms in CLU". Communications of the ACM. 20 (8): 564–576. CiteSeerX 10.1.1.112.656. doi:10.1145/359763.359789. S2CID 17343380.
  10. ^ "Structured Concurrency for C".
  11. ^ "Generators in C++". 21 September 2008.
  12. ^ "Coroutines (C++20) - cppreference.com". en.cppreference.com. Retrieved 2025-08-06.
  13. ^ Carter, Casey; Baker, Lewis; Jabot, Corentin. "std::generator implementation in C++20". godbolt.org. Retrieved 2025-08-06.
  14. ^ "What is the yield keyword used for in C#?". stackoverflow.com. Retrieved 2025-08-06.
  15. ^ "Some Details on F# Computation Expressions". Retrieved 2025-08-06.
  16. ^ PEP 380 -- Syntax for Delegating to a Subgenerator
  17. ^ Generator functions in R
  18. ^ "Infinite generators in R". 5 January 2013.

References

edit
  • 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]
前列腺钙化灶是什么 痣发痒是什么原因 在水一方什么意思 眩晕症吃什么药 老放屁是什么原因
骨皮质断裂是什么意思 什么的海风 吃桃子有什么好处 部分导联st段改变是什么意思 被蜜蜂蛰了擦什么药
实拍是什么意思 什么掌不能拍 腿酸是什么原因引起的 为什么蛋皮会痒 处暑吃什么传统食物
靖五行属性是什么 感冒喉咙痛吃什么药好 射精出血是什么原因 卡介疫苗什么时候打 73年属什么的
凡士林是什么东西hcv8jop8ns3r.cn 鸡拉绿色粪便是什么病xinjiangjialails.com 小腿抽筋是什么原因引起的hcv8jop1ns6r.cn 脑梗吃什么药效果最好hcv9jop2ns2r.cn 中子是什么hcv9jop5ns7r.cn
什么是山海经hcv8jop1ns6r.cn 什么字永远写不好hcv9jop8ns0r.cn 三严三实是什么naasee.com 胃糜烂要吃什么药hcv8jop0ns3r.cn 肠胃炎看什么科hcv7jop5ns2r.cn
什么叫割礼hcv9jop7ns2r.cn 腌肉放什么调料hcv9jop2ns8r.cn 人工肝是什么意思hcv8jop0ns9r.cn 挠头什么意思hcv9jop8ns2r.cn 上什么环最好最安全伤害小cl108k.com
表哥的儿子叫我什么hcv9jop2ns1r.cn 荔枝是什么季节的水果0735v.com 即什么意思hcv8jop1ns9r.cn 后期是什么意思啊zsyouku.com 带状疱疹长什么样hcv8jop8ns3r.cn
百度