Alternate declaration syntax

Koroskin Denis 2korden at gmail.com
Sun Apr 13 02:55:33 PDT 2008


On Sun, 13 Apr 2008 12:07:11 +0400, Georg Wrede <georg at nospam.org> wrote:
> Hans W. Uhlig wrote:
>>  I would think something similar to perl would work
>>  {var1, var2, var3} = blah(1,2,3);
>> {int var1, string var2, object var3} = blah(1,2,3);
>>  const blah(int a, int b, int c) returns const int, invariant string,  
>> object {
>>     return 1, "hello", this;
>> }
>
> Well, at first sight, this looks nice.

Doesn't look nice to me. Look at this:

auto t = 1, "hello", this;

What it the t.typeof? Do you think it's {int, string, this.typeof}?
No, it's just this.typeof, because comma is a statement separator in this  
context.
Moreover, I don't think this is consistent:

int i;
string s;
this.typeof t;

{i, s, t} = 1, "hello", this;

Compare to:
{i, s, t} = {1, "hello, "this};

or to:
[i, s, t] = [1, "hello", this];

Anyway, I don't like {} syntax much. I believe, in D it denotes scopes.
Even array initialization moved from C style {1, 2, 3} to D style [1, 2,  
3].

To me, tuples aren't different from arrays. And I would like to operate on  
them like on arrays:

auto t = [1, "hello", this];
auto s = t[0..1]; // s == {1, "hello" }. t{0..1} looks like an ugly  
language hack to me.

Or like this:

{int, int, string} k = [1, 2, "3"];
k[0..1] = [1, 1];   // here it is. What is the type of [1, 1]? I don't  
care!
int[2] i = k[0..1]; // Arrays should be convertible to tuples and  
vice-versa



More information about the Digitalmars-d mailing list