-
Notifications
You must be signed in to change notification settings - Fork 3
Functions
Victor Mataré edited this page Dec 11, 2020
·
11 revisions
In golog++
, functions are pure functional expressions.
That is, they must return some value of a non-void type, and they are side-effect free.
In particular, that means they are always made up of exactly one expression of the appropriate type, and nowhere can they contain any instructions like action calls or other things that may appear in a curly-braced code block.
TYPE function NAME(TYPE arg1 [, TYPE arg2 ...]) = EXPRESSION_OF_TYPE
A function that returns the sum of two numbers:
number function plus(number lhs, number rhs) = lhs + rhs
A function that returns true if a number is greater than ten:
bool function gt10(number n) =
if (n > 10)
true
else
false
Alternative definition:
bool function gt10(number n) = n > 10