auto arr = [1, 2, 3] should be a static array, not a GC allocated array

H. S. Teoh hsteoh at qfbox.info
Thu Jul 14 18:29:43 UTC 2022


On Thu, Jul 14, 2022 at 10:57:13AM -0700, Ali Çehreli via Digitalmars-d wrote:
> On 7/14/22 09:50, jfondren wrote:
> 
> > inferred length with a feature like `int[_] arr`.
> 
> Is there a reason why that can't be added to D? I don't see any
> downside.[1]
> 
> Ali
> 
> [1] Other than bike-shedding:
> 
> - int[$]      // Not perfect because the array does not have a length
>               // (yet) but $ means exactly that in other contexts.

IMO, this is the best bikeshed color. :-P


> - int[auto]   // Better but 'auto' means "type" to me.
> 
> - int[static] // Aaaah... good old 'static' to the rescue. :D

Argh, please no!! `static` is already overloaded too much in D, please
don't make it worse.


> - int[{}]     // Meaning "take the length from the initializer".
>               // (Yes, I am joking.)

This one made me cringe. :-/


> - int[=]      // Because this is initialization after all.
> 
> - int[+]      // Meaning: "Please count for me."

These are bad for the parser, because the current language expects a
numerical expression between the [].


> - int[∑1]     // Ditto but because not all keyboards have that
>               // character, the alternative tetragraph is proposed
>               // below.
> 
> - int[???<1]  // Readable enough? :o)

OK, either you're pulling my leg, or I must have missed some memo about
... I dunno what. :-D

//

But anyway, this is by far not the first time this issue has been
brought up, and it's high time we made some progress on it.  Where's the
DIP when you need it?  Actually, I'm almost certain somebody already
wrote the DIP, and IIRC even implemented it in a dmd branch.  We should
resurrect the DIP/implementation and push it through.  It has been too
many years.


T

-- 
"The number you have dialed is imaginary. Please rotate your phone 90 degrees and try again."


More information about the Digitalmars-d mailing list