-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
an idea about loop #1768
Comments
+1 |
Maybe
This way, we can use fewer keywords, more concise expressions, and clearer semantics. Of course
To be on the safe side, the if statement should be forced to be followed by a compound statement. My core idea is not |
The C-idiom is |
I'm afraid of macros, it's not context friendly, it makes what I see inconsistent with what it actually is. Not using macros is a good thing. And carbon's |
Yes, indeed. Macros also make it very difficult to change the syntax later, so they better not add macros.
Yes, I think the designers have set themselves up for a lot of complaining by having so much redundancy in the syntax… …but, as long as they don't add macro-like features then it should be possible to create an alternative syntax that compiles to the same abstract syntax tree. |
I have spend time to consider this problem again. It's a good thing to remove the restricted position about the condition. But others may be a little ill-considered. My thoughts about for(;;) {
if (/* */) {
// do something
continue;
} // Mu thought about `again` is not well in this case
} The traditional syntax combines conditionals with jumps, which is convenient but not suitable for all cases. But if we separate the two, we may have to write longer code.
I don't think most people want to do this, even if it gives us the most flexibility. So should we separate conditionals and jumps to handle some special cases, even when typing longer code? Thanks for taking the time to look at my half-baked ideas, good luck Carbon. |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the |
In C++ and others, we often code these:
Like this, the condition is not always at the beginning or end of the loop body.
So why not try this syntax:
Traditional loops always put the condition at the head or tail, but we can make it appear where it needs to appear, even more than once, just like
if
break
Maybe we can use other keywords to act as
continue
.For example
again
Or we do not provide conditions on the loop syntax, so that the programmer ends the loop with an if statement in the loop body:
The text was updated successfully, but these errors were encountered: