July 24, 2012
On Tue, 24 Jul 2012 13:00:44 +0200, Jonathan M Davis <jmdavisProg@gmx.com> wrote:

> On Tuesday, July 24, 2012 11:03:16 Simen Kjaeraas wrote:
>> On Tue, 24 Jul 2012 04:21:18 +0200, Andrei Alexandrescu
>>
>> <SeeWebsiteForEmail@erdani.org> wrote:
>> >> Tuple!(float, "x", float, "y") bar() {
>> >> return typeof(return)( 0.0, 0.0 );
>> >> }
>>
>> [snip]
>>
>> > We could make
>> >
>> > return tuple(0.0, 0.0);
>> >
>> > to work. I can't imagine a scenario in which this relaxation would  
>> cause
>> > a bug.
>>
>> I would argue it should work, for the exact reasons outline above. And as
>> you say, it should cause no bugs.
>>
>> But can it be made to work in current D, as a library solution? Or do you
>> mean the language should be changed? (This looks to me a lot like the old
>> opImplicitCast)
>
> That's what alias this is for.

Well, sorta. See, I'm asking for an unbounded set of possible
conversions, as Tuple!int should be implicitly convertible to
Tuple!(int, "a"), Tuple!(int, "b"), Tuple!(int, "Help"), and
Tuple!(int, "AnotherOneBitesTheDust").

And that's just the ones with int as the first parameter. Then comes
float, double, long, and so on.

I may be wrong, but I don't think alias this can handle that. In fact,
I just tried, and got DMD to hang.

-- 
Simen
July 24, 2012
On 7/24/12 5:03 AM, Simen Kjaeraas wrote:
> On Tue, 24 Jul 2012 04:21:18 +0200, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org> wrote:
>
>>> Tuple!(float, "x", float, "y") bar() {
>>> return typeof(return)( 0.0, 0.0 );
>>> }
> [snip]
>> We could make
>>
>> return tuple(0.0, 0.0);
>>
>> to work. I can't imagine a scenario in which this relaxation would
>> cause a bug.
>
> I would argue it should work, for the exact reasons outline above. And as
> you say, it should cause no bugs.
>
> But can it be made to work in current D, as a library solution? Or do you
> mean the language should be changed? (This looks to me a lot like the old
> opImplicitCast)

Library solution.

Andrei

July 24, 2012
On Monday, 23 July 2012 at 21:14:31 UTC, Simen Kjaeraas wrote:
> On Mon, 23 Jul 2012 22:51:19 +0200, Stuart <stugol@gmx.com> wrote:
>
>> Saves us having to create a struct for every goddamn little function; or using tuples directly, which means we have to refer to variables like .value1 and .value2 instead of something meaningful.
>
> You mean like this?
>
> Tuple!(float, "x", float, "y") bar() {
>     return typeof(return)( 0.0, 0.0 );
> }
>
> auto xCoord = bar().x;

You mean it's already supported? Nice! Although, It'd still be awesome to be able to do things like:

   auto a,b = bar();

   auto c,_ = bar();

July 24, 2012
On Tue, 24 Jul 2012 15:42:19 +0100, Stuart <stugol@gmx.com> wrote:

> On Monday, 23 July 2012 at 21:14:31 UTC, Simen Kjaeraas wrote:
>> On Mon, 23 Jul 2012 22:51:19 +0200, Stuart <stugol@gmx.com> wrote:
>>
>>> Saves us having to create a struct for every goddamn little function; or using tuples directly, which means we have to refer to variables like .value1 and .value2 instead of something meaningful.
>>
>> You mean like this?
>>
>> Tuple!(float, "x", float, "y") bar() {
>>     return typeof(return)( 0.0, 0.0 );
>> }
>>
>> auto xCoord = bar().x;
>
> You mean it's already supported? Nice! Although, It'd still be awesome to be able to do things like:
>
>     auto a,b = bar();
>
>     auto c,_ = bar();

