August 09, 2003 Re: Associative Array Literal Syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:bh38pd$2hhg$1@digitaldaemon.com... > > "Julio César Carrascal Urquijo" <adnoctum@phreaker.net> wrote in message news:bddhhf$bqj$1@digitaldaemon.com... > > > why not simple assignment operator? > > > > > > myArray = {"red" = "ff0000", // ... > > > > > > Since structs are initialized with the ":" operator associative arrays should to > > > > char[char[]] myArray = [ > > "red": "ff0000", > > "green": "00ff00", > > ... > > ] > > I think it's a good syntax too. > why not the perl/php syntax (and isn't it char[][key_type] for a assoc array (key of char[]) of arrays of char ??) char[][char[]] myArray = [ "red" => "ff0000", "green" => "00ff00" ]; I don't object to the ':' and can see the consistency, seems to me that if another lang (derived from the same roots) has a syntax for something it seems better to copy it unmodified (as long as it fits). |
August 10, 2003 Re: Associative Array Literal Syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | "Mike Wynn" <mike.wynn@l8night.co.uk> wrote in message news:bh3ggq$2obn$1@digitaldaemon.com... > > "Walter" <walter@digitalmars.com> wrote in message news:bh38pd$2hhg$1@digitaldaemon.com... > > > > "Julio César Carrascal Urquijo" <adnoctum@phreaker.net> wrote in message news:bddhhf$bqj$1@digitaldaemon.com... > > > > why not simple assignment operator? > > > > > > > > myArray = {"red" = "ff0000", // ... > > > > > > > > > Since structs are initialized with the ":" operator associative arrays should to > > > > > > char[char[]] myArray = [ > > > "red": "ff0000", > > > "green": "00ff00", > > > ... > > > ] > > > > I think it's a good syntax too. > > > why not the perl/php syntax > (and isn't it char[][key_type] for a assoc array (key of char[]) of arrays > of char ??) > char[][char[]] myArray = [ > "red" => "ff0000", > "green" => "00ff00" > ]; > > I don't object to the ':' and can see the consistency, seems to me that if > another lang (derived from the same roots) has a syntax for something it > seems better to copy it unmodified (as long as it fits). => would work, but I think the consistency of : gives it a slight edge. |
August 10, 2003 Re: Associative Array Literal Syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter |
>>I don't object to the ':' and can see the consistency, seems to me that
>
> if
>
>>another lang (derived from the same roots) has a syntax for something it
>>seems better to copy it unmodified (as long as it fits).
>
>
> => would work, but I think the consistency of : gives it a slight edge.
>
>
I tend to agree with Walter (how can I go wrong? ;).
'=>' does not feel consistant with a language like D, though it does look attractive. It seems like something Ada would have. A colon feels more natural and C-like. It's used in the 'case' and 'goto' statements (and ?:). It just feels more fitting to the associative array context where an effect is being related to a cause.
Later,
John
|
Copyright © 1999-2021 by the D Language Foundation