I dun a DIP, possibly the best DIP ever

Manu turkeyman at gmail.com
Fri Apr 24 06:52:28 UTC 2020


On Fri, Apr 24, 2020 at 4:35 PM Walter Bright via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On 4/23/2020 10:51 PM, Manu wrote:
> > Another reason I introduce `...` is for static fold.
> > The follow-up to this DIP would make this expression work:
> >
> >    `Tup + ...`  ->  `Tup[0] + Tup[1] + ... + Tup[$-1]`
>
> I expect static foreach can handle that. But we can dig a little deeper. D
> doesn't have a special syntax to sum the elements of an array, but it can
> use a
> library function to do it. The next observation is that to sum the
> elements of a
> tuple, all the tuple members need to be implicitly convertible to a single
> arithmetic type. There is a way to do that:
>
>      [ Tup ]
>

No, it's not necessary that they are common types. It's actually the
opposite intent of the expression.
If they wanted what you say, they would write what you say today.

The point of tuple expansions as opposed to using an array is almost
certainly because you DO have mixed types.
If the BinOp is logical, anything that can coerce to true/false is
acceptable. If it's arithmetic, then operator overloads are probably part
of the equation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20200424/8e38aa8c/attachment.htm>


More information about the Digitalmars-d mailing list