Karim Belabas on Mon, 08 May 2023 17:24:53 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: boolean values for [] and List()


* Max Alekseyev [2023-05-08 16:55]:
> Why is there a discrepancy between empty vector and empty list?
> 
> ? if([], print("yes"), print("no"))
> no
> ? if(List(), print("yes"), print("no"))
> yes

Side effect of other definitions and design choices: PARI's '==' (here == 0)
operator is dodgy, use '===' if you want more consistent semantics.

The definition for a == b when it doesn't obviously makes sense is to
check whether a - b evaluates to 0, where an evaluation error is
interpreted as 'NO'. A t_LIST is not an arithmetic type and doesn't
support subtraction, so List() - 0 is an error (whereas [] - 0 is [],
which evaluates to 0 by another convention).

In short, a t_LIST is always 'non-0'.

Cheers,

    K.B.
-- 
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/