Trouble understanding the true nature of the null function

28 views
Skip to first unread message

Praful Asher

unread,
Mar 15, 2012, 3:04:52 AM3/15/12
to Land of Lisp
The null function as per the book (Chapter 4) returns true for any of
the nil values. I was playing around in the REPL environment and saw
the following behavior:

1)
(null 'nil) => T

2)
(null '(2 3 4 nil)) => NIL

The first command behaves as expected. I am confused with the output
of the second command. Isn't that supposed to be "T" since the list
passed as parameter to the null function contains a 'nil ?

Ryan Scheel

unread,
Mar 15, 2012, 3:12:11 AM3/15/12
to land-o...@googlegroups.com
'(2 3 4 nil) is (list 2 3 4 nil) which is not nil. It only returns true for the nil values, not all values that contain nil values inside. 

If you know Java, think of null as the expression (object == null).  If the object is an array with null values in it, the expression is still false.

You could map null to the list though, as per (map null '(2 3 4 nil)) and you should get '(NIL NIL NIL T).

Praful Asher

unread,
Mar 15, 2012, 4:18:46 AM3/15/12
to Land of Lisp
Thanks Ryan. That clears it!

On Mar 15, 12:12 pm, Ryan Scheel <ryan.ha...@gmail.com> wrote:
> '(2 3 4 nil) is (list 2 3 4 nil) which is not nil. It only returns true for
> the nil values, not all values that contain nil values inside.
>
> If you know Java, think of null as the expression (object == null).  If the
> object is an array with null values in it, the expression is still false.
>
> You could map null to the list though, as per (map null '(2 3 4 nil)) and
> you should get '(NIL NIL NIL T).
>
Reply all
Reply to author
Forward
0 new messages