Comparing a list with an integer returns strange results

Hi all,

we've been confronted to a strange case. For a better understanding we've reproduced the behavior in a expression rule : if({ 1 } = 1, { 2, 3, 4 }, {}) returns 2.

Obviously, comparing a list with an integer is the error here. But, then, the result should be either the empty list or null or an error message.

For more fun, you can test : if({true, false, true},{2,4,6},{3,5,7})

In our mind, a type error should be returned.

Regards.

  Discussion posts and replies are publicly visible

Parents
  • There have been a few discussions on this over the years, the if() statement is flexible per say where you can pass it a list of conditions and a list of outputs, and it will evaluate all of them independently at run time.  It can make debugging interesting if it is not used in it's simpler configuration with singular inputs as if(condition,whenTrue,whenFalse).

    That is why the expression below results in 3 outputs, as it evaluates true, then false, then true, in a row = {2,5,6}

    if({true, false, true},{2,4,6},{3,5,7})

Reply
  • There have been a few discussions on this over the years, the if() statement is flexible per say where you can pass it a list of conditions and a list of outputs, and it will evaluate all of them independently at run time.  It can make debugging interesting if it is not used in it's simpler configuration with singular inputs as if(condition,whenTrue,whenFalse).

    That is why the expression below results in 3 outputs, as it evaluates true, then false, then true, in a row = {2,5,6}

    if({true, false, true},{2,4,6},{3,5,7})

Children