Calculator processes information to shape the solution to meet specific requirements. Calculator is a template with additional evaluation features. Calculator can take parameters, implement algorithms, and control flow of execution. Calculator can also execute queries. A calculator can be chained to another query to transform the results or generate aggregrate values.
Declaration Format
Calculator and template are similar in format. The main difference is that a calculator declaration starts with keyword calc, while a template declaration starts with template. However, as the role of calculator is to generate information while template has the role of establishing facts. Therefore calculator is capable of doing far more than template. Most of the additional functionality concerns what can be placed inside a template, but unique to calculator is the ability to include parameters in the declaration.
Calculator variables can be set using parameters passed in the declaration by appending a parameter list to it. Here is an example where parameter "factorial" is set to 1 and "i" is set to 1 too:
...
)(factorial = 1, i = 1);
A reason for setting parameters in the declaration may be to easily allow adjustments to be made at a later time. Note that parameter initialization overrides variable initialization inside the calculator.
Query Format
The way a calculator is referenced in a query resembles that of template. A calculator query can be used on it's own or chained the same as a Logic Query using ">>" notation.
( [ axiom-name : ] calculator-name [ ( parameter-list ) ] ) [ >> ... ]
The axion-name part is optional, and the query proceeds directly to evaluation when the axiom-name is not present. Also, when an axiom name appears in a calculator chain, only the first axiom from the source is unified with the calculator in a single step before proceeding down the chain.
A calculator may take values from the solution or is self-contained, hence both axiom-name and parameter-list are optional. Independent calculator examples are counting or performing some other aggregation operation.
