Expressions

To describe you code, you need to use expressions. In Definiti, all expressions return a value. The list of accepted expressions will be describe in this page.

Boolean expression

true | false

Returns directly true or false.

true
false

Number expression

[0-9]+('.'[0-9]+)?

Returns directly an number.

1
1.2
12.34

String expression

'"' ('\\"' | .)* '"'

Returns directly a raw string.

""
"my string"
"My String with \" escaped"

Reference expression

Returns the value which the reference targets. References can be:

  • Parameter (function, type, verification, lambda)

  • Function

  • Enumeration

Logical expressions

Composed to boolean expressions to verify either their both valid or one of them is valid.

For your information, && operator have precedence over the || operator.

Comparison expressions

Compare two values and return a boolean about this evaluation.

Types in both left and right expressions for equality expressions (== and !=) require to be the same exact type (even generics). In the other case, the compiler will not compile.

Type in both left and right expressions for inequality expressions (<, <=, > and >=) require to be numbers. There is no syntactic sugar to compare orders of other types (ex: Date). If you need to compare them, use a conversion function.

If you want to check a value is between two numbers, do it with logical expressions:

Computing expressions

Compute a new value from two other values.

Operations *, / and % have precedence over + and -. Otherwise precedence is from left to right.

Unlike in some languages, it is not possible to concatenate strings with +.

Not expression

Reverse the value of the inner expression.

Function call

Call a function with arguments.

If the function has generics, you must declare them.

Attribute call

Call an attribute from the returned value of the left expression.

It can be attributes of:

  • Native types

  • Declared types

  • Enumerations

Method call

Execute a method from the returned value of the left expression.

It can be methods of native types only.

Conditions

Execute some code depending of an expression.

The return type of the condition is the return type of both if part and else part. In the case the type differs, the return type of the expression will be Unit.

Even though the else part is optionally, there is few (if none) cases where it has a value to avoid it in Definiti.

Ok/Ko expressions

These expressions exist for the use inside verifications. Their return type is not interesting and is not designed to be used outside verifications or to be combined in other expressions.

They describe a validation or an invalidation with errors.

Parenthesis

An expression with parenthesis has precedence over other expressions. It is useful to override the default precedence.

Lambda

Lambdas, also known as anonymous functions, arrow functions and so on, describe a function without naming it.

It can only be used as parameters of functions or methods.

Currently, lambda are very verbose. A future work will be done to avoid unnecessary syntax.

Order of precedence

If you ask yourself what is the order of precedence of all expressions, it is simply from the last one to the first one (higher to lower).

It does not really change for most languages so you should not be lost.

Here ends the list of expressions in Definiti.

Last updated