nil is the empty list, also written as
) is often used as the base case of a recursive function that processes lists. Here is a small function that returns the sum of all elements in a list:
fun sum nil = 0
| sum (x::xs) = x + sum xs;
Together with the cons operator (::)
nil can be used to create lists. For example,
1::2::3::nil results in the list
[1,2,3]. This is mostly used to illustrate how lists are represented in SML. Usually you would just write
[1,2,3] if you need that list in a program.
ariels says: Also in the Lisps (Common Lisp) and Scheme. Whether or not nil is an atom is a matter of much debate...
In Pascal (and Delphi), nil is the value of a null pointer, i.e. the special value that indicates that the pointer does not point to something.