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

Allow for an early return in a proc #295

Open
jimbxb opened this issue May 11, 2022 · 1 comment · May be fixed by #363
Open

Allow for an early return in a proc #295

jimbxb opened this issue May 11, 2022 · 1 comment · May be fixed by #363
Labels
enhancement New feature or request

Comments

@jimbxb
Copy link
Collaborator

jimbxb commented May 11, 2022

Sometimes, the use of an early return is useful.

Perhaps we can add a return statement that acts like fail but instead of failing the procedure, terminates the procedure without failing

e.g.

def product(matrix:list(list(int)), ?p:int) {
     ?p = 1
     for ?row in matrix {
         for ?i in row {
              if { i = 0 :: ?p = 0; return }
              !p *= i
         }
     }
}
@jimbxb
Copy link
Collaborator Author

jimbxb commented May 11, 2022

I suppose this example could be solved with the use of a generalised break, taking an optional integer constant, n argument that breaks n loops

e.g.

def product(matrix:list(list(int)), ?p:int) {
     ?p = 1
     for ?row in matrix {
         for ?i in row {
              if { i = 0 :: 
                  ?p = 0 
                  break 2
              } 
              !p *= i
         }
     }
}

Generalised next makes sense too, then

@jimbxb jimbxb added the enhancement New feature or request label May 11, 2022
@jimbxb jimbxb linked a pull request Nov 15, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant