Page 1 of 1

About nil and the empty list ()

Posted: Fri Sep 10, 2010 10:57 am
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.

Re: About nil and the empty list ()

Posted: Fri Sep 10, 2010 12:26 pm
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.