Lpp chose to use 0 as nil. This allows Lpp code to be
symmetric with usual C code that uses 0 and 1 as predicates. The
alternative would be to have to use the null function for every
predicate occurrence. For example any Lpp function f returning
let or Lpp object x can be used as a predicate
if (x) // do something
if (f()) // do something
Note that nil serves as three important things, a logical
value, the end of a list and it is also the symbol nil. The 0
as nil concept it is to be thought of as though the symbol
object nil resides at memory address 0. So that everything
that can be done with a symbol can be done with 0. For example
symbolName(0) => "nil"
When a let variable has the value 0 it prints as nil.
Conversely when in any s-expression is read from a stream nil
is translated into 0 internally. Lpp provides a global variable
True that has as its value the Lpp Symbol t,
See Symbols. And Nil is defined simply as 0, so it is just
as efficient to use Nil as 0 in your code except that the
compiler knows that Nil is an Lpp type.
Choosing 0 as nil creates an ambiguous situation when a type
can be interpreted as either int or let. For example
overloaded Lpp functions that are disambiguated between those that
have the same function profile but differ in an int or
let argument and so the following is legitimate
let someFunction(int i, let obj); // i to be an int
let someFunction(let i, let obj); // i to be an Lpp Integer or nil
So to disambiguate you would use Nil where nil was
intended
someFunction(0, something); // Means 0 as an int
someFunction(L(0), something); // Means 0 as an Lpp Integer
someFunction(Nil, something); // Menas 0 as Lpp nil
| Nil | Constant |
| True | Constant |
Nil is intended to be used in programs where the nil
symbol is needed and True is intended to be used where the
t symbol is needed. These are both names of constants that can
not be assigned other values. Since the Lpp Nil object prints
as nil and the Lpp True object prints as t,
nil and t when used in this manual will refer to those
objects respectively.
The name of the constant True and Nil can be redefined
per compilation unit, See Redefining Predefined Names. So for
example an Lpp programmer could redefine these names to be nil
and t to correspond to the Common Lisp constants nil and
t. After examining many C++ programs it was decided that the
default should not be the names nil and t since these
frequently occurred as variable names. For example t is
frequently used as a variable in C++ programs to denote "time".
Also, using Nil and True in Lpp programs emphasizes the
fact that they are just C++ identifier names and not in fact symbols
as they are in Lisp programs.
| null exp | Function |
null returns t if given expression exp evaluates
to nil and returns nil otherwise.