Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
November 16, 2020 D grammar oddities | ||||
---|---|---|---|---|
| ||||
struct and unions aren't types. function and delegate are not either. According to the grammar. |
November 16, 2020 Re: D grammar oddities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dibyendu Majumdar | On Mon, Nov 16, 2020 at 11:55:29PM +0000, Dibyendu Majumdar via Digitalmars-d wrote: > struct and unions aren't types. > function and delegate are not either. > > According to the grammar. Link? T -- Creativity is not an excuse for sloppiness. |
November 17, 2020 Re: D grammar oddities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dibyendu Majumdar | On Monday, 16 November 2020 at 23:55:29 UTC, Dibyendu Majumdar wrote:
> struct and unions aren't types.
> function and delegate are not either.
>
> According to the grammar.
A struct declaration *creates* a type, but it is not, itself, a type. When you declare `struct MyStruct { /* ... */ }`, the type that's created is just called `MyStruct`--which means that, grammatically, the type is an identifier.
|
November 17, 2020 Re: D grammar oddities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dibyendu Majumdar | On Monday, 16 November 2020 at 23:55:29 UTC, Dibyendu Majumdar wrote: > struct and unions aren't types. Correct, They are declarations. For their declarations an internal TypeStruct / TypeUnion is created. Later Identifier are resolved to those TypeQualified. > function Same principle. Function are declarations and an internal TypeFunction is created for the decl. In addition when there's a need to express a function type, an alias must be used, for example: alias F = void(int); > and delegate are not either. they are. But it's hidden as type suffix: https://dlang.org/spec/declaration.html#TypeSuffixes void delgate (int) -------^ ---------^ BasicType TypeSuffix > > According to the grammar. |
November 17, 2020 Re: D grammar oddities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Tuesday, 17 November 2020 at 00:24:20 UTC, Paul Backus wrote: > A struct declaration *creates* a type, but it is not, itself, a type. When you declare `struct MyStruct { /* ... */ }`, the type that's created is just called `MyStruct`--which means that, grammatically, the type is an identifier. Sure - but the issue is the grammar is useless for trying to understand the language. There is a production Types -> .... But it isn't map to a type. https://dlang.org/spec/grammar.html#types |
November 17, 2020 Re: D grammar oddities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dibyendu Majumdar | On Tuesday, 17 November 2020 at 22:01:16 UTC, Dibyendu Majumdar wrote:
> On Tuesday, 17 November 2020 at 00:24:20 UTC, Paul Backus wrote:
>
>> A struct declaration *creates* a type, but it is not, itself, a type. When you declare `struct MyStruct { /* ... */ }`, the type that's created is just called `MyStruct`--which means that, grammatically, the type is an identifier.
>
> Sure - but the issue is the grammar is useless for trying to understand the language.
>
> There is a production Types -> .... But it isn't map to a type.
>
> https://dlang.org/spec/grammar.html#types
wrong link - sorry - just look for Type production in the grammar
|
November 17, 2020 Re: D grammar oddities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dibyendu Majumdar | On Tuesday, 17 November 2020 at 22:04:34 UTC, Dibyendu Majumdar wrote: >> >> Sure - but the issue is the grammar is useless for trying to understand the language. >> >> There is a production Types -> .... But it isn't map to a type. >> >> https://dlang.org/spec/grammar.html#types > > wrong link - sorry - just look for Type production in the grammar I assume this is the production you mean: https://dlang.org/spec/grammar.html#Type I don't understand why you'd say that this is "useless." It is perfectly useful if you want to understand how to refer to a type syntactically--for example, in a variable declaration, or when passing it as an argument to a template. Is your complaint that a description of the language's *syntax* does not do anything to help you understand its *semantics*? If so, that's certainly true, but I'm not sure why you'd expect it to. The job of the grammar is only to explain the language's syntax. Explaining the semantics of D is what the other pages in the language spec are for. |
Copyright © 1999-2021 by the D Language Foundation