Parentheses - Manhunter07/MFL GitHub Wiki

Parentheses are essentially used for in three scenarios:

  1. To group a sub expression inside larger expression that the compiler is to be evaluated before its preceeding and succeeding operators (in other words, to make sure that a certain sub term is evaluated before another one, as known from math terms)
  2. To pass ordered or named arguments to a function as parameters, or to pass type arguments to a type constructor
  3. To tell the compiler to evaluate an expression in places where an identifier would usually stand, like in field names of record notations or in member keys

Remarks

  • All opened parentheses must be closed by the end of the sub expression
  • A closing parenthesis must be preceeded by an opening parenthesis
  • Overlapping parentheses or crossovers by parentheses and other similar constructs like brackets or braces are not allowed

Examples

The following example shows how parentheses can be used to overwrite pre-defined operator precedences:

2 * 13.8 + 9 \returns 36.6\
2 * (13.8 + 9) \returns 45.6\

Parenthesis are used to pass comma-separated arguments to a function, for example:

Sin(23.9)
Max(-4. Pi, 1.9, 0.3)
Map(Mapper = @Length, Value = ["James", "Michael", "Lara"])

Additionally, you can use them to evaluate an expression as an access key, like in these examples:

{f1 = 31.4, ("f2") = 19.7, ("f" + System.Convert.ToString(3)) = 60.3}
[5, 9, 3.2, -6].(0 + 2)
{Name = "Tom", Age = 56}.("Name").(Length("Tom") - 1)