emacs.d/clones/lisp/colinallen.dnsalias.org/lp/node26.html

61 lines
1.5 KiB
HTML
Raw Normal View History

2022-08-02 12:34:59 +02:00
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Originally converted to HTML using LaTeX2HTML 95 (Thu Jan 19 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE> Checking for NIL</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Checking for NIL">
<meta name="keywords" value="lp">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<BR> <HR>
<A HREF="node27.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
<A HREF="node24.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
<A HREF="node25.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <BR>
<A HREF="lp.html"><B>Contents</B></A>
<B> Next:</B>
<A HREF="node27.html"> Logical Operators: And </A>
<B>Up:</B>
<A HREF="node24.html"> More Predicates and </A>
<B> Previous:</B>
<A HREF="node25.html"> Equality Predicates</A>
<BR> <HR> <P>
<H2> Checking for NIL</H2>
<P>
The predicates null and not act identically. Good programming style dictates that you use null when the semantics of the program suggest interest in whether a list is empty, otherwise use not:
<BLOCKQUOTE>
<PRE>&gt; (null nil)
T
&gt; (not nil)
T
&gt; (null ())
T
&gt; (not ()) ;;preferable to use null
T
&gt; (null '(a s))
NIL
&gt; (not '(a s)) ;;preferable to use null
NIL
&gt; (not (= 1 (* 1 1)))
NIL
&gt; (null (= 1 (* 1 1))) ;;preferable to use not
NIL
</PRE>
</BLOCKQUOTE>
<P>
<BR> <HR>
<P>
<ADDRESS>
<I>&#169; Colin Allen &amp; Maneesh Dhagat <BR>
March 2007 </I>
</ADDRESS>
</BODY>