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

Add syntax sugar for if, for, while and import #527

Open
mtshiba opened this issue Sep 30, 2024 · 0 comments
Open

Add syntax sugar for if, for, while and import #527

mtshiba opened this issue Sep 30, 2024 · 0 comments
Labels
enhancement New feature or request RFC New specifications of Erg
Milestone

Comments

@mtshiba
Copy link
Member

mtshiba commented Sep 30, 2024

We propose syntax sugar for some of Erg's built-in subroutines, which will make Erg code look more similar to Python and be easier to use for users familiar with Python.

New if syntax

if cond:
   ...
elif cond2: # optional
  ...
else: # optional
  ...

desugared:

if cond:
    do: ...
    else :=
        if cond2:
            do: ...
            else := do: ...

New if! syntax

if! cond:
   ...
elif! cond2: # optional
  ...
else!: # optional
  ...

New while! syntax

while! cond:
   ...
else!: # optional
  ...

desugared:

while! do! cond:
   do!: ...
   else! := do!: ...

New for! syntax

for! i in it:
    ...
else!:
    ...

desugared:

for! it:
    i => ...
    else! := do! ...

New import syntax

import foo
import foo as bar
import foo.bar as bar
from foo import bar
# import foo.bar # synyax error, we don't need this

desugared:

foo = import "foo"
bar = import "foo"
bar = import "foo/bar"
bar = import "foo/bar"
@mtshiba mtshiba added enhancement New feature or request RFC New specifications of Erg labels Sep 30, 2024
@mtshiba mtshiba added this to the v0.7.0 milestone Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request RFC New specifications of Erg
Projects
None yet
Development

No branches or pull requests

1 participant