Talk:Arithmetic evaluation

Revision as of 21:51, 24 January 2008 by rosettacode>Mwn3d (Makes sense)

Should we assume clean input or do we need to add in error checking? --Mwn3d 14:17, 11 December 2007 (MST)

Left unspecified (a solution can do either) User:Epsilon

TCL and [expr]

As is is written, this task is impossible in TCL since TCL has no concept of a "number" -- all variables are strings of bytes at the bottom and the only way to add a number to another one is to expressly declare some string to be interpreted as ... an expression. I.e. if variable "A" contains the string "3" then TCL has no idea that this might be a number. However [expr $A] would be a number (returned as a string again) and [expr $A+3] would be the string "6". Thus no matter how complicated my program might get, at some point I would have to invoke something like [expr $var1 $symbol $var2] (which would take the string formed by concatenating the contents of $var1, $symbol and $var2 and interpret them as an expression and return the result). This "bottom invocation", however would be prohibited by the task rules (and if I allow [expr] then I might as well just call [expr $original_string] and be done with the whole exercise in one line). Suggestions anybody? Sgeier 20:01, 22 January 2008 (MST)

I have rephrased the task in an attempt to clarify that the prohibition is against relatively direct evaluation of the input. Evaluation of the results of parsing is expected, not prohibited. --TBH 09:37, 23 January 2008 (MST)

Bigger than a task?

Is this task on par with RCBF? Is it closer to a project than a task? --Mwn3d 08:55, 24 January 2008 (MST)

To be honest, I'd put it in with "riddles" more than anything. It's a pretty standars CS101 task and the generic answer says that you use two stacks, one for the numbers and one for the operators. Thus this really boils down to "implement a stack". Of course that doesn't mean that someone might not have a particularly clever solution that would teach a lot about the way some language works. (Just because I find a task uninteresting doesn't mean someone else does the same). The reason I would put this in "puzzles" is that all languages I actually use have an arithmetic evaluator built-in. Thus "assign a value to an array" is an operation I do actually perform in my code, but "parse arithmetic strings" is not.Sgeier 14:46, 24 January 2008 (MST)
That makes sense. It's at least different from a regular task. A prefix notation "small programming language" interpreter (with just addition and multiplication and strings) was actually a project for my CS3 class (the CS classes are 200-level at my school). We did it using a tree rather than a stack, but that was for prefix notation. --Mwn3d 14:51, 24 January 2008 (MST)
Return to "Arithmetic evaluation" page.