The power of macros is exactly what you seem to perceive as a weakness. Most 
languages doesn't allow you to modify your own code on compile-time, some offer 
limited support. Nim is really one of the few languages which offers this level 
of compile-time modification of code, which is a really powerful feature. The 
fact that macros aren't available on runtime is simply because Nim code doesn't 
exist on runtime. When you compile Nim it first gets compiled down to C, then 
that gets further compiled down to machine instructions. So by the time you're 
executing your code the program isn't really Nim any longer. As someone else 
have mentioned, it is possible to use the Nim compiler as a library, either to 
create your own modified compiler, or to execute NimScript (the subset of the 
Nim language which is executed in macros and .nimble files during compilation) 
but this is a rather huge dependency just to do a little bit of math.

As other have mentioned if you want to do math on runtime from strings it's 
better to use a math evaluation library, Yardanico has one which is linked 
above, and I have written one which can be used for RPN expressed math.

Reply via email to