Sadly the comma operator (inherited from C/C++) blocks this syntax.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
July 24, 2012
On Tuesday, 24 July 2012 at 14:50:02 UTC, Regan Heath wrote:
> On Tue, 24 Jul 2012 15:42:19 +0100, Stuart <stugol@gmx.com> wrote:
>
>> You mean it's already supported? Nice! Although, It'd still be awesome to be able to do things like:
>>
>>    auto a,b = bar();
>>
>>    auto c,_ = bar();
>
> Sadly the comma operator (inherited from C/C++) blocks this syntax.

Well, how about "auto {a,b} = ", or "auto [a,b] = ", or something like that?
July 24, 2012
On Tue, Jul 24, 2012 at 03:49:14PM +0100, Regan Heath wrote:
> On Tue, 24 Jul 2012 15:42:19 +0100, Stuart <stugol@gmx.com> wrote:
[...]
> >You mean it's already supported? Nice! Although, It'd still be awesome to be able to do things like:
> >
> >    auto a,b = bar();
> >
> >    auto c,_ = bar();
> 
> Sadly the comma operator (inherited from C/C++) blocks this syntax.
[...]

The comma operator must go.

I know, I know, it ain't gonna happen with D2. One can still hope, though.


T

-- 
To provoke is to call someone stupid; to argue is to call each other stupid.
July 24, 2012
On Tue, 24 Jul 2012 16:42:19 +0200, Stuart <stugol@gmx.com> wrote:

> You mean it's already supported? Nice!

That's what I mean. :p


> Although, It'd still be awesome to be able to do things like:
>
>     auto a,b = bar();
>
>     auto c,_ = bar();

That would be nice, and has been on the table numerous times.
Nothing has yet been implemented, and I don't think even a
syntax has been decided upon, so we might never see that.

The closest thing we have is probably this:

int a = 1;
int b = 3;
TypeTuple!(a,b) = tuple(b,a); // Look ma, I'm swapping!
assert(a == 3);
assert(b == 1);

...which inspired me to write this implementation of fibonacci:

T fib(T = int)(int n, T a = 0, T b = 1) {
    while ( n-- ) {
        TypeTuple!(a,b) = tuple(b, a +b);
    }
    return a;
}

-- 
Simen
July 24, 2012
On 07/24/2012 07:42 AM, Stuart wrote:

> You mean it's already supported? Nice! Although, It'd still be awesome
> to be able to do things like:
>
> auto a,b = bar();
>
> auto c,_ = bar();
>

Works in foreach loops:

    foreach (a, b; hasTupleElements)

The element type of the following range of map results is a tuple:

import std.stdio;
import std.algorithm;

void main()
{
    auto values = [1.25, 2.50, 3.75];
    auto results = map!(a => a / 4, a => a * 10)(values);

    writeln(" Quarters  Ten Times");

    foreach (quarterResult, tenTimesResult; results) {
        writefln("%8.2f%8.2f", quarterResult, tenTimesResult);
    }
}

Ali

July 24, 2012
On 7/24/12, H. S. Teoh <hsteoh@quickfur.ath.cx> wrote:
> The comma operator must go.

The comma operator needs to die a fast but painful death. I've had this sort of bug recently:

int getInt(string op)
{
    if (op, "a")
        return 1;
    else
    if (op == "b")
        return 2;
    else
        return 3;
}

Guess which number it always returns regardless of input.
July 24, 2012
On Tue, 2012-07-24 at 16:59 +0200, Simen Kjaeraas wrote: […]
> ...which inspired me to write this implementation of fibonacci:
> 
> T fib(T = int)(int n, T a = 0, T b = 1) {
>      while ( n-- ) {
>          TypeTuple!(a,b) = tuple(b, a +b);
>      }
>      return a;
> }

Or possibly better:

long fibonacci ( immutable long n ) {
  return array ( takeExactly ( recurrence ! ( "a[n-1] + a[n-2]" ) ( 0L , 1L ) , cast ( size_t ) ( n + 1 ) ) ) [ n ] ;
}

?
-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder