September 08, 2017
Hello,

Is there a way in D of applying a transform function to the following expressions at compile-time such that the first is modified and the second left unchanged?

Where 'a' and 'b' are of the same type:
1. "transform(a * a)" returns an object to evaluate "2 * a"
2. "transform(a * b)" returns an object to evaluate "a * b"

Such transformations appear to be impossible without some kind of access to the symbol name in order to distinguish the two scenarios.

If it is possible, what are the reflection functions one would need to use to implement this?

If it is not possible, has there been any interest or attempts to add such reflection functionality to the language to make it possible?

Thank you,
Dominic Jones

September 08, 2017
On Friday, 8 September 2017 at 13:15:51 UTC, Dominic Jones wrote:
> Where 'a' and 'b' are of the same type:
> 1. "transform(a * a)" returns an object to evaluate "2 * a"
> 2. "transform(a * b)" returns an object to evaluate "a * b"

1. "transform(a + a)" returns an object to evaluate "2 * a"
2. "transform(a + b)" returns an object to evaluate "a + b"