www.delorie.com/gnu/docs/emacs-lisp-intro/emacs-lisp-intro_66.html search
Programming in Emacs Lisp

 [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

### An explanation of `nil`

Before illustrating a test for truth, we need an explanation of `nil`.

In Emacs Lisp, the symbol `nil` has two meanings. First, it means the empty list. Second, it means false and is the value returned when a true-or-false-test tests false. `nil` can be written as an empty list, `()`, or as `nil`. As far as the Lisp interpreter is concerned, `()` and `nil` are the same. Humans, however, tend to use `nil` for false and `()` for the empty list.

In Emacs Lisp, any value that is not `nil`---is not the empty list--is considered true. This means that if an evaluation returns something that is not an empty list, an `if` expression will test true. For example, if a number is put in the slot for the test, it will be evaluated and will return itself, since that is what numbers do when evaluated. In this conditional, the `if` expression will test true. The expression tests false only when `nil`, an empty list, is returned by evaluating the expression.

You can see this by evaluating the two expressions in the following examples.

In the first example, the number 4 is evaluated as the test in the `if` expression and returns itself; consequently, the then-part of the expression is evaluated and returned: `true' appears in the echo area. In the second example, the `nil` indicates false; consequently, the else-part of the expression is evaluated and returned: `false' appears in the echo area.

 ```(if 4 'true 'false) (if nil 'true 'false) ```

Incidentally, if some other useful value is not available for a test that returns true, then the Lisp interpreter will return the symbol `t` for true. For example, the expression `(> 5 4)` returns `t` when evaluated, as you can see by evaluating it in the usual way:

 ```(> 5 4) ```

On the other hand, this function returns `nil` if the test is false.

 ```(> 4 5) ```

 [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

 webmaster delorie software   privacy Copyright © 2003   by The Free Software Foundation Updated Jun 2003
{"ft_lang_label":"__label__en","ft_lang_prob":0.7683743,"math_prob":0.84606653,"size":2106,"snap":"2019-13-2019-22","text_gpt3_token_len":563,"char_repetition_ratio":0.14557564,"word_repetition_ratio":0.11518325,"special_character_ratio":0.2739791,"punctuation_ratio":0.13138686,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9621937,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-03-20T02:48:01Z\",\"WARC-Record-ID\":\"<urn:uuid:793b1cd6-cf5f-4e9a-9daa-af7077af190c>\",\"Content-Length\":\"7269\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8a64dfae-301d-42ac-bad5-5959c49af2b9>\",\"WARC-Concurrent-To\":\"<urn:uuid:b93f027f-0253-4c97-9558-a7e447f6463a>\",\"WARC-IP-Address\":\"65.175.133.15\",\"WARC-Target-URI\":\"http://www.delorie.com/gnu/docs/emacs-lisp-intro/emacs-lisp-intro_66.html\",\"WARC-Payload-Digest\":\"sha1:G4Z4EOK3L7OOPKJUU2DWYEKW2JEBEP63\",\"WARC-Block-Digest\":\"sha1:5OVVTV7QJBOHLQARWQU42J7K6J26YGQM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-13/CC-MAIN-2019-13_segments_1552912202199.51_warc_CC-MAIN-20190320024206-20190320050206-00464.warc.gz\"}"}