Calculated fields
User programs can define calculated fields. A calculated field is implemented using the same field
term that is used when generating the logic program from the Cyberismo content. It is as simple as that!
This is best explained with an example. Let us assume that a card type risk has two integer fields likelihood
and impact
, which range between 1..3. The following logic program adds a calculated field riskLevel
, ranging between 1..9, calculated with the formula likelihood * impact
, to all cards of the card type risk that have the fields likelihood
and impact
.
field(X, "moduleName/fieldTypes/riskLevel", Likelihood * Impact) :-
field(X, "cardType", "moduleName/cardTypes/risk"),
field(X, "moduleName/fieldTypes/likelihood", Likelihood),
field(X, "moduleName/fieldTypes/impact", Impact).