Array literals' default type

Ellery Newcomer ellery-newcomer at utulsa.edu
Tue Oct 13 11:51:22 PDT 2009


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.



More information about the Digitalmars-d mailing list