A few simple syntactic proposals

Robert Fraser fraserofthenight at gmail.com
Thu Apr 17 01:27:40 PDT 2008


Jason House wrote:
> Robert Fraser wrote:
>> 3. String literals should be typed as dynamic arrays. This would mean
>> that "foo" would be of type invariant(char)[] not type
>> invariant(char)[3u] . Note that this would have the disadvantage of
>> requiring an explicit cast if the string literal were to be needed as a
>> static array, but how many times have you actually used a string literal
>> to initialize a static array (or used a static array at all...?)
> 
> I'm not vetoing this, but I will say that I don't really appreciate why this
> is a problem.  I also wonder if there's a more generic problem about
> handling of static vs. dynamic arrays.

There are major static array problems, and I actually created this topic 
so that someone with more experience working with D than I have can come 
and suggest the _real_ fixes that are needed.

The only time I've run into the problem is in array declarations, but I 
know it's also a problem for template metaprogramming. An example of the 
array thing is declaring a literal array of strings:

auto cities = [ "New York", "London", "Paris", "Tokyo" ]

This will fail to compile notmally. You need to use:


auto cities = [ "New York"[], "London", "Paris", "Tokyo" ]

... but this is something that might trip a new user up.



More information about the Digitalmars-d mailing list