Skip to content

Inconsistent use of curly braces #834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wolfseifert opened this issue Nov 15, 2023 · 2 comments
Closed

Inconsistent use of curly braces #834

wolfseifert opened this issue Nov 15, 2023 · 2 comments

Comments

@wolfseifert
Copy link

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?

@JohelEGP
Copy link
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.

@wolfseifert
Copy link
Author

Closing as duplicate of 26a4cbf#r128455814.

@wolfseifert wolfseifert closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants