XForms/Calculator

One of the classic examples of a web application program is a calculator.

Discussion
The calculator program is about 300 lines long. But much of the code is just telling what actions should happen when a button gets pressed.

The model of the calculator is very simple. Just a five variables:


 * display - the visible display
 * displaybuffer - a secondary display that is not visible
 * first - the first operator
 * second - the second operator
 * memory - used by the memory function

Here is the trigger for the "5" button:

 5     

The actions for the trigger is to do just two things:
 * 1) are to multiply the value of the display buffer by 10 (shifting the digits over by one) and then to add a five.
 * 2) copy the value of the display buffer to the display.

There are also scientific function calculators but they have a smiliar structure.

It is interesting to compare a JavaScript version to the XForms version. The JavaScript version is shorter but the JavaScript can take advantage of some of the tools that are available to JavaScript.