Jump to page: 1 2 3
Thread overview
October 05

Why is this allowed


struct EntityDef
{
    struct
    {
        int hp;
    }
}

But not this fucking thing?

struct EntityDef
{
    struct
    {
        int hp;
    } stats;
}

Let me name my shit

No, i don't want to do:

struct EntityDef
{
    struct Stats
    {
        int hp;
    } Stats stats;
}

Repeating the same name 3 times, i should go back to the stone age too no?

C and all other C like languages allow me to be concise

Why is it a D thing to be backward?

October 05
I don't know why it isn't supported.

Its very useful with bindings to C.

The parser should be able to swap it to a named instance with a generated name.

October 05
On Saturday, 5 October 2024 at 06:43:00 UTC, Richard (Rikki) Andrew Cattermole wrote:
> I don't know why it isn't supported.
>
> Its very useful with bindings to C.
>
> The parser should be able to swap it to a named instance with a generated name.

Let's PR and let's merge
October 05

On Saturday, 5 October 2024 at 06:35:57 UTC, ryuukk_ wrote:

>

No, i don't want to do:

struct EntityDef
{
    struct Stats
    {
        int hp;
    } stats;
}

Repeating the same name 3 times, i should go back to the stone age too no?

C and all other C like languages allow me to be concise

Why is it a D thing to be backward?

In the coding scheme, fields/members/methods may be at the beginning, middle, or end of the structure, or may not be identifiers to the right of the anonymous structs. In structures, a lot (I wish it was in bitfield) has been taken from C. Especially not using typedef and not having extra semicolons make D stand out even with these. As for anonymous structures, they have to be like this in order to be used with unions.

I think everything is as it should be, and even more: Please include the relevant comment line (the // characters next to the anonymous struct) in the code and be amazed by the change :)

struct Foo
{
    int bar;

    //struct {/*
    Baz baz;
    struct Baz
    {
        auto opAssign(int value)
          => baz = value;//*/
        int baz;
    }
}

void main()
{
    Foo foo;
    foo.bar = 7;
    foo.baz = 42;
    
    imported!"std.stdio".writeln(foo); /*
    with opAssign()      Anonymous
    Foo(7, Baz(42))  or  Foo(7, 42)    */
}

Thank you to the creators and maintainers of the D.

SDB@79

October 05

On Saturday, 5 October 2024 at 06:35:57 UTC, ryuukk_ wrote:

>

Why is this allowed


struct EntityDef
{
    struct
    {
        int hp;
    }
}

But not this fucking thing?

struct EntityDef
{
    struct
    {
        int hp;
    } stats;
}

Let me name my shit

No, i don't want to do:

struct EntityDef
{
    struct Stats
    {
        int hp;
    } Stats stats;
}

Repeating the same name 3 times, i should go back to the stone age too no?

C and all other C like languages allow me to be concise

Why is it a D thing to be backward?

It’s the semicolon. As soon as the closing brace, the declaration is over. You would have to invent new syntax.

-Steve

October 05
On Saturday, 5 October 2024 at 10:35:30 UTC, ryuukk_ wrote:
> On Saturday, 5 October 2024 at 06:43:00 UTC, Richard (Rikki) Andrew Cattermole wrote:
>> I don't know why it isn't supported.
>>
>> Its very useful with bindings to C.
>>
>> The parser should be able to swap it to a named instance with a generated name.
>
> Let's PR and let's merge

btw not new topic..
https://forum.dlang.org/thread/pblaqxrrjypswtmtnjhd@forum.dlang.org?page=1

But I think you will need a DIP for that
October 05

On Saturday, 5 October 2024 at 16:40:46 UTC, Salih Dincer wrote:

>

On Saturday, 5 October 2024 at 06:35:57 UTC, ryuukk_ wrote:

>

No, i don't want to do:

struct EntityDef
{
    struct Stats
    {
        int hp;
    } stats;
}

Repeating the same name 3 times, i should go back to the stone age too no?

C and all other C like languages allow me to be concise

Why is it a D thing to be backward?

In the coding scheme, fields/members/methods may be at the beginning, middle, or end of the structure, or may not be identifiers to the right of the anonymous structs. In structures, a lot (I wish it was in bitfield) has been taken from C. Especially not using typedef and not having extra semicolons make D stand out even with these. As for anonymous structures, they have to be like this in order to be used with unions.

I think everything is as it should be, and even more: Please include the relevant comment line (the // characters next to the anonymous struct) in the code and be amazed by the change :)

struct Foo
{
    int bar;

    //struct {/*
    Baz baz;
    struct Baz
    {
        auto opAssign(int value)
          => baz = value;//*/
        int baz;
    }
}

void main()
{
    Foo foo;
    foo.bar = 7;
    foo.baz = 42;
    
    imported!"std.stdio".writeln(foo); /*
    with opAssign()      Anonymous
    Foo(7, Baz(42))  or  Foo(7, 42)    */
}

Thank you to the creators and maintainers of the D.

SDB@79

I literally don't understand what your code does

I'm not sure this is related to my suggestion

October 06
On Saturday, 5 October 2024 at 17:41:13 UTC, Sergey wrote:
> On Saturday, 5 October 2024 at 10:35:30 UTC, ryuukk_ wrote:
>> On Saturday, 5 October 2024 at 06:43:00 UTC, Richard (Rikki) Andrew Cattermole wrote:
>>> I don't know why it isn't supported.
>>>
>>> Its very useful with bindings to C.
>>>
>>> The parser should be able to swap it to a named instance with a generated name.
>>
>> Let's PR and let's merge
>
> btw not new topic..
> https://forum.dlang.org/thread/pblaqxrrjypswtmtnjhd@forum.dlang.org?page=1
>
> But I think you will need a DIP for that

There is no need for a DIP to be able to name something

Whoever knows how to do it, just submit a PR, we'll discuss there

Notice, what happened to those people in that linked thread? Yeah right..

October 06

On Saturday, 5 October 2024 at 17:26:59 UTC, Steven Schveighoffer wrote:

>

On Saturday, 5 October 2024 at 06:35:57 UTC, ryuukk_ wrote:

>

Why is this allowed


struct EntityDef
{
    struct
    {
        int hp;
    }
}

But not this fucking thing?

struct EntityDef
{
    struct
    {
        int hp;
    } stats;
}

Let me name my shit

No, i don't want to do:

struct EntityDef
{
    struct Stats
    {
        int hp;
    } Stats stats;
}

Repeating the same name 3 times, i should go back to the stone age too no?

C and all other C like languages allow me to be concise

Why is it a D thing to be backward?

It’s the semicolon. As soon as the closing brace, the declaration is over. You would have to invent new syntax.

-Steve

There is no new syntax to invent

instead of writing this error:

onlineapp.d(8): Error: no identifier for declarator `stats`

you generate a random identifier and assign it

    extern(D) static Identifier generateAnonymousId(const(char)[] name)

https://github.com/dlang/dmd/blob/master/compiler/src/dmd/identifier.d#L165

I'm very far from being bright, but i know simple logic

October 06

On Saturday, 5 October 2024 at 17:26:59 UTC, Steven Schveighoffer wrote:

>

It’s the semicolon. As soon as the closing brace, the declaration is over. You would have to invent new syntax.

Maybe type tuple syntax will support this:

struct EntityDef
{
    (int hp) stats;
}

EntityDef ed;
int x = ed.stats.hp;
« First   ‹ Prev
1 2 3