IvoryScript further reading

Why an Order script works as a calculator

An IvoryScript Order script consists of a sequence of expressions. Before reduction, each expression is transformed so that its value can be displayed:

         #!(showWithNewLine (COERCE <expr>))
      

The inserted COERCE provides a type context for the expression. During type inference it is either removed where no conversion is required, or replaced by the appropriate cast application.

showWithNewLine then provides the displayed form and the enclosing #! denotes reduction of that application.

For example, an Order script may contain simply:

         7 * 6
      

The expression does not itself contain an instruction to display or fully evaluate anything. The surrounding Order transformation supplies the context required to obtain and display its value. This is why an Order script can be used much like a calculator without giving expressions calculator-like semantics.

For more than one expression, the transformed expressions are combined using SEQ. Two expressions become:

         #!(
         SEQ
         (transformExpr <expr1>)
         (transformExpr <expr2>)
         )
      

and a longer sequence extends the same transformation:

         #! (
         SEQ
         (#!(
         SEQ
         (transformExpr <expr1>)
         (transformExpr <expr2>)
         ))
         (transformExpr <expr3>)
         )
      

This continues for all expressions in the sequence. Each expression must ultimately be coercible either to a type having a Show instance or to Exp Void. In the latter case there is no resulting value to display.

The calculator behaviour therefore belongs to the Order program form, not to the expressions themselves. The same expression may occur elsewhere without being displayed or reduced in this way.