Macro abuse
The use of macros in Clipper was a great gambiarra that had several problems and was frequently abused, as is the case of the example shown.
There is no reason to do this other than ignorance or laziness to do it right. Most of the places where macro was used could be done without the macro in a simpler and certainly safer way. The case of compiling an arbitrary formula was a case that might be justifiable. But it is not. Even the Harbor has a better solution than Clipper, compiling it right and saving and loading blocks of compiled code.
Suppose you really want to let users type formulas on their own. This is foolhardy and should be accompanied by a compiler itself to make sure everything is ok and is not doing anything more than it should. The use of the macro is a huge security hole. For those who do not know what it is and are wondering what that would be, it is eval
of JavaScript.
C # Equivalent
In static and fully compiled languages it is more complicated to do this. C # even provides some ways to run in a virtual machine (it would also give a more complete runtime ). But before doing this, try to use the right tools of a static language. Find out about the structural structural design patterns , especially the inStrategy pattern that I think is what I really need. It will not allow the user to enter formulas but will facilitate the inclusion of formulas to customize the software. These formulas will be previously compiled and possibly validated by the software vendor. There are several techniques to follow to create a secure plugin system that performs this properly.
Another possibility to actually let the user enter the formula is to create a compiler for this.
OC # always allowed code generation at runtime, but it was complicated, with .Net Compiler Platform was much easier. It even gives you the ability to simulate what the Clipper macro did in a reasonably simple way, and if you abstract, the syntax is even similar. But the fact that you can generate code from a source does not mean that you have to do it. It does not mean that a number of safety measures should not be taken. And they are reasonably complicated measures to implement.
An example of the scripting API:
int result = await CSharpScript.EvaluateAsync<int>("1 + 2");
An introduction to documentation can be found on Microsoft's GitHub. There is no definitive official documentation yet.
I find Async
unnecessary in simple cases like this, but I do not even know if the current version has a synchronous execution.
Conclusion
I should stress that this should not be used by those who do not have full understanding of all the implications of their use and know how to solve everything or accept that code is reckless. Should have a law enforcing a code so can only be used with express consent of the user. While it is true that a user who is harmed by this and has not been notified of the risk (in some cases even if it has been notified), it can certainly prosecute those who exposed it in this way.