Bill Allombert on Sat, 05 Nov 2022 23:56:07 +0100

 Re: Bug in evaluating "if(p==[],...)"

```On Sat, Nov 05, 2022 at 11:42:04PM +0100, Gottfried Helms wrote:
> This is a funny bug.
>
> I have a function with two arguments (p,q);
>  - if in argument p is a scalar value, a vector in q is expected,
>  - if in p is a vector, in q is a scalar expected.
>  The vectors can be empty (p=[] or q=[]), their type being vector
>  simply indicates, that some specific sequel has to be worked.
>
>
> Here is the maximally reduced function:
>
> {testfindroots_pq(p=[],q=[]) = my();
>     if(p==[]
>        ,print("p=",p," q=",q," ---> heading in p==[] path  ");
>        ,print("p=",p," q=",q," ---> heading in p<>[] path  ");
>       ); }
>
>
> Here the result:
>
> testfindroots_pq([],1) \\ p=[] q=1 ---> heading in p==[] path        +++ correct
> testfindroots_pq([],0) \\ p=[] q=0 ---> heading in p==[] path        +++ correct
>
> testfindroots_pq(1,[]) \\ p=1 q=[] ---> heading in p<>[] path        +++ correct
> testfindroots_pq(0,[]) \\ p=0 q=[] ---> heading in p==[] path        ***** false *****
>
> The problem is here, that supplying the scalar integer value "0" is
> taken as "==[]" (but not for instance the integer value "1")

Yes this is sometime annoying, you can use ===[] instead, not sure it that helps you:

? 0===[]
%1 = 0
? 1===[]
%2 = 0
? []===[]
%3 = 1

Cheers,
Bill

```