NIL(3cl)

Common Lisp Reference

NIL(3cl)

 

NAME

nil – boolean false; empty list; empty type; symbol (symbol, boolean, or list)    

SYNOPSIS

 

;; although () and nil are interchangeable, the notation
;; provides a hint as to the use

nil             
;; as a boolean  
nil             ;; as a symbol  
‘()              ;; as an empty list  
nil              ;; as symbol or boolean  

()               ;; as an empty list  
 

ARGUMENTS and VALUES

n/a       

VALID CONTEXT

n/a    

BINDING TYPES AFFECTED

n/a   

DESCRIPTION

nil has a variety of meanings. It is a symbol in the COMMON-LISP package with the name "NIL", it is boolean (and generalized boolean) false, it is the empty list, and it is the name of the empty type (a subtype of all types).

Within Common Lisp, nil can be notated interchangeably as either NIL or (). By convention, the choice of notation offers a hint as to which of its many roles it is playing. For example, although it is permissible to write (defun function-with-no-args nil ...), where nil stands for an empty list of arguments, such a usage is misleading and to be avoided.

When nil is used as a type: A type is a symbol, list, or class. In this case, nil is a list with no objects, and so nil is also called the empty type. The type nil is a subtype of every type. No object is of type nil, but nil is of type null.    

AFFECTED BY

(none)  

EXCEPTIONAL SITUATIONS

(none)   

NOTES

The type containing the object nil is the type (class) null, not the type nil. The only object of type null is nil, which represents the empty list and can also be notated ().   

The object nil when used as an environment object denotes the null lexical environment.  

If a form produces zero values, then the caller receives nil as a value.      

EXAMPLES

 
(print ())                 ; avoided  
(defun three nil 3)        ; avoided  
’(nil nil)                 ; list of two symbols  
’(() ())                   ; list of empty lists  
(defun three () 3)         ; emphasize empty parameter list  
(append ’() ’()) ()      ; emphasize use of empty lists  
(not nil) true           ; emphasize use as boolean false  
(get nil color)          ; emphasize use as a symbol       

SEE ALSO

null(class)(3cl), null(function)(3cl)     

AUTHOR and COPYRIGHT

Substantial portions of this page are taken from draft proposed American National Standard for Information Systems—Programming Language—Common Lisp, X3J13/94-101R, Version 15.17R, Fri 12-Aug-1994 6:35pm EDT; no copyright indicated.

Additional clarification and comments by Michael Marking <marking@tatanka.com>, http://www.tatanka.com/software/cl-manpages/; alternatively, https://github.com/wakinyantanka/cl-manpages/. Copyright 2017 Michael Marking as both an original and a derivative work.

Licensed under Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0).

This page last revised Sunday 26 March 2017.