3.2. Booleans Operators


Expressions in Lush are considered ``false'' when their evaluation returns the empty list. All other expressions are considered ``true''. The symbol t however is preferred for this meaning.



3.2.0. Boolean Arithmetic


A number of functions are available for programming tests and to return boolean values



3.2.0.0. (= n1 n2)
[DX]


Test if n1 is equal to n2 . Two objects are equal if they have the same type and if they convey the same information. The criterion for deciding equality therefore depends on the type of the object.

This function supports any Lush object.

Example:

? (= '(1 2 (3)) (cons 1 '(2 (3))))
= t

? (= [  1.00  2.00 ] [  1.00  2.00 ])
= t

Testing the equality between special numeric values may be tricky. For example, the IEEE754 specification(supported by most of the industry) defines special bit patterns named NaN(Not a Number). Comparing two NaNs should always return false. Major operating systems and compilers however do not respect this.

Lush expressly specifies that the result returned by the equality test is *always* true when objects n1 and n2 share the same memory location. In other words, if the function == returns t then the function = returns t as well.

See: Special Numerical Values (IEEE754).
See: (== n1 n2 )
See: Comparison of User Defined Objects.




3.2.0.1. (<> n1 n2)
[DX]


Tests if n1 is different from n2 . This function is equivalent to
(de <> (n1 n2) (not (= n1 n2)))

Example:

? (<> 2 "abcd")
= t

? (<> 2 2)
= ()

See: (= n1 n2 )




3.2.0.2. (== n1 n2)
[DX]


See: (= n1 n2 )
Test if n1 and n2 are physically equal.

This function does not even look at the information conveyed by the lisp objects n1 or n2 . It just tests that the pointers returned by the expression n1 and n2 are equals.

Pointer equality not only means that objects referred to by expression n1 and n2 are equal, but also means that they are located at the same memory addresses.

This information is meaningful as soon as you use functions that modify objects (as opposed to functions returning a modified copy of the object and leave the initial object unchanged). These functions include the following:

Function == may be used in conjunction with these functions. Modifying indeed the object referred to as n1 will therefore also modify the object referred to as n2 . Function == may also be used as a fast way to compare objects and matrix when you know that the only possibility of equality is physical equality.

Example:

? (setq a 3)
= 3
? (== a 3)
= ()
? (= a 3)
= t
? (== a a)
= t
? (setq a [1 2])
= [1 2]
? (setq b [1 2])
= [1 2]
? (= a b)
= t
? (== a b)
= ()
? (a 0)
= [0 2]
? (= a b)
= ()
? b
= [1 2]


3.2.0.3. (0= n)
[DX]


Test if n is equal to 0.

See: Special Numerical Values (IEEE754).




3.2.0.4. (0<> n)
[DX]


Test if n is different from 0.

See: Special Numerical Values (IEEE754).




3.2.0.5. (<= n1 n2)
[DX]


Test if n1 is less or equal than n2 . Arguments n1 or n2 may be dates, strings or numbers. User defined objects may be supported as well.

See: Special Numerical Values (IEEE754).
See: Comparison of User Defined Objects.




3.2.0.6. (< n1 n2)
[DX]


Test if n1 is less than n2 . Arguments n1 or n2 may be dates, strings or numbers. User defined objects may be supported as well.

See: Special Numerical Values (IEEE754).
See: Comparison of User Defined Objects.




3.2.0.7. (>= n1 n2)
[DX]


Test if n1 is greater or equal than n2 . Arguments n1 or n2 may be dates, strings or numbers. User defined objects may be supported as well.

See: Special Numerical Values (IEEE754).
See: Comparison of User Defined Objects.




3.2.0.8. (> n1 n2)
[DX]


Test if n1 is greater equal than n2 . Arguments n1 or n2 may be dates, strings or numbers. User defined objects may be supported as well.

See: Special Numerical Values (IEEE754).
See: Comparison of User Defined Objects.




3.2.0.9. (and l1 ... ln)
[DX]


Evaluates sequentially l1 .. ln . If a result is the empty list, function and immediately returns () . The result of the evaluation of ln is returned otherwise.

Example:

? (and (= 2 2) (= 2 3) (print (= 2 2)))
= ()



3.2.0.10. (or l1 ... ln)
[DX]


Evaluates sequentially l1 .. ln . If a result is not the empty list, this result is immediately returned. The empty list is returned otherwise.

Example:

? (or (= 2 2) (= 2 3))
= t



3.2.0.11. (null l)
[DX]


Returns t if the result of evaluating l is the empty list. Returns the empty list otherwise. The macro character |~| may be used for that purpose.

Example:

? (null t)
= ()



3.2.0.12. (not l)
[DX]


The null and not functions are identical.



3.2.0.13. ~ l
[MCHAR] (sysenv.lsh)


This macro-character expand to (null l) .



3.2.1. Predicates


Predicates test the type of any lisp object.



3.2.1.0. (listp l)
[DX]


Returns a non-nil result when l is a list, including the case of the empty list.

Example:

? (listp ())
= t

? (listp "abc")
= ()

? (listp '(2 3))
= (2 3)



3.2.1.1. (consp l)
[DX]


Returns a non-nil result when l is a non-empty list.

Example:

? (consp ())
= ()

? (consp "abc")
= ()

? (consp '(2 3))
= (2 3)



3.2.1.2. (atomp l)
[DX]


Returns a non-nil result when l is an atom.

Example:

? (atomp ())
= t



3.2.1.3. (numberp l)
[DX]


Returns a non-nil result when l is a number.

Example:

? (numberp 3.14)
= 3.14



3.2.1.4. (symbolp l)
[DX]


Returns a non-nil when l is a symbol.

Example:

? (symbolp 'a)
= a



3.2.1.5. (externp l)
[DX]


Returns a non-nil result item when l is a non numerical atom.

Example:

? (externp car)
= ::DX:car



3.2.1.6. (classp l)
[DE]


Returns a non-nil item when l is a class.

Example:

? (classp object)
= t



3.2.1.7. (functionp n)
[DX]


Returns t if n is a function.

Example:

? (functionp "abc")
= ()

? (functionp functionp)
= ::DX:functionp



3.2.1.8. (stringp s)
[DX]


Returns a non nil result if s is a string.

Example:

? (stringp "abc")
= "abc"