newLISP Fan Club

Forum => newLISP in the real world => Topic started by: johu on September 10, 2010, 03:57:07 AM

Title: About nil and the empty list ()
Post by: johu on September 10, 2010, 03:57:07 AM
According to Users Manual and Reference,
Quote
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:
Quote
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,
> (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,
> (title-case "aBCDE")
"ABCDE"
> (title-case "aBCDE" true)
"Abcde"
> (title-case "aBCDE" '())
"ABCDE"
>

It might be not problem, maybe.
Title: Re: About nil and the empty list ()
Post by: Lutz on September 10, 2010, 05:26:46 AM
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.