Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Different result between if statement and if expression #55

Open
MadeByMars opened this issue Feb 20, 2020 · 1 comment
Open

Different result between if statement and if expression #55

MadeByMars opened this issue Feb 20, 2020 · 1 comment

Comments

@MadeByMars
Copy link

I wrote something like

instance node: iterable
...
call shim.unicast(self, 0 if node.is_max(self) else node.next(self), m);

Ivy complains that ivy/include/1.7/order.ivy: line 92: guarantee ... FAIL. That assertion is assert exists S. S > x;

Once I change it to:

if node.is_max(self) {
    call shim.unicast(self, 0, m);
} else {
    call shim.unicast(self, node.next(self), m);
}

it passes.

I guess the condition may not be correctly instantiated in if-expression.

@kenmcmil
Copy link
Contributor

The problem here is that the Ivy if-then-else and logical operators are not 'short-circuiting'. This means that the call to node.next occurs whether the condition node.is_max(self) is true or false.

My intention is to change this in the next version of the language. I will leave this issue open until then. Meanwhile, you have to work around the issue, as shown above.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants