Jump to page: 1 212  
Page
Thread overview
Tuple DIP
Jan 12, 2018
Timon Gehr
Jan 12, 2018
Timon Gehr
Jan 12, 2018
Timon Gehr
Jan 12, 2018
Basile B.
Jan 13, 2018
Timon Gehr
Jan 13, 2018
Mark
Jan 13, 2018
Timon Gehr
Jan 13, 2018
Mark
Jan 13, 2018
Chris M.
Jan 13, 2018
Nordlöw
Jan 13, 2018
Rubn
Jan 13, 2018
rikki cattermole
Jan 13, 2018
SrMordred
Jan 13, 2018
jmh530
Jan 13, 2018
Basile B.
Jan 13, 2018
Basile B.
Jan 13, 2018
Basile B.
Jan 13, 2018
jmh530
Jan 13, 2018
Timon Gehr
Jan 13, 2018
Jacob Carlborg
Jan 13, 2018
Timon Gehr
Jan 13, 2018
Ilya Yaroshenko
Jan 13, 2018
Mengu
Jan 13, 2018
Timothee Cour
Jan 13, 2018
Timon Gehr
Jan 13, 2018
Timothee Cour
Jan 13, 2018
Timon Gehr
Sep 20, 2018
Guillaume Boucher
Jun 03, 2019
Timon Gehr
Jun 03, 2019
Exil
Jun 03, 2019
Timon Gehr
Jun 04, 2019
Jacob Carlborg
Jun 05, 2019
Guillaume Boucher
Jan 13, 2018
aberba
Jan 13, 2018
rjframe
Jan 13, 2018
Timon Gehr
Jan 13, 2018
rjframe
Jan 13, 2018
rjframe
Jan 13, 2018
Mark
Jan 13, 2018
Timon Gehr
Jan 13, 2018
Timon Gehr
Jan 13, 2018
MrSmith
Jan 13, 2018
Timothee Cour
Jan 13, 2018
Timothee Cour
Jan 13, 2018
Timon Gehr
Feb 16, 2018
Martin Nowak
Feb 16, 2018
Jonathan M Davis
Feb 17, 2018
Timon Gehr
Feb 16, 2018
H. S. Teoh
Feb 17, 2018
Timon Gehr
Feb 17, 2018
Timon Gehr
Jan 13, 2018
Timothee Cour
Jan 14, 2018
rikki cattermole
Jan 14, 2018
Q. Schroll
Jan 14, 2018
Q. Schroll
Jan 14, 2018
Timon Gehr
Jan 14, 2018
Timothee Cour
Jan 14, 2018
Timon Gehr
Jan 14, 2018
Timothee Cour
Feb 16, 2018
Martin Nowak
Jan 15, 2018
Walter Bright
Jan 23, 2018
Atila Neves
Jan 23, 2018
Atila Neves
Re: Tuple DIP - tuple unification with arrays and structs
Jan 15, 2018
Walter Bright
Jan 16, 2018
aliak
Jan 16, 2018
Timon Gehr
Jan 16, 2018
jmh530
Jan 16, 2018
Timon Gehr
Jan 17, 2018
aliak
Jan 17, 2018
Guillaume Boucher
Jan 17, 2018
Timon Gehr
Mar 15, 2018
Nick Treleaven
Mar 15, 2018
Timon Gehr
May 02, 2018
Timon Gehr
Jan 17, 2018
Manu
Jan 17, 2018
Timon Gehr
Jan 31, 2018
Seb
Feb 16, 2018
Martin Nowak
Feb 17, 2018
Timon Gehr
Feb 19, 2018
timotheecour
Feb 19, 2018
Timon Gehr
Feb 19, 2018
Timon Gehr
Feb 19, 2018
Timothee Cour
Feb 20, 2018
Timon Gehr
Feb 20, 2018
Timothee Cour
Feb 20, 2018
Timon Gehr
Mar 15, 2018
ixid
Mar 15, 2018
Timon Gehr
Mar 15, 2018
JN
Mar 15, 2018
Stefan Koch
Mar 15, 2018
Seb
Jun 26, 2018
Francesco Mecca
Jun 27, 2018
12345swordy
Jun 28, 2018
Timon Gehr
Jul 03, 2018
12345swordy
Sep 19, 2018
12345swordy
Sep 19, 2018
Timon Gehr
Sep 22, 2018
12345swordy
Jun 03, 2019
ixid
Jun 03, 2019
Timon Gehr
Nov 18, 2020
Andre Pany
Jan 01, 2021
Rekel
Jan 02, 2021
aberba
Jan 03, 2021
Paul
Jan 03, 2021
Timon Gehr
Jan 03, 2021
Paul Backus
Jan 03, 2021
Andre Pany
Jan 03, 2021
aberba
Jan 05, 2021
12345swordy
Jan 09, 2021
Imperatorn
Jan 09, 2021
12345swordy
Jan 09, 2021
Imperatorn
Jan 10, 2021
aberba
Jan 11, 2021
angel
Jan 11, 2021
Meta
January 12, 2018
As promised [1], I have started setting up a DIP to improve tuple ergonomics in D:

