Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
May 10, 2010 [phobos] tie for std.typecons.Tuple | ||||
---|---|---|---|---|
| ||||
Hi, Currently, Phobos has Tuple but doesn't have tie. So I implemented tie for std.typecons.Tuple. http://www.bitbucket.org/repeatedly/scrap/src/tip/tie_.d Original author is 9rnsr but his version is a bit messy and overkill. I substantially rewrote his tie. - clear syntax (tie(&n, &d) => tie(n, d)) - Implicit conversion I would like to suggest this tie is integrated into phobos. What do you think of this? |
May 10, 2010 [phobos] tie for std.typecons.Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to Masahiro Nakagawa | On Mon, May 10, 2010 at 2:22 PM, Masahiro Nakagawa <repeatedly at gmail.com> wrote:
> Hi,
>
> Currently, Phobos has Tuple but doesn't have tie.
> So I implemented tie for std.typecons.Tuple.
>
> http://www.bitbucket.org/repeatedly/scrap/src/tip/tie_.d
>
> Original author is 9rnsr but his version is a bit messy and overkill.
> I substantially rewrote his tie.
> - clear syntax (tie(&n, &d) => tie(n, d))
> - Implicit conversion
>
> I would like to suggest this tie is integrated into phobos.
>
> What do you think of this?
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
Looks great. Just 2 questions:
1) Does chaining works? I.e.
tie(a, b) = tie(c, d) = tuple(1,2); // a = b = 1, b = c = 2
2) You could probably use __dollar for ignored elements, to prevent
namespace pollution and symbol conflicts:
tie(a, $) = tuple(1, 2); // a = 1
This leads to another idea: Phobos should have struct Dolllar and global __dollar variable so that everyone don't have to redefine it, just import some Phobos module and use it.
|
May 11, 2010 [phobos] tie for std.typecons.Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis | On Mon, 10 May 2010 21:32:00 +0900, Denis <2korden at gmail.com> wrote: > On Mon, May 10, 2010 at 2:22 PM, Masahiro Nakagawa <repeatedly at gmail.com> wrote: >> Hi, >> >> Currently, Phobos has Tuple but doesn't have tie. >> So I implemented tie for std.typecons.Tuple. >> >> http://www.bitbucket.org/repeatedly/scrap/src/tip/tie_.d >> >> Original author is 9rnsr but his version is a bit messy and overkill. >> I substantially rewrote his tie. >> - clear syntax (tie(&n, &d) => tie(n, d)) >> - Implicit conversion >> >> I would like to suggest this tie is integrated into phobos. >> >> What do you think of this? >> > > Looks great. Just 2 questions: > 1) Does chaining works? I.e. > tie(a, b) = tie(c, d) = tuple(1,2); // a = b = 1, b = c = 2 http://www.bitbucket.org/repeatedly/scrap/changeset/e4c270e6c30d Done. > 2) You could probably use __dollar for ignored elements, to prevent > namespace pollution and symbol conflicts: > tie(a, $) = tuple(1, 2); // a = 1 I don't understand this. Please show me example. I tried following code with dmd 2.046 beta: ----- import std.stdio; struct Dollar {} __gshared Dollar __dollar; void main() { writeln($); } // foo.d(8): '$' is valid only inside [] of index or slice ----- Umm... > This leads to another idea: Phobos should have struct Dolllar and global __dollar variable so that everyone don't have to redefine it, just import some Phobos module and use it. I agree. |
May 10, 2010 [phobos] tie for std.typecons.Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to Masahiro Nakagawa | On Mon, May 10, 2010 at 7:44 PM, Masahiro Nakagawa <repeatedly at gmail.com> wrote:
> On Mon, 10 May 2010 21:32:00 +0900, Denis <2korden at gmail.com> wrote:
>
>> 2) You could probably use __dollar for ignored elements, to prevent
>> namespace pollution and symbol conflicts:
>> tie(a, $) = tuple(1, 2); // a = 1
>
> I don't understand this. Please show me example.
> I tried following code with dmd 2.046 beta:
> -----
> import std.stdio;
>
> struct Dollar {}
> __gshared Dollar __dollar;
>
> void main()
> {
> ? ?writeln($);
> }
>
> // foo.d(8): '$' is valid only inside [] of index or slice
> -----
> Umm...
>
My bad, it is indeed disallowed outside of opSlice. Didn't know that.
|
May 29, 2010 [phobos] tie for std.typecons.Tuple | ||||
---|---|---|---|---|
| ||||
Posted in reply to Masahiro Nakagawa | I think tie() should be removed because it is unsafe. Masahiro, could you please look into that?
We should discuss alternative means, but I strongly believe whatever abstractions we add should be, if at all possible, safe. But tie() is not appropriate.
Andrei
On 05/10/2010 05:22 AM, Masahiro Nakagawa wrote:
> Hi,
>
> Currently, Phobos has Tuple but doesn't have tie.
> So I implemented tie for std.typecons.Tuple.
>
> http://www.bitbucket.org/repeatedly/scrap/src/tip/tie_.d
>
> Original author is 9rnsr but his version is a bit messy and overkill.
> I substantially rewrote his tie.
> - clear syntax (tie(&n, &d) => tie(n, d))
> - Implicit conversion
>
> I would like to suggest this tie is integrated into phobos.
>
> What do you think of this?
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
Copyright © 1999-2021 by the D Language Foundation