Thread overview
[phobos] phobos commit, revision 1516
May 17, 2010
dsource.org
May 22, 2010
Masahiro Nakagawa
May 17, 2010
phobos commit, revision 1516


user: Masahiro Nakagawa

msg:
Add tie to std.typecons

http://www.dsource.org/projects/phobos/changeset/1516

May 22, 2010
I don't think tie() is good for us, sorry for not voicing this earlier.

Since it takes the addresses of references and it escapes them into a struct for later use, it is inherently unsafe.

I suggest we replace tie() with a typesafe alternative, for example scatter(). Instead of

int    n;
double d;
tie(n, d) = tuple(10, 3.14);
assert(n == 10);
assert(d == 3.14);

we have the safe alternative:

int    n;
double d;
scatter(tuple(10, 3.14), n, d);
assert(n == 10);
assert(d == 3.14);


What do you all think?

Andrei


On 05/17/2010 11:19 AM, dsource.org wrote:
> phobos commit, revision 1516
>
>
> user: Masahiro Nakagawa
>
> msg:
> Add tie to std.typecons
>
> http://www.dsource.org/projects/phobos/changeset/1516
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
May 23, 2010
How does scatter deal with nested Tuple?


On Sat, 22 May 2010 23:16:34 +0900, Andrei Alexandrescu <andrei at erdani.com> wrote:

> I don't think tie() is good for us, sorry for not voicing this earlier.
>
> Since it takes the addresses of references and it escapes them into a struct for later use, it is inherently unsafe.
>
> I suggest we replace tie() with a typesafe alternative, for example scatter(). Instead of
>
> int    n;
> double d;
> tie(n, d) = tuple(10, 3.14);
> assert(n == 10);
> assert(d == 3.14);
>
> we have the safe alternative:
>
> int    n;
> double d;
> scatter(tuple(10, 3.14), n, d);
> assert(n == 10);
> assert(d == 3.14);
>
>
> What do you all think?
>
> Andrei
>
>
> On 05/17/2010 11:19 AM, dsource.org wrote:
>> phobos commit, revision 1516
>>
>>
>> user: Masahiro Nakagawa
>>
>> msg:
>> Add tie to std.typecons
>>
>> http://www.dsource.org/projects/phobos/changeset/1516
>>
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
May 22, 2010
On 05/22/2010 11:51 AM, Masahiro Nakagawa wrote:
> How does scatter deal with nested Tuple?

It's a good question. I didn't take the scatter idea too far, and I haven't thought of how additional extras could be implemented.

All I'm saying is that tie() will be unusable in all safe D programs, and therefore we should be looking at alternative abstractions.


Andrei