I dun a DIP, possibly the best DIP ever

Walter Bright newshound2 at digitalmars.com
Fri Apr 24 07:34:06 UTC 2020


On 4/23/2020 11:52 PM, Manu wrote:
> On Fri, Apr 24, 2020 at 4:35 PM Walter Bright via Digitalmars-d 
> <digitalmars-d at puremagic.com <mailto: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.

The only way:

   1 + 'a' + 1.0 + 1L + 2.0L

can be computed is if the operands are brought to a common arithmetic type.


More information about the Digitalmars-d mailing list