An expression is a combination of literals, data types, keywords, variables, function calls, operators, and calls to model elements. It always returns its resulting value. For example, "Hello " + getWorld()
concatenates the strings, "Hello " and the string returned by the getWorld()
function call, and returns the concatenation.
//returns the right side "hello":
def String var := "hello";
To chain multiple expression into a single expression, connect them with a semi-colon or a new line. Such a chained expression returns the return value of the last expression in the chain. Intermediary return values of the other chained expressions are ignored.
def String varString; varString := "Hello" //two expressions chained by a semi-colon (;)
varString:=varString + "World" //an expression chained by a new line
An expression block is an expression with its own contexts.
Expression blocks follow the visibility rules of contexts: the data in an expression block, such as, an expression variable, cannot be access from outside of the block.
The if
, then
, else
, switch
, foreach
, while
, for
content represent an expression block. You can create an expression block explicitly as well: start the block with the begin
keyword and finish it with the end
keyword.
begin
//declaration of an expression variable:
def Boolean visibility := true
//beginning a codeblock
begin
//declaration of an expression variable in the block (not available out of the block):
def Boolean visibility := false;
visibility == false;
end;
visibility == true;
end;
Literals represent fixed values. The notation of literals depends on the data type they represent. The notation is documented in Data Types.