pocketlang icon indicating copy to clipboard operation
pocketlang copied to clipboard

[Enhancement] conditional expression

Open khchen opened this issue 1 year ago • 0 comments

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

khchen avatar Jul 30 '22 17:07 khchen