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

[Enhancement] conditional expression #284

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

Conversation

khchen
Copy link

@khchen khchen commented Jul 30, 2022

In many other language, ternary operator (:?) is the syntax for basic conditional expression.
However, in some language (e.g. coffeescript), they use if expression as conditional expression.

This patch adds if expression as the conditional expressionf for pocketlang.
I think it is more clear than ternary operator especially there is more then one condition (if ... elif ... else ...).

In the if expression, than can be omit, and end is not necessary (aslo not allowed). Example:

print(if true then 123 else 456)
print(if true 123 else 456)
print(if false 123 elif false 546 else 789)

a = if false
      123
    elif false
      456
    else
      789

print(a)

Output:

123
123
789
789

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

Successfully merging this pull request may close these issues.

None yet

1 participant