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

Named blocks #10

Open
liquidev opened this issue Dec 28, 2021 · 0 comments
Open

Named blocks #10

liquidev opened this issue Dec 28, 2021 · 0 comments
Labels
feature This issue is related to implementing a major feature of the compiler. language feature Adding a new feature into the language.

Comments

@liquidev
Copy link
Member

liquidev commented Dec 28, 2021

Because the language lacks goto, breaking out of a nested loop is quite unreadable:

var done = false
for y in 1..10
   for x in 1..10
      if my_array[x + y * 10] == 0
         done = true
         break
   if done
      break

Therefore, I think that named blocks should be introduced:

block loops
   for y in 1..10
      for x in 1..10
         if my_array[x + y * 10] == 0
            break @loops

Reasoning behind the syntax:

  • Prefixed declarations are better than infixed, because they're easier to parse and don't require backtracking.
    • Thus, block <name> and break @<name> instead of <name>: and break <name>
  • block should be an expression, thus one should be able to return a value out of a block.
    • I'm still not sure about the syntax here. break @loops -1 looks maybe just a little weird? Especially when combined with some more complex expression like break @loops x + y * 2
      • Maybe introduce a with keyword between the label and the result expression: break @loops with x + y * 2
      • On the other hand, the @label already separates the label name from the expression, especially if it's highlighted differently from normal expressions in editors.
@liquidev liquidev added language feature Adding a new feature into the language. feature This issue is related to implementing a major feature of the compiler. labels Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue is related to implementing a major feature of the compiler. language feature Adding a new feature into the language.
Projects
None yet
Development

No branches or pull requests

1 participant