July 14, 2022

On Thursday, 14 July 2022 at 17:33:22 UTC, bachmeier wrote:

>

On Thursday, 14 July 2022 at 15:26:44 UTC, Dave P. wrote:

>

On Thursday, 14 July 2022 at 14:51:01 UTC, bachmeier wrote:

>

On Thursday, 14 July 2022 at 13:14:59 UTC, ryuukk_ wrote:

>

It is misleading, nobody expect this to be GC allocated
[...]

That would be a potential justification. OP claims nobody would expect a dynamic array, though, and matching C's behavior hardly makes the design choice obvious.

Yes, I forgot to write the other half of my comment. I am also annoyed by this behavior, but I would be able to work around it if there was a convenient way to specify a static array of inferred length. Ansi C has this, D does not.

July 14, 2022
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.

- int[auto]   // Better but 'auto' means "type" to me.

- int[static] // Aaaah... good old 'static' to the rescue. :D

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

- int[=]      // Because this is initialization after all.

- int[+]      // Meaning: "Please count for me."

- int[∑1]     // Ditto but because not all keyboards have that
              // character, the alternative tetragraph is proposed
              // below.

- int[???<1]  // Readable enough? :o)

July 14, 2022

On Thursday, 14 July 2022 at 17:57:13 UTC, Ali Çehreli 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

Unfortunately _ is a valid identifier:

enum _ = 3;
int[_] nums = [1, 2, 3];
assert(_ == 3);
>

[1] Other than bike-shedding:

  • int[$] // Not perfect because the array does not have a length
    // (yet) but $ means exactly that in other contexts.

And enum $ = 3 is an error.

July 14, 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."
July 14, 2022

On Thursday, 14 July 2022 at 17:57:13 UTC, Ali Çehreli 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.

Also think about it this way: If everything was inferenced, there would be no need for a programmer.

Ali's analogies are actually about us programmers being friends with numbers. We need numbers and right on data, to see the truth...

July 14, 2022
On 7/14/22 11:29, H. S. Teoh wrote:

>> - 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.

I don't think 'static' can get any worse. Would the following make this use case stand out more?

  int[static static]  // Oooh! Me likes...

> OK, either you're pulling my leg

Was that too subtle? :) Yes, I was having fun.

Ali

July 14, 2022
On Thu, Jul 14, 2022 at 11:36:20AM -0700, Ali Çehreli via Digitalmars-d wrote:
> On 7/14/22 11:29, H. S. Teoh wrote:
> 
> >> - 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.
> 
> I don't think 'static' can get any worse. Would the following make this use case stand out more?
> 
>   int[static static]  // Oooh! Me likes...

Maybe int[static array] would make it much more obvious to newbies. ;-)


> > OK, either you're pulling my leg
> 
> Was that too subtle? :) Yes, I was having fun.
[...]

Let's bring the fun back to programming(tm)! ;-)


T

-- 
People tell me that I'm skeptical, but I don't believe them.
July 14, 2022
On 7/14/22 11:55, H. S. Teoh wrote:

> Maybe int[static array] would make it much more obvious to newbies. ;-)

Looks good but 'array' is a legal identifier. :( Luckily nothing some creative acrostic can't fix:

  int[static alias,ref,return,assert,'y'] arr;

(Programmers would be free to use any keyword they like.)

That 'y' literal is an obvious eye sore. So we can expand the syntax to specify which character of each keyword is used for the acrostic. I utilize 'static' for that purpose as well:

  // 0-based indexing for consistency
  int[static static(1)
             ,cast
             ,break
             ,private
             ,false
             ,synchronized] arr;
          //   ^
          //   |
          // Character 1 of each keyword reads "array"

Ok, too much silliness for one day. I stop here.

Ali

July 14, 2022
On Thu, Jul 14, 2022 at 12:18:34PM -0700, Ali Çehreli via Digitalmars-d wrote:
> On 7/14/22 11:55, H. S. Teoh wrote:
> 
> > Maybe int[static array] would make it much more obvious to newbies. ;-)
> 
> Looks good but 'array' is a legal identifier. :( Luckily nothing some creative acrostic can't fix:
> 
>   int[static alias,ref,return,assert,'y'] arr;
[...]
> Ok, too much silliness for one day. I stop here.
[...]

But but but... this is proposed syntax for automatically detecting the length of a static array.  At the very least, it should spell out this fact:

	int[auto static pragma(array, length)] arr;

The pragma, of course, is to provide a context where legal identifiers have special meaning. :-D

On a serious note, though, int[$] is ideal.


T

-- 
Music critic: "That's an imitation fugue!"
July 14, 2022

On Thursday, 14 July 2022 at 17:57:13 UTC, Ali Çehreli wrote:

>
  • int[$] // Not perfect because the array does not have a length

I wanted to implement that in my language and found a subtle problem that makes the implementation of the feature a not so nice looking special case : the semantics of int[$] require the initializer unlike auto, which can be directly replaced by the initializer type. That breaks the binary and (somewhat ideal) approach of either auto and replace or full type and implicit conv of the initializer.