I dun a DIP, possibly the best DIP ever

Steven Schveighoffer schveiguy at gmail.com
Wed Apr 22 14:53:21 UTC 2020


On 4/22/20 9:45 AM, WebFreak001 wrote:
> On Wednesday, 22 April 2020 at 12:19:25 UTC, rikki cattermole wrote:
>> Change it to something like .unpackSequence instead of ... and I would 
>> be happy.
> 
> I'm for some other thing than ... too, in C++ it's a quite bad syntax 
> and it can become very ugly to maintain with all the different 
> combinations you could use it with from a compiler viewpoint. 
> Additionally if you do miss some combinations or allow more complex 
> operators it will quickly become a mess of "why does this compile but 
> why doesn't this compile" or "why does this do something different"
> 
> I'm especially not a fan of allowing all of
> (Tup*10)...  -->  ( Tup[0]*10, Tup[1]*10, ... , Tup[$-1]*10 )
> and
> (Tup1*Tup2)...
> and
> myArr[Tup + 1]... -> myArr[Tup[0] + 1], myArr[Tup[1] + 1], myArr[Tup[2] 
> + 1]
> 
> would this be valid:
> f!T...(x)

It would expand to:

(f!T[0], f!(T[1]), ... , f!(T[n]))(x)

I don't think this would compile.

> or rather this?
> f!T(x)...

That would work, you would have:

(f!(T[0])(x), f!(T[1])(x), ..., f!(T[n])(x))

> what does (cast(Tup)x)... evaluate to?

(cast(Tup[0])x, cast(Tup[1])x, ..., cast(Tup[n])x);

> is f(Tup) and f(Tup...) now doing the same thing?

Yes, using Tup... is the same as Tup. Only inside expressions that use 
Tup would the ... make sense.

> if
> f(Items.x...)
> works then what about
> f(Items.MemberTup...) ?

I would expect an expansion as Manu described, where the natural 
expansion of Items becomes Items[0].MemberTup, Items[1].MemberTup, ...

However, there are some ambiguities that I'm not sure have been solved. 
What about templates that expand to tuples? Are the results of those 
tuples part of the ... expansion?

What about:

alias F!(T...) = AliasSeq!(T, T);

Consider this expansion:

alias t = AliasSeq!(int, char);

F!(F!t))...

Does it mean:

F!(F!int), F!(F!char)) => int, int, int, int, char, char, char, char

or does it mean:

F!(AliasSeq!(int, char, int, char))... => int, char, int, char, int, 
char, int, char

In other words, what if part of the expression *creates* a tuple. Is 
that the thing that gets expanded? I would have to say no, right? 
Otherwise, the whole thing might be expanded and the ... trivially applied.

So that means things like (assuming G does something similar but not 
identical to F:

F!(G!int)... would have to be the same as F!(G!int). This might be very 
confusing to someone expecting the inner tuple to be done before the 
expansion is considered.

I don't know how to DIP-ify this idea. But it definitely needs to be 
talked about.

-Steve


More information about the Digitalmars-d mailing list