Next: The Lisp Reader, Previous: Features as Lisp, Up: Rep's Lisp Introduction [Contents][Index]
In librep there is a single data value representing boolean
“false”—the empty list, written as ()
. All other values are
considered “not-false”, i.e. “true”.
By convention the constants nil
and t
are used to
represent the canonical boolean values. The constant variable
nil
evaluates to the empty list (i.e. “false”), while t
evaluates to itself (i.e. not-“false”, therefore “true”).
Reiterating, all of the conditional operations regard anything
which is not ()
as being true (i.e. non-false). The actual
symbol t
should be used where a true boolean value is explicitly
stated, to increase the clarity of the code.
So, ()
, and its alias nil
, represent both the empty list
and boolean falsehood. Most Lisp programmers write ()
where its
value as a list should be emphasized, and nil
where its value as
boolean false is intended. Although neither of these values need be
quoted (see Quoting), most programmers will quote the empty list to
emphasize that it is a constant value. However nil
should not be
quoted, doing so would produce the symbol nil
, not
boolean falsehood. For example:
(append '() '()) ⇒ () ;Emphasize use of empty lists
(not nil) ⇒ t ;Emphasize use as boolean false
(get 'nil 'color) ;Use the symbol nil
When a function is said to “return false”, it means that it returns the false boolean value, i.e. the empty list. When a function is said to “return true”, this means that any non-false value is returned.
Next: The Lisp Reader, Previous: Features as Lisp, Up: Rep's Lisp Introduction [Contents][Index]