December 22, 2020
On Tuesday, 22 December 2020 at 15:31:06 UTC, Rekel wrote:

>
> Don't take that as a defence of changing pointer syntax by the way, just noting I think the argument pointers and arrays should be defined using a similar syntax is not consistent when thinking about indexing & dereferencing.
>
> Besides, I think '[4]foo* foos;' is quite clear.
> "array of foo pointers" seems very natural to me.

Ugh. No thanks :-) My brain would short circuit every time I see it.
December 22, 2020
On 12/22/20 6:35 AM, ag0aep6g wrote:

> Flip the pointer syntax, too:
>
>      *Foo a; /* a pointer to a Foo */

I am not a language expert but I think that would make D's parsing complicated (like C++'s < token) because * already means "derefence" in that position. So, the parser would see *Foo as a potential compilation error but would have to parse forward, etc.

>    [4]Foo b; /* an array of four Foos */

[4] already has a meaning. ;)

> [][4]Foo c; /* a dynamic array of arrays of four Foos each */

I've just learned that the type of [] is void[]. Huh...

> But now we're no longer C-like, I guess.x

Ali

December 22, 2020
On 12/22/20 8:56 AM, Ali Çehreli wrote:

> * already means "derefence"

"dereference"

>  > But now we're no longer C-like, I guess.x

That x seems to be due to my fat Emacs fingers.

Ali


December 22, 2020
On Tuesday, 22 December 2020 at 16:56:18 UTC, Ali Çehreli wrote:
> On 12/22/20 6:35 AM, ag0aep6g wrote:
>
> > Flip the pointer syntax, too:
> >
> >      *Foo a; /* a pointer to a Foo */
>
> I am not a language expert but I think that would make D's parsing complicated (like C++'s < token) because * already means "derefence" in that position. So, the parser would see *Foo as a potential compilation error but would have to parse forward, etc.

I'm not seriously suggesting changing D's syntax. The current syntax is fine with me.

`Foo* a;` is already "complicated", though. `*` can also mean multiplication in that position:

----
struct F
{
    F opBinary(string op : "*")(F a) { return F(); }
    void opBinary(string op : "+")(int a) { import std.stdio; writeln("Hello, world!"); }
}
void main()
{
    F Foo;
    F a;
    Foo* a + 1; /* prints "Hello, world!" */
}
----

That's a convoluted example, of course. But it shows that the compiler already has to look ahead to decide what the `*` means. It doesn't just go "That's a type!" when it sees "Foo*".
December 22, 2020
On Tuesday, 22 December 2020 at 16:56:18 UTC, Ali Çehreli wrote:
> >    [4]Foo b; /* an array of four Foos */
>
> [4] already has a meaning. ;)

It  does in that context? Do tell, I'm unaware.

Also, is it possible to move entire thread to a different forum group? 😂
This feels more like a discussion fit for 'general'.
December 22, 2020
On Tuesday, 22 December 2020 at 16:55:40 UTC, Mike Parker wrote:
> On Tuesday, 22 December 2020 at 15:31:06 UTC, Rekel wrote:
>
>>
>> Don't take that as a defence of changing pointer syntax by the way, just noting I think the argument pointers and arrays should be defined using a similar syntax is not consistent when thinking about indexing & dereferencing.
>>
>> Besides, I think '[4]foo* foos;' is quite clear.
>> "array of foo pointers" seems very natural to me.
>
> Ugh. No thanks :-) My brain would short circuit every time I see it.

I take it you're not open to considering [4]*foo either?
I feel like there are quite strong argument for it, regarding readability & (definition vs operator) consistency.😅
December 22, 2020
On 12/22/20 10:53 AM, Rekel wrote:> On Tuesday, 22 December 2020 at 16:56:18 UTC, Ali Çehreli wrote:
>> >    [4]Foo b; /* an array of four Foos */
>>
>> [4] already has a meaning. ;)
>
> It  does in that context? Do tell, I'm unaware.

An array literal with a single int element 4:

  pragma(msg, typeof([4]));

prints int[].

> Also, is it possible to move entire thread to a different forum group? 😂
> This feels more like a discussion fit for 'general'.

I've seen others "cross reference" to other threads perhaps by CC'ing the other newsgroup as well. (In case it's not obvious, these are newsgroups with a "forum" interface.)

Ali


1 2 3
Next ›   Last »