opMixin or mixin function templates with convenience operator?

Paul Backus snarwin at gmail.com
Thu Dec 12 21:40:33 UTC 2019


On Thursday, 12 December 2019 at 19:42:59 UTC, Ola Fosheim 
Grøstad wrote:
> On Thursday, 12 December 2019 at 19:08:40 UTC, Paul Backus 
> wrote:
>> 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.
>
> I think a solution for string interpolation has to be very 
> close to what other languages offer, maybe it would have to be 
> made a special case for strings.

I agree. Personally, I'm a fan of Adam Ruppe's proposal.

A mixin operator would have applications beyond just string 
interpolation, though. For example, it could make pattern 
matching a bit more palatable:

     a[i .. j].match!(
         #pattern!`[] => false`,
         #pattern!`[xs...] => search(xs, target)`
     );

>> 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"?
>
> Yes, I guess it would be possible to type a mixin-string in 
> such a way that it is only allowed to represent a lambda 
> function that is being called. As in typing the string to a 
> function signature, would be one step.

Is there any actual difference between mixing in a bare 
expression vs. an immediately-called lambda function that 
evaluates to the same expression? Forcing string mixins to 
represent lambdas in particular seems needlessly restrictive.


More information about the Digitalmars-d mailing list