Evaluators
To write efficient KML Libraries, it is mandatory to understand the evaluation mechanisms. The first step is to declare your Concepts and their structures (attributes/children). You can then define evaluators to specify how the Concepts you have declared will lead to the creation of objects. There are different kinds of evaluators:
External Rules
External rules are EKL functions defined at the library level. Their signatures will indicate what attributes they are an evaluator for.
Suppose you have defined a rule in your Library:
Add (a : Integer, b : Integer, c : Out Integer) { c = a + b }Suppose you define the following Concept:
Concept MyAdditionnor : BaseConcept { Object : VoidType; Attributes { Inputs { Integer a; Integer b; } Outputs { Integer c; } } Rules { External Rules { Add(a,b,c); } } }In this Library, the External Rule Add is seen as an evaluator for c and it requires a and b to be valuated and to be executed.
Local Rules
Local Rules are local to a Concept, they are analyzed to determine for which Attributes they are an evaluator.
Concept Factorial : BaseConcept { Object : VoidType; Attributes { Inputs { Integer n; } Outputs { Integer result; Integer iterations; } } Rules { Rule { let i = 0 result = n for i while i < n { result = result * n-1-i } iterations = i } } }
The local rule defined above is detected as an evaluator for result and iterations requiring n to be valuated to run.
Formulas
Constructors
Constructors are an alternative to a call to new() to instantiate a KML Concept child. They allow explicit evaluation of the attributes of the Concept whereas the inputs are given using the order in which the attributes were declared, when calling new.
Concept Bottle: BaseConcept { Attributes { Inputs { Length BottleHeight; } } Children { BottleBody body = { Height = BottleHeight; Diameter = 5cm; } } }The constructor is an evaluator for the body child using BottleHeight as input.