https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md


This DIP aims to make code like the following valid D:

---
auto (a, b) = (1, 2);
(int a, int b) = (1, 2);
---

---
foreach((sum, diff); [(1, 2), (4, 3)].map!((a, b) => (a + b, a - b)))
{
    writeln(sum, " ", diff);
}
/+ prints:
3 -1
7 1
+/
---

Before going ahead with it, I'd like some preliminary community input:

- I'm not yet completely satisfied with the DIP.
  (See section "Limitations".)
  Please let me know suggestions or further concerns you might have.


- There are good example use cases missing. While I'm confident I could
  invent a few of them given a little time, I thought maybe I can
  expedite the process and make the point more convincingly by asking
  for use cases you encountered in your own code. The DIP already
  contains an example due to bearophile.


[1] https://forum.dlang.org/post/or625h$2hns$1@digitalmars.com
January 12, 2018
On 12.01.2018 23:44, Timon Gehr wrote:
> ...
> 
> Before going ahead with it, I'd like some preliminary community input:
> ...
Also, if you have more links to forum posts requesting related features, that would be useful (googling turned up the ones that are in the DIP, but I know that there were more).
January 12, 2018
On 12.01.2018 23:44, Timon Gehr wrote:
> 
> ---
> auto (a, b) = (1, 2);
> (int a, int b) = (1, 2);
> ---

(The two lines are two independent examples :o).)
January 12, 2018
On Friday, 12 January 2018 at 22:44:48 UTC, Timon Gehr wrote:
> As promised [1], I have started setting up a DIP to improve tuple ergonomics in D:
>
> https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md

markdown trick: you can use


```diff
```

for a nicer grammar section.
January 13, 2018
On Friday, 12 January 2018 at 22:44:48 UTC, Timon Gehr wrote:
> As promised [1], I have started setting up a DIP to improve tuple ergonomics in D:
>
> https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md
>
>
> This DIP aims to make code like the following valid D:
>
> ---
> auto (a, b) = (1, 2);
> (int a, int b) = (1, 2);
> ---
>
> ---
> foreach((sum, diff); [(1, 2), (4, 3)].map!((a, b) => (a + b, a - b)))
> {
>     writeln(sum, " ", diff);
> }
> /+ prints:
> 3 -1
> 7 1
> +/
> ---
>
> Before going ahead with it, I'd like some preliminary community input:
>
> - I'm not yet completely satisfied with the DIP.
>   (See section "Limitations".)
>   Please let me know suggestions or further concerns you might have.
>
>
> - There are good example use cases missing. While I'm confident I could
>   invent a few of them given a little time, I thought maybe I can
>   expedite the process and make the point more convincingly by asking
>   for use cases you encountered in your own code. The DIP already
>   contains an example due to bearophile.
>
>
> [1] https://forum.dlang.org/post/or625h$2hns$1@digitalmars.com

Could we also support function tuples? For instance:

int sum(int a, int b) { return a+b; }
int diff(int a, int b) { return a-b; }

(int, int) f = (sum, diff) // no ";" for consistency with existing syntax
int (x,y) = f(1, 2); // x=3, y=-1
int (w,z) = (1, 2).f() // same as above, UFCS
int (u,v) = (1, 2).(sum, diff) // same as above, "lambda tuple"

