GassaFM / interpr

Toy language to learn parallel computing
MIT License
5 stars 4 forks source link

If chek all conditions #18

Open eakravchenko opened 4 years ago

eakravchenko commented 4 years ago

If a & b cheks all conditions, even a is false. Therefore, you need to write a if(r>=0): if(x[r]>=0): instead of if(r>=0 & a[r] ):

It is very uncomfortable.

GassaFM commented 4 years ago

Yeah, that's why we have && and || and shortcut boolean evaluation in most languages. Apart from mild inconvenience of introducing lazy evaluation into the interpreter, I wanted people to stumble here, and appreciate that trait of other languages. So, what solution do you propose?

eakravchenko commented 4 years ago

If witth double condition i can rewrite for two if. But what should i do with while i < len & x[i] <= 0: it cannot be rewritten with two while!

GassaFM commented 4 years ago

You can use a boolean-like variable to simulate that, like:

ok := 1
while ok:
    ok &= i < len
    if ok:
        ok &= x[i] <= 0
        if ok:
            ...

I agree it's very inconvenient though.