In the context of KnowledgeKube, an Expression is an instruction to your application to perform a specific task, after which it will return a value. The task, and the value returned, will depend on how the expression is written, but might include one of the following:

  • A simple arithmetic equation, returning the numeric result of that equation.
  • A logical comparison, returning True or False depending on the result of that comparison.
  • An instruction to fetch the current value assigned to a KnowledgeKube question, then return that value as a text string.

There are a vast number of uses for expressions; they can be used to navigate the end user from one part of an application to another, control the visibility of a specific part of the application, transform a set of numeric data, and much more besides.

The subject of expressions is extensive. This section will give you a primer and teach you how to implement some types of expressions, but there is much more to learn if you want to take full advantage of the power of expressions. You should refer to the Mercato Expression Cookbook if you want to find out more.

Below is a simple expression that combines two values and divides the result by a third value:

(4 + 10) / 5;

The numbers used in this expression are examples of Literal values, other examples of which are strings such as John Smith and High Street. As well as literals, you can also use Keywords in expressions. The next example shows an expression containing both literals and keywords:

5 + MyValue - 2;

Here, MyValue is a keyword that refers to a Value. The result of this expression is obtained by adding 5 to the value of the MyValue keyword, then subtracting 2. If, for example, MyValue has a value of 10, the final result of the expression will be 13.

Keywords are unique, and in the context of most expressions they refer to one of the following:

Element Description Further Reading
Question The value associated with this keyword is whatever the end user has entered against the corresponding question. Adding a Question to the Expression Parser
Model Identifier The value associated with this keyword is taken directly from the identifier. Model Identifiers
Function A function is a specialised procedure that can be initiated, or Called using its keyword. The procedure tells KnowledgeKube to perform one or more pre-defined tasks without the need for you to write the task(s) into your expression in full. Functions

Keywords in expressions are identifiable by the absence of quote marks around what would otherwise be a literal string of text. In the example below, a literal string value is assigned to the keyword MyName:

MyName:= "Matthew";

Unlike strings, numeric literals do not need quote marks around them. A similar assignment expression using a numeric literal might be written as follows:

MyHeightCm:= 190;

Because numbers are written without the use of quotes, you cannot create a keyword that starts with a number.

Each expression will lie dormant in your application until it is activated, or Triggered. The means by which an expression is triggered will depend on a number of factors that will be covered during the course of this guide. Examples of trigger methods include clicking a button, or loading a form. You can even use one expression to trigger another.

Now you understand the basic concept of expressions, refer to the following topics:

Description Further Reading
Add an expression type question to your application. Implementing an Expression
Use a question's value in an expression. Adding a Question to the Expression Parser