Bundt Scripting Reference · Bundt Scripting Language version 1.0.1.0

Expressions

An expression is a fragment of a script which, when evaluated, yields a resulting value.

Some expressions are very simple, such as 15 / 3 > 4, which yields true. Others are more complex.

Details

Expressions allow us to algorithmically obtain a result from a set of inputs. This may involve calculations, comparisons, or the execution of statements.

There are different kinds of expressions:

  • Literals, which literally contain the values that they yield when evaluated, such as 15 (a numeric literal), true (a Boolean literal), or "Hello", a text literal.
  • Special values such as null or unknown.
  • Collections, which are organized groups of other expressions, such as [en_GB: Building, es_ES: Edificio, it_IT: Palazzo] (an identifier dictionary).
  • Variable expressions, which evaluate a variable, such as %a.
  • Pick expressions, which pick one model or model part by its guid, id or key.
  • Unary operator expressions, which involve an unary operator, such as ! (Boolean negation) or - (numeric minus), being applied to another expression.
  • Compound expressions, which involve two or more expressions conected by binary operators, such as * (numeric multiplication) or > (greater-than comparison).
  • Parenthesized expressions, which involve another expression in parentheses so that it gets evaluated as a group.
  • Finally, statements are also considered to be expressions.

You can quickly evaluate an expression and check out the resulting value by usig a write statement. For example, you can run write 15 / 3 > 4; to verify that it produces a result of true.

Every expression has a type, which determines what kind of value it yields when evaluated. For example, the expression 15 / 3 > 4 is of Boolean type, as it produces a Boolean value (true or false) when evaluated. The expression [en_GB: "Building", es_ES: "Edi" + "ficio"], on the other hand, is of text dictionary type, as it produces a dictionary of texts when evaluated.

When simple expressions are combined into more complex ones through the use of operators, types must be respected. First of all, each simple expression in a combined one must have a compatible type so that operators can combine them successfully. For example, the expression 15 / 3 > "Hello" is invalid, as it tries to combine two literals of different types: 15 / 3 is numeric, whereas "Hello" is a text. If you try to evaluate this, the analyzer will report a type mismatch error.

Secondly, the types of combined expressions must be compatible with the operators being used. For example, false + true is invalid, because the + operator does not apply to the Boolean type; in other words, it doesn't make sense to add two Booleans together.

Please see Data Types for a comprehensive description of what types are available, and Operators for a description of what operators exist and what their compatible types are. The next sections provide some details on specific kinds of expressions.

Variable expressions

A variable expression returns the value of a variable. Variable expressions consist of a % sign followed by the variable name, such as %a.

Pick expressions

A pick expressions picks a model or model part by its guid, id or key. Pick expressions consist of a # sign followed by any combinatin of a model guid and a model part id, separated by a semicolon.

  • If you include only a model guid, as in #'e9a2bac7-6806-49f0-b7b8-1d9398570909', the expression returns the model having that guid.
  • If you include only a model part id, as in #37, the expression returns the model part with that id in the context model.
  • If you include both a model guid and model part if, as in #'e9a2bac7-6806-49f0-b7b8-1d9398570909':37, the expression returns the model part with that key in the context model.

See Also


Contents distributed under a Creative Commons Attribution 4.0 International License · About · Terms of Use · Contact Us · last updated on 08 October 2020