In the last example, (sum, diff) is basically lowered to (x,y) => (sum(x,y), diff(x,y)).
January 13, 2018
On 13.01.2018 00:16, Basile B. wrote:
> On Friday, 12 January 2018 at 22:44:48 UTC, Timon Gehr wrote:
>> As promised [1], I have started setting up a DIP to improve tuple ergonomics in D:
>>
>> https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md
> 
> markdown trick: you can use
> 
> 
> ```diff
> ```
> 
> for a nicer grammar section.

Updated, thanks!
January 13, 2018
On Friday, 12 January 2018 at 22:44:48 UTC, Timon Gehr wrote:
> As promised [1], I have started setting up a DIP to improve tuple ergonomics in D:
>
> [...]

Yes please
January 13, 2018
Should include an example of returning a tuple from a function. I know one of the pains with variadic templates is that they can't be returned.

So maybe something that goes over the following use case:


auto returnTuple(Args...)(Args args)
{
    return args;
}


(int a, float b) = returnTuple(4, 1.0f);


Or just returning your regular tuple:


(int, float) returnSomeTuple()
{
    return (10, 1.0f); // or whatever
}

January 13, 2018
On 13.01.2018 01:20, Mark wrote:
> 
> Could we also support function tuples?

In principle, yes, though I imagine it is a lot harder to argue for its inclusion than for that of the features currently proposed in the DIP, because existing language features already come rather close.

> For instance:
> 
> int sum(int a, int b) { return a+b; }
> int diff(int a, int b) { return a-b; }
> 
> (int, int) f = (sum, diff) // no ";" for consistency with existing syntax

No ";" is inconsistent. Also the type of f cannot be (int, int), and (sum, diff) would try to call sum and diff with 0 arguments and fail.

> int (x,y) = f(1, 2); // x=3, y=-1
> int (w,z) = (1, 2).f() // same as above, UFCS
> int (u,v) = (1, 2).(sum, diff) // same as above, "lambda tuple"
> 
> In the last example, (sum, diff) is basically lowered to (x,y) => (sum(x,y), diff(x,y)).

I think this is easy enough to achieve without dedicated syntax:

import std.typecons;

template apply(F...){
    auto apply(T)(T arg){
        import std.conv, std.range, std.algorithm;
        return mixin(text("(",iota(F.length).map!(i=>text("F[",i,"](arg)")).join(","),")"));
    }
}

void main(){
    int sum(int a, int b) { return a+b; }
    int diff(int a, int b) { return a-b; }
    auto (u,v)=(1,2).apply!(sum, diff);
    import std.stdio;
    writeln(u," ",v);
}
January 13, 2018
On 12/01/2018 10:44 PM, Timon Gehr wrote:
> As promised [1], I have started setting up a DIP to improve tuple ergonomics in D:
> 
> https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md
> 
> 
> This DIP aims to make code like the following valid D:
> 
> ---
> auto (a, b) = (1, 2);
> (int a, int b) = (1, 2);
> ---
> 
> ---
> foreach((sum, diff); [(1, 2), (4, 3)].map!((a, b) => (a + b, a - b)))
> {
>      writeln(sum, " ", diff);
> }
> /+ prints:
> 3 -1
> 7 1
> +/
> ---
> 
> Before going ahead with it, I'd like some preliminary community input:
> 
> - I'm not yet completely satisfied with the DIP.
>    (See section "Limitations".)
>    Please let me know suggestions or further concerns you might have.
> 
> 
> - There are good example use cases missing. While I'm confident I could
>    invent a few of them given a little time, I thought maybe I can
>    expedite the process and make the point more convincingly by asking
>    for use cases you encountered in your own code. The DIP already
>    contains an example due to bearophile.
> 
> 
> [1] https://forum.dlang.org/post/or625h$2hns$1@digitalmars.com

I really dislike the syntax, it looks hard to parse.

#{int, string}

Where T... all equal types

#{1, "str"}

Where T... all equal values
Alternatively:

#(1, "str")

Since it is "arguments" to "construct" it.
Doesn't that look easier to parse and use?


It can be just a bit of syntax suger around (in object.di):

struct Tuple(T...) {
	alias Types = T;

	T args;

	// opIndex/opIndexAssign
}
« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11