Discussion Thread: DIP 1037--Add Unary Operator ...--Community Review Round 1

Paul Backus snarwin at gmail.com
Sat Oct 31 02:04:21 UTC 2020


On Friday, 30 October 2020 at 23:55:54 UTC, Manu wrote:
>
> I was about to raise both those examples you showed here. I show
> staticMap's implementation right there, and I also show types 
> in tuples.
> The trouble as I see is that there's a spec language problem, 
> where a tuple
> element is a 'kind of thing' that I don't know what to call 
> that.

I think "tuple element" is probably the best you can do. It's a 
little clunky, but clunky is better than ambiguous.

> What do you call this: MyTypeTuple[10]  ?
> Is that an index *expression*? Internally, it's an IndexExp, 
> but the tuple
> does not have expression elements, so the result is not an 
> expression, it's
> a type. I would call that an expression as applied to a tuple 
> regardless
> what kind of thing the result is.
> What about this: MyThing.Member  <- where Member may be a type. 
> Internally
> that's called a DotIdExp... so it's still an expression, even 
> if it's
> result is not an expression.

According to the grammar in the language spec, these are both 
IdentifierLists [1] when they appear in a context where a type is 
expected. In a context where an expression is expected, 
`MyTuple[10]` is an IndexExpression [2], and `MyThing.Member` is 
a PostfixExpression [3]. There is no such thing as a DotIdExp in 
the language spec.

In general, if you need to refer to a particular syntactic 
construct, I think it's better to use the name from the language 
spec, rather than the DMD-internal class name.

[1] https://dlang.org/spec/grammar.html#IdentifierList
[2] https://dlang.org/spec/grammar.html#IndexExpression
[3] https://dlang.org/spec/grammar.html#PostfixExpression


More information about the Digitalmars-d mailing list