I dun a DIP, possibly the best DIP ever

Manu turkeyman at gmail.com
Fri Apr 24 00:16:52 UTC 2020


On Fri, Apr 24, 2020 at 2:30 AM Steven Schveighoffer via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On 4/23/20 9:53 AM, Manu wrote:
>
> >
> > You can do this by expanding tuples with the appropriate indices:
> >    fun(Xs[CrossIndexX], Ys[CrossIndexY])...
> > Where CrossIndexX is (0, 0, 1, 1) and CrossIndexY is (0, 1, 0, 1).
>
> I don't think this works, aren't Xs and Ys tuples also?
>
> I think what you need is to expand the Xs and Ys into further tuples:
>
> alias XParams = Xs[CrossIndexX]...;
> alias YParams = Ys[CrossIndexY]...;
> fun(XParams, YParams)...;
>
> Which would work I think.
>
> this means you need 4 pre-expression declarations! Two for the X and Y
> expansions, and two for the indexes.
>
> -Steve
>

Oh yeah, it was too late at night. Your solution looks right.


On a slightly unrelated note; there's a really interesting idea up-thread
about making nested `...` not be expanded by the outer `...`
For instance:

  template T(A, B...) { ... }
  T!(Tup1, Tup2...)...

What we're saying here is, Tup2 gets the identity expansion, but that
result is NOT expanded with the outer; so the expansion above is:

  T!(Tup1, Tup2...)...  ->  ( T!(Tup1[0], Tup2...), T!(Tup1[1], Tup2...),
...,  T!(Tup1[$-1], Tup2...) )

This is opposed to currently where we recurse through nested expansions,
effectively:

  T!(Tup1, Tup2)...  ->  ( T!(Tup1[0], Tup2[0]), T!(Tup1[1], Tup2[1]),
...,  T!(Tup1[$-1], Tup2[$-1]) )

So, despite Tup2's expansion is the identity expansion, this syntax allows
Tup2 to be passed to T!()'s variadic args as the tuple it is, rather than
expanded like Tup.
Using `...` in nested context this way gives articulate control over cases
where multiple Tuples in the tree should or shouldn't be expanded by `...`

I think this is also the natural rule; it follows from the claim that
expansion is performed pre-semantic evaluation; nested `...` is only a
tuple AFTER evaluation, so it seems natural that it should not be expanded
by the outer expansion.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20200424/f39b5192/attachment-0001.htm>


More information about the Digitalmars-d mailing list