Using the ideas illustrated by the previous examples you can build a simple pocket calculator.

For simplicity, postfix notation is used, i.e., to compute 3+4 you enter
`3 Ent 4 +`.

Here is the source code:

importFudgetsmain=fudlogue(shellF"Pocket Calculator"calcF)calcF=intDispF>==<mapstateFcalc[0]>==<buttonsFdataButtons=Plus|Minus|Times|Div|Enter|DigitIntderiving(Eq)buttonsF=placerF(matrixP4) (listF[d7,d8,d9,opDiv,d4,d5,d6,opTimes,d1,d2,d3,opMinus,hole,d0,ent,opPlus])wheredn=(Digitn,buttonF(shown))ent=opEnterhole=(Enter,holeF)opo=(o,buttonF(opLabelo))whereopLabelPlus="+"opLabelMinus="-"opLabelTimes="*"opLabelDiv="/"opLabelEnter="Ent"calc(n:s) (Digitd,_)=new(n*10+d)scalcs(Enter,_)=(0:s,[])calc(y:x:s) (Plus,_)=new(x+y)scalc(y:x:s) (Minus,_)=new(x-y)scalc(y:x:s) (Times,_)=new(x*y)scalc(y:x:s) (Div,_)=new(x`div`y)scalcs_=(s,[])newns=(n:s,[n])

- To specify the placement of the buttons we have used
`placerF`

(as in Example 4) and the placer`matrixP`

which has the number of columns as an argument. - The state maintained by the application specific code (the
function
`calc`

) is a stack (represented as a list) of numbers. The function`calc`

pushes and pops numbers from the stack as appropriate. The last clause in the definition means that nothing happens if there are too few values on the stack for an operation.