How to use a non-static objects in string `mixin`?

Paul Backus snarwin at gmail.com
Sat Aug 27 15:02:30 UTC 2022


On Saturday, 27 August 2022 at 13:20:13 UTC, hype_editor wrote:
> I need to use function `eval` sometimes, but compiler throws an 
> error: `Error: variable `firstOperand` cannot be read at 
> compile time`.
> ```d
> 	override public double eval()
> 	{
> 		double firstOperand = firstExpr.eval();
> 		double secondOperand = secondExpr.eval();
>
> 		return mixin(
> 			format("%d %s %d", firstOperand, operator, secondOperand)
> 		);
> 	}
> ```

`mixin` is not the right tool to use here. Try rewriting the code 
to use a `switch` statement or a series of `if`-`else` statements 
instead.


More information about the Digitalmars-d-learn mailing list