Mixin every entity

Basile B. b2.temp at gmx.com
Thu Jul 25 15:05:11 UTC 2024


On Thursday, 25 July 2024 at 14:30:31 UTC, Quirin Schroll wrote:
> 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?

I dont know how to this explain this better but let's try. The 
AST is essentially made of 4 great family of nodes, Statements, 
Expressions, Declarations and Types.
Those are easy to insert dynamically. That's all. I did not say 
that partial construct could not be mixed-in, rather that this 
seems complicated at first glance.


More information about the dip.ideas mailing list