Expression transformation by symbol name

Dominic Jones via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 8 06:15:51 PDT 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



More information about the Digitalmars-d mailing list