ID:268652
 
I've been thinking if it was possible to have a formula in text form turned to a real one?

For example:
var/formula = "1+1" 
src << formula // outputs 1+1
formula = text2formula(formula) // something like this
src << formula // outputs 2


If it isn't possible currently, it would make a suggestion to improve BYOND. =)

~~> Dragon Lord
I agree, I was trying to add a function like this to my Deluxe Calc. Basically all I can suggest is using some sort of advanced findtext code that looks for an expression, basically very hard in my opinion, and then uses the text it's found to calculate the answere based on variables equal to the numbers found....Im battering on here... no good at explainin'.
I believe that AbyssDragon has a parser library that can do some math stuff.
Sure you can do that. Make a function that reads through a text string number and symbol by number and symbol, taking the appropriate action at each. Make a while loop that continuously checks to see if there is another operation to be performed; and if there is, check to see what the next operator and number in line are and do the appropriate math with a switch. When it is done looping, you have your answer, so return it.
In response to Loduwijk
What about including parenthesis and such?

I think the bottom line is that since DreamMaker already reads this kind of math, it doesn't seem like a long shot to request a function that reads text strings in a similar way.
It wouldn't be difficult to come up with a routine to handle such formulas (just parse the components into a list and go to town!), so why would supporting such a proc be desirable? I can't imagine it is frequently necessary....