Array literals' default type

Don nospam at nospam.com
Wed Oct 14 00:01:42 PDT 2009


Ellery Newcomer wrote:
> Bill Baxter wrote:
>>> foo((1,2)); // um, what?
>> You see that kind of thing in Python all the time, with NumPy at
>> least.  Array dimensions for example are set with a tuple.  So
>>    x = array((1,2), dtype=int)
>> And very common to see things like numpy.zeros((10,20)).
> 
> This is one place [of many] where you can't say, "Oh, leave off the
> parens and it's a comma exp". That leaves me in the lurch.
> 
>>> When offered semantic ambiguity, just say no.
>> You didn't really show any examples of ambiguity that I could see.
>> Some of those examples may have a legal meaning in C, so that's an
>> issue if so.
>>
> 
> If you try to add tuple expressions AND keep comma expressions, you
> either can't recurse from paren exp to comma exp (or any exp, really) or
> you have semantic ambiguity. If you can't recurse comma exps, they're
> nothing more than semicolons. Worthless, so you might as well remove them.
> 
> Or you have to introduce a new syntax.
> 
> <aside>
> 
> Actually, making comma exp a little uglier might be an appealing
> solution. something like
> 
> CommaExp -> , CommaExp
> CommaExp -> AsgExp
> 
> gives you
> 
> auto a = (,1,2); // a = 2
> auto a = (1,2); // a = (1,2)
> 
> You still have the problem of ( nonCommaExp ), though. And
> user-friendliness issues.
> 
> I'm sure others could think of better ideas.

You do NOT need to keep the comma operator. What you do need to do, 
though, is make sure that any use of , doesn't silently produce 
different behaviour to what it would do in C.



More information about the Digitalmars-d mailing list