Open strsthapa opened 1 week ago
Hi$
tab$
is: ta
+ b$
or t
+ ab$
. What Calcoad actually does in these cases: it parser the variable from right ($) to left and returns the first variable it finds (the fhortest one). So, just avoid variables that match letters at the end. Please use different names. There was a solution to this problem - to introcude a leading special symbol, like _b$
, but it would require a lot of additional typing.
Macros are perprocessed before calculations, just like C macros. As a result, the final (unwrapped) code is obtained by rewriting the variables with the actual text and only string processing is involved at this stage. So, if you pass 2*3
to x$
, x$^2
first becomes 2*3^2
. You can see this in the unrwapped code. Then, we calculate it using PEMDAS rule and get 2*3^2 = 2*9 = 18
. To avoid that, just put brackets in code: (x$)^2
. If you need this only for calculation purposes, the best way is to use actual functions, not macros: f(x) = x^2
. Then you will have f(2*3) = 6^2 = 36
. Macros are not intended for that.
As we discussed above, macros are preprocessed by string rewriting. So, if the unwrapped code you obtain after that represents a valid computable expression, you can assing it to a variable, e.g. y = f$(x$)
. But this is not completely true. You will not actually assign the macro, but the code behind the macro. I think that you think about macros as equivalent to functions, but they are not. They are just a simple way to reuse repeated code. Not only equations, but also text, Html, etc.