truth value of the empty list?

Q&A's, tips, howto's
Locked
TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

truth value of the empty list?

Post by TedWalther »

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?
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

sunmountain
Posts: 39
Joined: Tue Mar 15, 2011 5:11 am

Re: truth value of the empty list?

Post by sunmountain »

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

Code: Select all

(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

Code: Select all

()
and

Code: Select all

("")
?
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

Locked