juvix icon indicating copy to clipboard operation
juvix copied to clipboard

Multiway `if` syntax

Open lukaszcz opened this issue 2 years ago • 0 comments

Our if is actually not readable, especially with nested ifs. Instead of writing e.g.

    if
      (y1 == 0)
      q
      (if
        (y2 == 0)
        p
        (if
          (x1 == x2)
          (if (y1 == y2) (double p) (mkPoint 0 0))
          (let
            slope := (y1 - y2) / (x1 - x2);
            r_x := slope * slope - x1 - x2;
            r_y := slope * (x1 - r_x) - y1;
          in mkPoint r_x r_y)));

we should be able to write e.g.

    if
      | y1 == 0 := q
      | y2 == 0 := p
      | x1 == x2 := 
          if
            | y1 == y2 := double p
            | else := mkPoint 0 0
      | else :=
          let
            slope := (y1 - y2) / (x1 - x2);
            r_x := slope * slope - x1 - x2;
            r_y := slope * (x1 - r_x) - y1;
          in mkPoint r_x r_y;

lukaszcz avatar Apr 18 '24 12:04 lukaszcz