next up previous
Next: Simulation of the Simple Up: The Concept of a Previous: How the Tokens work

The Second Version

In the second version I let each numeral emit and receive decimal values in addition to the number value. When pressed, each numeral conveys its decimal value, according to its relative location in the number.

What this means is that given the number '345', pressing the number '3' will give you a decimal value of 300.

In addition to this I introduce a new token, the bracket. Brackets make the evaluation of an expression much more complex, since there are more possible ways of creating an invalid expression. This means that 'debugging' the expression becomes more important, since ideally a wrong answer should never be given to the child.

The brackets work in a similar way to the numerals, i.e., they emit values to their left and right. The difference lies in the way the read their values. The right bracket reads its value from the operator which it contains on the left, and vica versa for the left bracket. The trouble starts when we have many brackets contained within one another. To take care of that problem the bracket has to count how many brackets it encounters on the way to the operator, increasing the counter when it encounters an identical bracket to itself, and decreasing the counter when it encounters the opposit bracket. This means that if the bracket encounters an operator and the bracket counter is non-zero, it should not use that operator, but continue searching. If no operator is found when the bracket counter is zero, we surmise that there is an error in the arithmatic expression.

Obviously this behaviour of the bracket is non-trivial to implement in a physical object, but lends itself well to a simulation on a computer. It should also be noted that this does not solve the problem of not getting the correct results if multiple operators are used and no brackets (i.e. "5+5+5", pressing either of those operators returns 10.) That, however, can be viewed as a feature instead of a bug, since aritmatic expressions should, strictly speaking, not allow for ambiguity in parsing and should therefore always use brackets to determine parsing order. This is in my opinion a good lesson to teach the child, and later it can skip writing the brackets when it knows that the result is the same for all possible parses.


next up previous
Next: Simulation of the Simple Up: The Concept of a Previous: How the Tokens work
Magnus Bjornsson
1998-12-11