Metaprog can be abstruse
Dom Disc
dominikus at scherkl.de
Wed Jul 6 11:23:22 UTC 2022
On Wednesday, 6 July 2022 at 00:11:58 UTC, kdevel wrote:
> 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,
> ];
> ```
Ok, but with this, you can't see where the overflow will occur.
So you have the same problem as with the one-liner (and it is
indeed very much longer).
More information about the Digitalmars-d
mailing list