Mixin every entity
Quirin Schroll
qs.il.paperinik at gmail.com
Wed Jul 24 12:10:12 UTC 2024
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.
One difference between usual mixins and mixins generating storage
classes and attributes (possibly more entities) is that those
would be valid when called with the empty string, resulting in no
storage class or attribute.
---
The only place I’d exclude from having its name generated is a
module.
```d
module mixin(expr);
```
That is a big no-no because module names are probably parsed
specially. And that’s fine.
More information about the dip.ideas
mailing list