Two chunks but No allocation

Salih Dincer salihdb at hotmail.com
Wed Mar 27 13:38:29 UTC 2024


Is it possible to process both chunks without requiring memory 
allocation (not using an array)?

For example:

```d
import std;
void main()
{
   auto fib = (real a, real b)
        => recurrence!"a[n-1] + a[n-2]"(a, b);

   auto myFib = fib(1, 1).take(48).array;
   auto goldenRadio = myFib.chunks(2).map!
   //"a[1] / a[0]";/* line #9
   ((a) {
     const m = a.front;
     a.popFront();
     const n = a.front;

     return m/n; });//*/

   goldenRadio.back.writefln!"%.21f";
   writeln("0.61803398874989484820");
}
```

Of course, it also works if you remove the comment marks on line 
#9 but I'm still using .array because the .chunks error tells me 
that.

So, not works this:

```d
fib(1, 1).take(48)
          //.array
          .chunks(2)
          .map!"a[1] / a[0]"
          .back
          .writeln; // 1.61803
```

Thanks...

SDB at 79


More information about the Digitalmars-d-learn mailing list