Metaprog can be abstruse

kdevel kdevel at vogtner.de
Wed Jul 6 00:11:58 UTC 2022


On Monday, 4 July 2022 at 13:03:55 UTC, Dom Disc wrote:
[...]
> This advantage becomes much more clear in, let's say:
> ```d
> immutable long powersOfThree = iota(27).map!(p => 
> 3.pow(p)).array;
> ```
> Handwritten this is a very long chain of arbitrary numbers and 
> you have to put a very close look, that those are indeed the 
> powers of three.

Really?

```
immutable long [] powersOfThree = [
       1,
       3,
       3 * 3,
       3 * 3 * 3,
       3 * 3 * 3 * 3,
       3 * 3 * 3 * 3 * 3,
       3 * 3 * 3 * 3 * 3 * 3,
       3 * 3 * 3 * 3 * 3 * 3 * 3,
       3 * 3 * 3 * 3 * 3 * 3 * 3 * 3,
       3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3,
       3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3,
       3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3,
    ];
```


More information about the Digitalmars-d mailing list