Array literals' default type

Michel Fortin michel.fortin at michelf.com
Sat Oct 10 11:38:38 PDT 2009


On 2009-10-10 12:12:27 -0400, "Lars T. Kyllingstad" 
<public at kyllingen.NOSPAMnet> said:

> Christopher Wright wrote:
>> Don wrote:
>>> At worst, it would be something like:
>>> 
>>> exec("description", createArray(procName, arg1, arg2) ~ generatedArgs ~ 
>>> createArray(arg3, arg4) ~ moreGeneratedArgs);
>> 
>> PHP does this. I haven't used PHP enough to hate it.
> 
> 
> I've used PHP a fair bit, and I don't hate its array syntax at all. 
> (There are plenty of other things in PHP to hate, though.) It's easily 
> readable, and not much of a hassle to write. But array() in PHP isn't a 
> function, it's a language construct with special syntax. To create an 
> AA, for instance, you'd write
> 
>    $colours = array("apple" => "red", "pear" => "green");
> 
> I'm not sure what the D equivalent of that one should be.

Associative array literals:

	string[string] s = ["hello": "world", "foo": "bar"];

Note that an "array" in PHP is always a double-linked list indexed by a 
hash-table. Writing `array(1, 2, 3)` is the same as writing `array(0 => 
1, 1 => 2, 2 => 3)`: what gets constructed is identical. That's quite 
nice as a generic container.



-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list