next up previous contents index
Next: Numerical Predicates Up: Introductory Scheme Previous: List Manipulation

Predicates

 

Predicates  in Scheme are boolean operators. They return either true , denoted #t , or false , denoted by the empty list, () . The predicates defined in Scheme are:

(atom?  expression)
Returns true if expression is an atom, or the empty list, false otherwise.

 
		 (atom? 'a) 		  tex2html_wrap_inline972  		 #t

(atom? 12) tex2html_wrap_inline972 #t

(atom? '(1 2 3)) tex2html_wrap_inline972 ()

(atom? '()) tex2html_wrap_inline972 #t

(list?  expression)
Returns true if expression is a list, including the empty list. Note that the empty list is the only expression that returns true for both atom? and list?.

 
		 (list? '(1 2 3)) 		  tex2html_wrap_inline972  		 #t

(list? 'a) tex2html_wrap_inline972 ()

(list? '()) tex2html_wrap_inline972 #t

(null?  expression)
Returns true only if expression is the empty list , ()  or nil .

 
		 (null? '()) 		  tex2html_wrap_inline972  		 #t

(null? '(1 2 3)) tex2html_wrap_inline972 ()

(null? 'a) tex2html_wrap_inline972 ()

(not  predicate)
Returns true if predicate returns (), false otherwise.

 
		 (not '()) 		  tex2html_wrap_inline972  		 #t

(not #t) tex2html_wrap_inline972 ()

(equal?  expression1 expression2)
Returns true if expression1 and expression2 are structurally equivalent; that is, if they have the same list structure and all their atoms are equal. This is not to be confused with eq? , which returns true only if its arguments are the same object. That is, equal? tests for structural equivalence, while eq? tests for pointer equivalence. In the following examples, assume that we have already entered (define foo '((1 2) 3)).

 
		 (equal? '((1 2) 3) '((1 2) 3)) 		  tex2html_wrap_inline972  		 #t

(eq? '((1 2) 3) '((1 2) 3)) tex2html_wrap_inline972 #t

(equal? '((1 2) 3) foo) tex2html_wrap_inline972 #t

(eq? '((1 2) 3) foo) tex2html_wrap_inline972 ()

(equal? foo foo) tex2html_wrap_inline972 #t

(eq? foo foo) tex2html_wrap_inline972 #t

(and  predicate1 predicate2)
Returns true if predicate1 and predicate2 both return true, false otherwise.

(or  predicate1 predicate2)
Returns true if either predicate1 or predicate2 return true, or false if neither of them return true.




next up previous contents index
Next: Numerical Predicates Up: Introductory Scheme Previous: List Manipulation

Steven J. Zeil
Tue Mar 4 14:36:27 EST 1997