opMixin or mixin function templates with convenience operator?

Paul Backus snarwin at gmail.com
Thu Dec 12 19:08:40 UTC 2019


On Thursday, 12 December 2019 at 18:35:03 UTC, Ola Fosheim 
Grøstad wrote:
> It is too noisy for formatting. Also, too hard for newbies to 
> use, they will misapply it and get weird errors.

I don't think it's any harder to use than the `mixin` keyword, 
though I'll concede that it's more cryptic to read and harder to 
search for in the documentation.

On the other hand, I think both of those arguments also apply to 
opMixin. Newbies are not likely to have an easy time 
understanding the difference between `foo!(args)` and 
`foo#(args)`. (After all, they already get tripped up by the 
difference between `foo(args)` and `foo!(args)`.)

> You need a type check on the library type to ensure that it has 
> been designed for mixin. (Mixin should not exist on the 
> application level.)

I'm not sure I understand what you mean. The only type you can 
mix in is `string`. There's no "library type" involved at all. 
Even the original "interpolator" example is really just a 
template function that takes a string as a compile-time argument 
and returns another string.

Are you proposing a language-level distinction between "string 
that contains D code for mixing in" and "string that contains 
some other kind of data"? I can see how that would be a useful 
thing to have, though it strikes me as orthogonal to the 
discussion in this thread--all uses of string mixins would 
benefit from it equally.


More information about the Digitalmars-d mailing list