Josef Eschgfaeller on Thu, 22 Oct 2015 14:39:15 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
eval of numeric strings |
I would like to define a function evaln which evaluates a string to a number only if the string contains explicitly the decimal representation of that number, not a variable. -------------------------------------------------- Behavior of eval: x=17; s=eval("x"); print(s); \\ 17. t=eval("17"); print(t); \\ 17. y="John" r=eval("y"); print(r); \\ John -------------------------------------------------- Desired behavior of evaln: x=17; s=evaln("x"); print(s); \\ x. t=evaln("17"); print(t); \\ 17. y="John" r=evaln("y"); print(r); \\ y. -------------------------------------------------- Idea of evaln (x is always a string): evaln (x) = if (isstringofdigits(x), eval(x), x) -------------------------------------------------- I could try to program isstringofdigits (including +,-. at the right places) by hand, but is there a better way? Thanks for help Josef Eschgfaeller