Bill Allombert on Mon, 08 May 2023 17:22:14 +0200


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

Re: boolean values for [] and List()


On Mon, May 08, 2023 at 10:55:16AM -0400, Max Alekseyev wrote:
> Why is there a discrepancy between empty vector and empty list?
> 
> ? if([], print("yes"), print("no"))
> no
> ? if(List(), print("yes"), print("no"))
> yes

This is because List() is not an arithmetic type: List()-List() is not defined:

? List()-List()
  ***   at top-level: List()-List()
  ***                       ^-------
  *** _-_: forbidden addition t_LIST + t_LIST.

so it is not subject to the 'x-x == 0' rule.

But in both case, it is better to do

if(#[],...)
if(#List(),...)

Cheers,
Bill.