opMixin or mixin function templates with convenience operator?

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Thu Dec 12 12:23:45 UTC 2019


On Thursday, 12 December 2019 at 11:48:47 UTC, Zoadian wrote:
> I'm all in favor of improving D meta programming to the point 
> we can express stuff like string interpolation in library code 
> because it might allow for other new cool stuff we were not 
> able to do before.

Yes, but you also need to reduce the chance of the mixin doing 
things completely unexpected or being used for weird things.

I suggest the following constraints:

1. opMixin should resolve to the executing of an anonymous 
function with the following constraints:

    a. the function must return something that can be used in an 
expression

    b. the function must be pure

    c. all parameters given to the function must be const

    d. all the parameters given to the function must be found in 
the opMixin input

    e. parameters should compile (obviously)

2. opMixin can only be used where you have a expression

1d) will be adhoc for strings, basically it requires the opMixin 
output function parameters to be word-boundary substrings in the 
opMixin input.

So i#"My {value} pony +2" could result in a one parameter 
function like this:

anonfunc(value)
anonfunc(My)
anonfunc(pony)
anonfunc(pony +2)

but nothing else (for 1 parameter)



More information about the Digitalmars-d mailing list