About nil and the empty list ()

Q&A's, tips, howto's
Locked
johu
Posts: 143
Joined: Mon Feb 08, 2010 8:47 am

About nil and the empty list ()

Post by johu »

According to Users Manual and Reference,
In newLISP, nil and the empty list () are not the same as in some other Lisps. Only in conditional expressions are they treated as a Boolean false, as in and, or, if, while, unless, until, and cond.
I think that it means the following:
1.The empty list () is treated as the Boolen false in the following functions :
and, cond, do-until, do-while, if, if-not, or, unlrss, when, while

2.The empty list () is treated as the Boolen true excluding the above primitive functions.
Then,

Code: Select all

> (map rest '((a b) (a) ()))
((b) () ())
> (filter rest '((a b) (a) ()))
((a b) (a) ())
> (clean rest '((a b) (a) ()))
()
> (map (fn (x) (or (rest x) nil)) '((a b) (a) ()))
((b) nil nil)
> (filter (fn (x) (or (rest x) nil)) '((a b) (a) ()))
((a b))
> (clean (fn (x) (or (rest x) nil)) '((a b) (a) ()))
((a) ())
> 
but,

Code: Select all

> (title-case "aBCDE")
"ABCDE"
> (title-case "aBCDE" true)
"Abcde"
> (title-case "aBCDE" '())
"ABCDE"
> 
It might be not problem, maybe.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: About nil and the empty list ()

Post by Lutz »

The 'filter', 'clean' and 'map' examples are all correct. Basically they test for 'nil' instead of 'nil or the empty list' in the 'if' and 'while' family of functions.

But the 'title-case' function should treat the empty list '() as 'not nil'. This bug is not present in the UTF8 versions but present in the non-UTF8 versions and will be fixed in the next version.

Locked