<div dir="ltr">I'd like to be able to declare a function with a special @mixin property that will auto-mixin at call site:<div><br><div>@mixin string foo(){return some_string;}</div><div>void main(){</div><div> foo; //behaves as mixin(foo()); if @mixin weren't provided</div>
<div>}</div></div><div><br></div><div>This is purely syntax sugar, as it could be done with a mixin at call site, but is very useful in a number of scenarios:</div><div><br></div><div>Example 1:</div><div>I wrote a string parsing function 'embed' that allows to embed variables in current scope in a string:</div>
<div>void main(){</div><div>int x1=11;<br></div><div><div>double x2=2.3;</div></div><div>assert(mixin("variables: x1=$x1, x2=$x2, sum=$(x1+x2)".embed) == "variables: x1=11, x2=2.3, sum=13.3");<br></div>
<div>}<br></div><div>The 'embed' function parses the input string, extracts the '$' tokens (with a proper escape mechanism) and return a string of the form 'std.conv.text( ...)' with appropriate arguments so that the string can be mixed in at call site as above.</div>
<div><br></div><div>Without the @mixin property we have:</div><div>mixin("variables: x1=$x1, x2=$x2, sum=$(x1+x2)".embed)<br></div><div><br></div><div>With the proposed @mixin property this would simplify to:</div>
<div>"variables: x1=$x1, x2=$x2, sum=$(x1+x2)".embed<br></div><div><br></div><div>Which is simpler and easier to read than:</div><div><br></div><div>text("variables: x1=",x1,", x2=",x2,", sum=",x1+x2);</div>
<div><br></div><div><br></div><div>There are many other use cases. </div><div><br></div><div>If for some reason we can't have @mixin special property, can we at least have UFCS for mixin, so that we could write:</div>
<div><div>"variables: x1=$x1, x2=$x2, sum=$(x1+x2)".embed.mixin<br></div></div><div><br></div><div><br></div></div>