C# の単純なジェネレーターを次に示します。
IEnumerable<int> Foo()
{
int a = 1, b = 1;
while(true)
{
yield return b;
int temp = a + b;
a = b;
b = temp;
}
}
Digital Mars Dで同様のジェネレータを作成するにはどうすればよいですか?
(質問はyield returnステートメントについてです)
ありがとう!
アップデート。それは面白い。数学的シーケンスを生成しているだけなので、繰り返しを使用するのが良いオプションかもしれません。
auto fib = recurrence!("a[n-1] + a[n-2]")(1, 1);
foreach (e; take(fib, 10)) // <- prints first ten numbers from the sequence
{
writeln(e);
}