August 10, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Saturday, 10 August 2013 at 10:19:34 UTC, John Colvin wrote: > On Monday, 29 July 2013 at 13:23:23 UTC, JS wrote: >> Sometimes it's nice to be able to have groups of variadic parameters: >> >> template t(T1..., T2...) >> >> ... >> >> t!(a, b, c; d, e, f); >> >> so that a,b,c are for T1 and d,e,f are for T2. >> >> This can be done by making a symbol and breaking up a single variadic but is messy. >> >> I doubt such a feature will ever get added but who knows... > > I was initially unimpressed, but after some recent work I would And this is why just because something looks "unimpressive" to you doesn't mean it is... Obviously if you've never run up against the specific problems proposed by people you won't know how frustrating it is, specially when there is an easy fix. This is why those commie bastards that shoot suggestions down at first sight ruin progress... they don't have the experience with the specific issue to know just how much it sucks. > really like this feature. I have been using > struct Group(T...) > { > alias Ungroup = T; > } > but, useful as it is, this feels like something that should have some sugar on it. > > template A(T0 ..., T1 ...) > { > // use T0 & T1 > } > > A!(int, long, double; Point, int) > > is so much nicer than > EXACTLY! Why the hell would I want to go around doing the stuff below all the time when there is a perfectly fine notation(above) for it? Just because deadlinx, or dicebot, or whoever wants to be close minded about it because they themselves haven't constantly ran into the issue. It's very easy to write off someone elses issues because you yourself don't have the problems but it shows a lot of arrogance. > template A(T0, T1) > if(isGroup!T0 && isGroup!T1) > { > alias t0 = T0.Ungroup; > alias t1 = T1.Ungroup; > > //use t0 && t1 > } > > A!(Group!(int, long, double), Group!(Point, int)) Even better, you can use something like A!(int, long, double, _S_, Point, int) where _S_ acts as the `;`. Not great, but in my opinion it is simpler than the grouping and ungrouping. (you can write a utility function to convert between them). |
August 10, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On Saturday, 10 August 2013 at 12:40:55 UTC, JS wrote:
> On Saturday, 10 August 2013 at 10:19:34 UTC, John Colvin wrote:
>> On Monday, 29 July 2013 at 13:23:23 UTC, JS wrote:
>>> Sometimes it's nice to be able to have groups of variadic parameters:
>>>
>>> template t(T1..., T2...)
>>>
>>> ...
>>>
>>> t!(a, b, c; d, e, f);
>>>
>>> so that a,b,c are for T1 and d,e,f are for T2.
>>>
>>> This can be done by making a symbol and breaking up a single variadic but is messy.
>>>
>>> I doubt such a feature will ever get added but who knows...
>>
>> I was initially unimpressed, but after some recent work I would
>
> And this is why just because something looks "unimpressive" to you doesn't mean it is... Obviously if you've never run up against the specific problems proposed by people you won't know how frustrating it is, specially when there is an easy fix. This is why those commie bastards that shoot suggestions down at first sight ruin progress... they don't have the experience with the specific issue to know just how much it sucks.
That is laden with assumption.
I had run in to the problem before, several times. I was not initially convinced your suggestion was a good idea, especially after monarch dodra posted Group. After some more experience and thought I have now changed my mind.
Anyway, never mind all that, what matters is the proposal.
I think this proposal is a good idea, or at least that there should be some simple syntax for doing this sort of thing. In particular I'd be interested in hearing from bearophile about how it might fit in with his wider ideas on tuples and syntax for packing/unpacking.
Also, are there any corner cases that haven't been considered.
alias T = Tuple!(int, int);
alias Ts = Tuple!(T, T);
template A(S0..., S1...)
{
alias s0 = S0;
alias s1 = S1;
}
A!(Ts.init).s0 a;
what types are a/s0 and s1?
s0 == Tuple!(int, int) == s1
or
s0 == Tuple!(Tuple!(int, int), Tuple!(int, int))
and s1 is an empty tuple
i.e. what will the rules for auto-expansion/unpacking be?
|
August 10, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Saturday, 10 August 2013 at 17:08:57 UTC, John Colvin wrote: > On Saturday, 10 August 2013 at 12:40:55 UTC, JS wrote: >> On Saturday, 10 August 2013 at 10:19:34 UTC, John Colvin wrote: >>> On Monday, 29 July 2013 at 13:23:23 UTC, JS wrote: >>>> Sometimes it's nice to be able to have groups of variadic parameters: >>>> >>>> template t(T1..., T2...) >>>> >>>> ... >>>> >>>> t!(a, b, c; d, e, f); >>>> >>>> so that a,b,c are for T1 and d,e,f are for T2. >>>> >>>> This can be done by making a symbol and breaking up a single variadic but is messy. >>>> >>>> I doubt such a feature will ever get added but who knows... >>> >>> I was initially unimpressed, but after some recent work I would >> >> And this is why just because something looks "unimpressive" to you doesn't mean it is... Obviously if you've never run up against the specific problems proposed by people you won't know how frustrating it is, specially when there is an easy fix. This is why those commie bastards that shoot suggestions down at first sight ruin progress... they don't have the experience with the specific issue to know just how much it sucks. > > That is laden with assumption. > > I had run in to the problem before, several times. I was not initially convinced your suggestion was a good idea, especially after monarch dodra posted Group. After some more experience and thought I have now changed my mind. > > Anyway, never mind all that, what matters is the proposal. > Well, again, the issue is that it only becomes one once you've actually experienced the problem enough. This is why those that actually haven't even run into the problem shouldn't really have a say so if it is valid or not, unless they can bring some theoretical reason why it is flawed. > I think this proposal is a good idea, or at least that there should be some simple syntax for doing this sort of thing. In particular I'd be interested in hearing from bearophile about how it might fit in with his wider ideas on tuples and syntax for packing/unpacking. > > Also, are there any corner cases that haven't been considered. > > alias T = Tuple!(int, int); > alias Ts = Tuple!(T, T); > > template A(S0..., S1...) > { > alias s0 = S0; > alias s1 = S1; > } > > A!(Ts.init).s0 a; > > what types are a/s0 and s1? > > s0 == Tuple!(int, int) == s1 > > or > > s0 == Tuple!(Tuple!(int, int), Tuple!(int, int)) > and s1 is an empty tuple > > i.e. what will the rules for auto-expansion/unpacking be? The way I see it, using `;` is what separates groups. So in your above code, s1 is empty. The `;` is shorthand for specifying groups. No where do you specify such a group for A!(...), so there are no groups. There is no direct way to get your second case under my proposal... unless the compiler was given some additional feature to do so. e.g., alias Ts = Tuple!(T, T); is not the same as alias Ts = Tuple!(T; T); also, we would probably want to use template A(S0...; S1...) instead of template A(S0..., S1...) The main thing is that `;` adds an extra symbol to split on that is entirely distinct from `,`. If you wanted, you could have Tuple! and TupleSC!. TupleSC! is used when splitting `;`. Tuple! and TupleSC! are not directly related(but can easily be flattened together if necessary. |
August 10, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS |
>> alias T = Tuple!(int, int);
>> alias Ts = Tuple!(T, T);
>>
>> template A(S0..., S1...)
>> {
>> alias s0 = S0;
>> alias s1 = S1;
>> }
>>
>> A!(Ts.init).s0 a;
so
alias T = Tuple!(int, int);
alias Ts = TupleSC!(T, T);
then Ts == ((int, int); (int, int))
and
alias T = TupleSC!(int, int);
alias Ts = Tuple!(T, T);
(int; int), (int; int))
and
alias T = TupleSC!(int, int);
alias Ts = TupleSC!(T, T);
(int; int); (int; int))
which all can be written longhand as TupleY!(TupleX!(int,int), TupleX!(int,int)).
|
August 10, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On 08/10/13 12:19, John Colvin wrote:
> On Monday, 29 July 2013 at 13:23:23 UTC, JS wrote:
>> Sometimes it's nice to be able to have groups of variadic parameters:
>>
>> template t(T1..., T2...)
>>
>> ...
>>
>> t!(a, b, c; d, e, f);
>>
>> so that a,b,c are for T1 and d,e,f are for T2.
>>
>> This can be done by making a symbol and breaking up a single variadic but is messy.
>>
>> I doubt such a feature will ever get added but who knows...
>
> I was initially unimpressed, but after some recent work I would really like this feature. I have been using
> struct Group(T...)
> {
> alias Ungroup = T;
> }
> but, useful as it is, this feels like something that should have some sugar on it.
>
> template A(T0 ..., T1 ...)
> {
> // use T0 & T1
> }
>
> A!(int, long, double; Point, int)
>
> is so much nicer than
>
> template A(T0, T1)
> if(isGroup!T0 && isGroup!T1)
> {
> alias t0 = T0.Ungroup;
> alias t1 = T1.Ungroup;
>
> //use t0 && t1
> }
>
> A!(Group!(int, long, double), Group!(Point, int))
template Tuple(A...) { alias Tuple = A; }
template Ungroup(G...) if (G.length==1) {
static if(__traits(compiles, Tuple!(G[0].Ungroup)))
alias Ungroup = Tuple!(G[0].Ungroup);
else
alias Ungroup = Tuple!(G[0]);
}
then
template A(T...) {
//alias t0 = Ungroup!(T[0]);
//alias t1 = Ungroup!(T[1]);
//use t0 && t1
static assert( {
foreach (ET; T)
pragma(msg, Ungroup!ET);
return 1;
}());
alias A = Ungroup!(T[0])[0];
Ungroup!(T[2])[$-1] AFloat;
}
A!(Group!(int, long, double), Group!(Point, int), float) x;
A!(int, Group!(Point, int), Group!("f", float)) x2;
A!(int, Group!(Point, int), float, "blah", double, Group!(ubyte, "m", float[8], 3.14)) x3;
A!(int, 0, float, Group!(ubyte, "m", float[2], Group!(Group!(int,11,12), Group!(float,21,22)))) x4;
Using just ';' would: a) be too subtle and confusing; b) not be enough
to handle the 'x4' case above.
artur
|
August 11, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to Artur Skawina | On Saturday, 10 August 2013 at 18:28:39 UTC, Artur Skawina wrote: > On 08/10/13 12:19, John Colvin wrote: >> On Monday, 29 July 2013 at 13:23:23 UTC, JS wrote: >>> Sometimes it's nice to be able to have groups of variadic parameters: >>> >>> template t(T1..., T2...) >>> >>> ... >>> >>> t!(a, b, c; d, e, f); >>> >>> so that a,b,c are for T1 and d,e,f are for T2. >>> >>> This can be done by making a symbol and breaking up a single variadic but is messy. >>> >>> I doubt such a feature will ever get added but who knows... >> >> I was initially unimpressed, but after some recent work I would really like this feature. I have been using >> struct Group(T...) >> { >> alias Ungroup = T; >> } >> but, useful as it is, this feels like something that should have some sugar on it. >> >> template A(T0 ..., T1 ...) >> { >> // use T0 & T1 >> } >> >> A!(int, long, double; Point, int) >> >> is so much nicer than >> >> template A(T0, T1) >> if(isGroup!T0 && isGroup!T1) >> { >> alias t0 = T0.Ungroup; >> alias t1 = T1.Ungroup; >> >> //use t0 && t1 >> } >> >> A!(Group!(int, long, double), Group!(Point, int)) > > template Tuple(A...) { alias Tuple = A; } > > template Ungroup(G...) if (G.length==1) { > static if(__traits(compiles, Tuple!(G[0].Ungroup))) > alias Ungroup = Tuple!(G[0].Ungroup); > else > alias Ungroup = Tuple!(G[0]); > } > > then > > template A(T...) { > //alias t0 = Ungroup!(T[0]); > //alias t1 = Ungroup!(T[1]); > > //use t0 && t1 > > static assert( { > foreach (ET; T) > pragma(msg, Ungroup!ET); > return 1; > }()); > > alias A = Ungroup!(T[0])[0]; > Ungroup!(T[2])[$-1] AFloat; > } > > A!(Group!(int, long, double), Group!(Point, int), float) x; > A!(int, Group!(Point, int), Group!("f", float)) x2; > A!(int, Group!(Point, int), float, "blah", double, Group!(ubyte, "m", float[8], 3.14)) x3; > A!(int, 0, float, Group!(ubyte, "m", float[2], Group!(Group!(int,11,12), Group!(float,21,22)))) x4; > > > Using just ';' would: a) be too subtle and confusing; b) not be enough > to handle the 'x4' case above. > > artur a) thats your opinion. b) wrong. Using Group is just an monstrous abuse of syntax. It's not needed. I don't think there is a great need for nested groupings, but if so it is easy to make ';' work. Do your really think that Group!() is any different than `;` as far as logic goes? If so then you really need to learn to think abstractly. This is like saying that there is a difference between using () or {} as groupings. There is no semantic difference except what you choose to put on it. Hell we could use ab for grouping symbols. Group!() and (); are the same except one is shorter and IMO more convienent... there is otherwise, no other difference. to see this, x4 can be written as A!(int, 0, float, (ubyte, "m", float[2], ((int,11,12), (float,21,22)))) x4; Note, all I did was delete Group!. IT IS HAS THE EXACT SAME LOGICAL INTERPRETATION. Just because it is more confusing for you does mean anything except you need to try harder. In this case, there is no need to use `;` because there is no group separation(in your definition of A). I would prefer to write it as A!(int, 0, float, (ubyte, "m", float[2], (int,11,12; float,21,22))) x4; As I can see the groups easier. In this case the ; serves only to distinguish linear groupings, not nested ones as it can't do this... brackets must be used. Linear groupings(sequential groups) are what is going to be used most of the time. I did not not have the need for nesting groups so didn't use brackets but it would be something needed for some. I don't think there would be a huge reason to have nested groupings since it is generally a compile time construct but I suppose in some instances it could be useful. e.g., key value pairs: ((k1, v1), (k2, v2), ...) but even then one could just write it (k1, v1; k2, v2; ....) The main point is that what you are trying to offer does not simplify things... and simplification is what is important. D can already do what is required in a roundabout way but it requires extra work and is more verbose(which I think, in general, is bad). I'd rather have something like # instead of group. e.g., Just because you add some symbol in front of brackets does not magically make anything you do different... just extra typing. > A!(int, 0, float, #(ubyte, "m", float[2], #(#(int,11,12), #(float,21,22)))) x4; But there should be no need for # as there is no need for Group. (again, I'm not talking about what D can do but what D should do) |
August 11, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to Artur Skawina | Guys, stop feeding the stupid troll now. He is not worth anyone's time. |
August 11, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Sunday, 11 August 2013 at 03:14:46 UTC, Timon Gehr wrote:
> Guys, stop feeding the stupid troll now. He is not worth anyone's time.
Yeah, who's the troll? Variadic grouping is useless says the troll.
|
August 11, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | > Group!() and (); are the same except one is shorter and IMO more convienent... there is otherwise, no other difference.
Except, of course, the fact that one requires a language change and the other doesn't.
|
August 11, 2013 Re: Variadic grouping | ||||
---|---|---|---|---|
| ||||
Posted in reply to jerro | On Sunday, 11 August 2013 at 08:32:35 UTC, jerro wrote:
>> Group!() and (); are the same except one is shorter and IMO more convienent... there is otherwise, no other difference.
>
> Except, of course, the fact that one requires a language change and the other doesn't.
and? How many language changes were done to D to make things more convienent? I didn't ask about how to do Variadic grouping but mentioned it as a feature for D.
"This can be done by making a symbol and breaking up a single
variadic but is messy."
Using Group is messy. I know some people like messy code but that shouldn't require everyone to write messy code.
|
Copyright © 1999-2021 by the D Language Foundation