Fuzion Logo
flang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

Chained Boolean Operators

The idea is to avoid clumns expression such as

  if 0 <= i && i < array.length
    stdout.println("Index $i is ok!");

by allowing chaining of boolean expressions as follows

  if 0 <= i < array.length
    stdout.println("Index $i is ok!");

Syntactic Sugar for Chained Boolean Operators

The idea is for any infix operators op1 and op2 in an expression of the form

  expr1 op1 expr2 op2 expr3

if expr1 op1 expr2 yields a bool result and infix op2 is not defined for bool but for the type of expr2 to convert this into

  tmp1 := expr1;
  tmp2 := expr2;
  (tmp1 op1 tmp2) && (tmp2 op2 expr3)

longer chains should also be possible, i.e.,

  a < b < c < d < e < f < g

should become

  { tmp1 := a; tmp2 := b; tmp1 < tmp2 } &&
  { tmp3 := c; tmp2 < tmp3 } &&
  { tmp4 := d; tmp3 < tmp4 } &&
  { tmp5 := e; tmp4 < tmp5 } &&
  { tmp6 := f; tmp5 < tmp6 } &&
  (tmp6 < g)

Syntactic Problems

The syntax of a call with actual generic arguments overlaps with the syntax of expressions, e.g.,

  a < b > > c

is ambiguous and could be parsed as a call to a giving the actual generic argument b and comparing the result of this call to c

  (a < b >) > c

as well as

  a < (b >) > c

which is equivalent to

  a.infix <(b.postfix >).infix >(c)

In case an expression can be parsed as a generic argument, it should be interpreted as a generic argument.

Other Languages

Python does something similar. How does this work in detail?