Skip to content

Inconsistent use of curly braces #834

Closed as not planned
Closed as not planned

Description

@wolfseifert

In a single statement function

a: () -> int =
  13;

b: () -> int = {
  return 42;
}

and in a for-loop with only one statement

v: vector = (1, 2, 3, 4, 5);
for v do (i) {
  print("(i)$ ");
}
println();
for v do (i)
  print("(i)$ ");
println();

curly braces are optional.

But for if

b:= true;
if b {
  println("b is true");
} else {
  println("b is false");
}

and while

v := :vector = (1, 2, 3, 4, 5);
i := 0U;
while i < v.size() next i++ {
  print("(v[i])$ ");
}
println();

curly braces are mandatory. This seems inconsistent to me. Or do I miss something?

Activity

  1. JohelEGP commented on Nov 15, 2023

    @JohelEGP
    Contributor

    See the thread at 26a4cbf#r128455814:

    Right, that comments should only have mentioned while loops, which have the same introductory structure as if conditions in that the condition and the body can be grammatically adjacent.

    Braces aren't required around for loop bodies.

    And they happen to be required around do loop bodies, but in that case it's not for the reason that a conditional could be ambiguous/confusion, since the body isn't adjacent to a conditional expression. There it's just for readability taste reasons.

  2. wolfseifert commented on Nov 16, 2023

    @wolfseifert
    Author

    Closing as duplicate of 26a4cbf#r128455814.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions