Choice is a special calculator which provides a solution from two or more alternatives. Choice has a format identical to an axiom declaration with named terms. However, when Choice evaluates, it creates variables from the terms in one row and makes these variables available to what follows. The first term in each row contains an expression for the selection of that row. The remaining terms are constants. The first term is referred to as the "selection term" and the value on which the selection is based is called the "selection value". There are three types of selection term:
- When the selection term is a string, then a regular expression tests the selection value for a match.
- When the selection term is a number or a variable, then it is tested for equality with the selection value
- The remaining option is the selection term is a expression which uses the selection value to produce a boolean result
Choice allows selection based on value ranges. The following script shows an example of a Choice to find the stamp duty applicable to a real estate transaction:
{amount < 12000, 0, 0.00, 1.00}
{amount < 30000, 12000, 120.00, 2.00}
{amount < 50000, 30000, 480.00, 3.00}
{amount < 100000, 50000, 1080.00, 3.50}
{amount < 200000, 100000, 2830.00, 4.00}
{amount < 250000, 200000, 6830.00, 4.25}
{amount < 300000, 250000, 8955.00, 4.75}
{amount < 500000, 300000, 11330.00, 5.00}
{amount > 500000, 500000, 21330.00, 5.50};
The choice keyword is followed by identifying name "bracket", the term names (set out here as column headings) and the choice alternatives.
There are several important details about how Choice is applied:
- All the Choice terms are named. These names also identify the Choice variables. All are used for the solution and the first doubles as the selection variable ("amount" in above example).
- Variables are allowed in the first term in each term set (the selection term)
- If a default selection term is required, then use keyword "unknown". See example opposite.
- A Choice can be either chained in a query the same way as a calculator, or can be employed as a calculator term. More details to come.
