Skip to content
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

support for-else and while-else #56153

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

support for-else and while-else #56153

wants to merge 1 commit into from

Conversation

simeonschaub
Copy link
Member

This adopts the semantics discussed in #1289, namely the else block is executed whenever the loop never runs. Unlike Python, break and continue are irrelevant. Multidimensional loops are not supported since there is some ambiguity whether e.g.

for i in 1:3, j in 1:0
    print(1)
else
    print(2)
end

should print 2 once, thrice or maybe not even at all.

Currently only supported in the flisp parser, so requires JULIA_USE_FLISP_PARSER=1. I could use some guidance on the necessary steps to add this to JuliaSyntax as well - AFAIU this would also require #56110 first.

closes #1289

This adopts the semantics discussed in #1289, namely the `else` block is executed whenever the loop never runs. Unlike Python, `break` and `continue` are irrelevant. Multidimensional loops are not supported since there is some ambiguity whether e.g.

```julia
for i in 1:3, j in 1:0
    print(1)
else
    print(2)
end
```

should print 2 once, thrice or maybe not even at all.

Currently only supported in the flisp parser, so requires `JULIA_USE_FLISP_PARSER=1`. I could use some guidance on the necessary steps to add this to JuliaSyntax as well - AFAIU this would also require #56110 first.

closes #1289
@simeonschaub simeonschaub added parser Language parsing and surface syntax compiler:lowering Syntax lowering (compiler front end, 2nd stage) feature Indicates new feature / enhancement requests labels Oct 14, 2024
simeonschaub added a commit to JuliaLang/JuliaSyntax.jl that referenced this pull request Oct 14, 2024
simeonschaub added a commit to JuliaLang/JuliaSyntax.jl that referenced this pull request Oct 14, 2024
@adienes
Copy link
Contributor

adienes commented Oct 15, 2024

downvote.

IMO it's a bad idea to add not-obvious-what-it-does syntax that also happens to not mean the same thing at all as identical syntax in the world's most popular language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) feature Indicates new feature / enhancement requests parser Language parsing and surface syntax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

for-else and while-else
2 participants