riolet / rix

Rix language combines the power of C language and the convenience of a high level language
GNU General Public License v3.0
729 stars 27 forks source link

multiple elifs will fail #19

Open JoePelz opened 8 years ago

JoePelz commented 8 years ago

The issue is with multiple elif statements, if a previous statement has already run. The following will generate erroneous output:

x = 1
y = 1
x == 1 && y == 1 if
  echo "x=1 y=1, "
? elif x == 1
  echo "x=1 y!=1, "
? elif y == 1
  echo "x!=1 y=1, "
? else
  echo "x!=1 y!=1, "

It will print x=1 y=1, x!=1, y=1 rather than the expected x=1 y=1, No workaround right now.

The fix may be to apply DeMorgan's Law on the second or later elif when negating the previous condition.

JoePelz commented 8 years ago

Workaround right now is discrete if statements

x == 1 && y == 1 if
  echo "x=1 y=1, "
y!=1 && x==1 if
  echo "x=1 y!=1, "
y==1 && x!=1 if
  echo "x!=1 y=1, "
x!=1 && y!=1 else
  echo "x!=1 y!=1, "