Mixin every entity

Quirin Schroll qs.il.paperinik at gmail.com
Thu Jul 25 14:30:31 UTC 2024


On Wednesday, 24 July 2024 at 20:17:21 UTC, Basile B. wrote:
> On Wednesday, 24 July 2024 at 11:57:35 UTC, Quirin Schroll 
> wrote:
>> Mixins can produce types, expressions, statements, and 
>> declarations. That is great, but it could be better.
>>
>> Why not allow mixin identifiers, storage classes, attributes, 
>> etc.?
>>
>> Contrived example:
>> ```d
>> struct mixin("C")
>> {
>> mixin("const"):
>>     void f(mixin("ref") int x) mixin("@safe") { }
>> }
>> ```
>>
>> There’s no good reason a whole entity must be written in a 
>> string literal with a “hole” to be filled by `format` just 
>> because its name is generated. Interpolated strings help, but 
>> are not fundamentally different.
>
> There is a good reason for that, that is not what is explained 
> in one of the answer I can read. Mixins must introduce full 
> grammatical constructs, i.e an expression, a statement, or a 
> declaration, so that the content can be passed to the parser. 
> Also they cant interfere with a scope. There's a well known bug 
> (closed as of today), `mixin("private:")`.

I think you missed the point. What counts as a whole grammatical 
construct? Types can be mixed in, after all… So, at this point, 
calling types, expressions, statements, and declarations “whole,” 
but others which have names in the D grammar not is just 
arbitrary. Now, `mixin("private:")` isn’t illegal, it just 
doesn’t do anything useful. Why can’t identifiers, storage 
classes, attributes, etc. *not* count as whole entities?


More information about the dip.ideas mailing list