1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-04 06:23:13 +03:00
juvix/tests/positive/Iterators.juvix
Łukasz Czajka 3cf79faafb
Formatter: add braces when the iterator body is not enclosed (#3122)
* Closes #3091
* Formatter adds braces when the body is not enclosed in braces or
parentheses. Braces-enclosed body is always printed as a block on a new
line:
```
for (acc := 0) (x in lst) {
  x + acc
}
```
* If the body is enclosed in ordinary parentheses, then they are
preserved and the iterator is printed on a single line, if possible:
```
for (acc := 0) (x in lst) (x + acc)
```
This is sometimes useful when you want iterator application as an
argument to something.
2024-10-25 11:42:01 +02:00

25 lines
553 B
Plaintext

module Iterators;
syntax iterator for {init := 1; range := 1};
for {A B : Type} (f : A → B → A) (x : A) (y : B) : A := f x y;
syntax iterator itconst {init := 2; range := 2};
itconst : {A B C : Type} → (A → A → B → C → A) → A → A → B → C → A
| f := f;
builtin bool
type Bool :=
| true : Bool
| false : Bool;
main : Bool :=
let
z : Bool := false;
in itconst (a := true; b := false) (c in false; d in false) {
for (x := true) (y in false) {
case x of
| true := y
| false := z
}
};