CondLink
CondLink is a kind of FunctionLink that implements branching similar to what is found in functional programming languages, such as scheme [1].
Contents
Syntax
CondLink has two syntaxes, conditions and expressions can be flattened or wrapped in list link.
Flattened Syntax:
CondLink <condition-1> <expression-2> ... <condition-n> <expression-n> <default-expression>
where <condition-i> is a kind of EvaluatableLink.
Wrapped syntax:
CondLink ListLink <condition-1> <expression-1> ... ListLink TrueLink <default-expression>
Semantics
As a ternary operation:
CondLink C E D
The above will execute E only if C is evaluated to crisp-logic True. Other wise the default expression D gets executed. And this is identical to a IfThenElseLink.
As n-ary operation:
CondLink C-1 E-1 ... C-n E-n D
The above will execute E-i only if C-i is evaluated to crisp-logic True. Where i is the index [1, n] for the first True evaluated condition. Other wise the default expression D gets executed.
Examples
(cog-execute! (CondLink (GreaterThanLink (NumberNode 2) (NumberNode 1)) (PlusLink (NumberNode 2) (NumberNode 3)) (NumberNode -1)))
will yield
(NumberNode 5)
Note that some similar operations can be acheived with MinLink, MaxLink and HeavisideLink.