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

Do statement #17

Open
jprochazk opened this issue Feb 25, 2023 · 0 comments
Open

Do statement #17

jprochazk opened this issue Feb 25, 2023 · 0 comments

Comments

@jprochazk
Copy link
Owner

jprochazk commented Feb 25, 2023

do_stmt = 'do' ':' block
do:
  v := 0
  print v # prints `0`

print v # error: undeclared variable `v`

Semantics

Semantically equivalent to:

if true:
  <block>

The do statement allows opening a new scope. The main utility is in the control over scoping of variables. An example use case is temporarily shadowing variables:

v := test()
do:
  v := v.to_other_thing()
  use_other_thing(v)
i_still_want_to_use_the_original(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant