newLISP Fan Club

Forum => newLISP in the real world => Topic started by: TedWalther on November 21, 2011, 11:01:25 PM

Title: truth value of the empty list?
Post by: TedWalther on November 21, 2011, 11:01:25 PM
I just got confused tonight.  It is handy for the empty list to be a "false" value.  I thought maybe it was only nil that registered as a false value.  But since the empty list is a false value, how about the empty string, and the number 0?  Lutz, did you already post on your reasons for this design decision?
Title: Re: truth value of the empty list?
Post by: sunmountain on November 21, 2011, 11:56:21 PM
I can't wait for the answer - this can get philosophical.



The key question is: what is value and when is it nil (as I remember there is no false in lisp, though) ?

If you look over to python, "", empty lists, tuples and numeric 0 are false.

That seems natural, but in lisp you work on lists, an (0) is in list - so true.

Even an empty string is a cell, with no value, it is in list - so true.

An empty list says: there is nothing in list, nil - so false.



So for me the question goes down to: is there an element in list or not ?



If you would take e.g. Python's approach you ask: does to value of an element evaluate to true ?



But: how can you then distinguish between () and ("") ?

Then both would give nil, but 1. case has no element where 2. has one (an empty string).

So for at least some cases you would need a hasElement* or such.



I think the lisp approach is consistent.



Just my thoughts.



*JAVA TM public final static synchronized unvoid function