Summary: The textbook discusses the following common Scheme predicates:
| Predicate | Example that returns True (#t) | Comment |
|---|---|---|
| number? | (number? 3.1415) | Is argument a number? |
| symbol? | (symbol? 'pi) | Is argument a symbol? |
| boolean? | (boolean? #t) | Is argument a boolean value? |
| pair? | (pair? '(a b)) | Is argument a [cons] pair? |
| null? | (null? '()) | Is argument the empty list? |
| procedure? | (procedure? car) | Is argument a procedure? |
| eq? | (eq? 'a 'a) | Do arguments represent identical symbols? |
| eqv? | (eqv? (car '(a a)) 'a) | Similar to eq? |
| equal? | (equal? '(b c) (cdr '(a b c))) | Are arguments the same symbols, numbers, booleans, or lists? |
Steps for this Lab:
This document is available through Netscape:
To find information on eq?, scroll down the table of contents to the main heading Standard procedures, and click on the subheader Equivalence predicates. When the Standard procedures ... Equivalence predicates page appears, scroll down to find descriptions for both eq? and eqv?. While the discussion may contain more detail that you really want or need, note that this document gives a precise statement about how Scheme works. Also, the description contains several examples.
Within Netscape, click the Back button once to return to the Table of Contents for the Scheme report. Since this document can serve as a valuable reference, you may want to record the URL address for future use. The easiest way to do this is to move the mouse to the Bookmarks menu and select the Add Bookmark option.
Now, move to the Bookmarks menu again and note that this Revised (5) Report ... is listed. In the future, you can return to this page just by selecting this bookmark.
Find a procedure which gives the integer quotient of two integer values; that is, the procedure should return the quotient of two integers, ignoring any remaineder. Thus, the integer quotient of 7 and 2 should be 3.
(eq? 'a 'a) (eqv? 'a 'a) (equal? 'a 'a) (eq? 'a 'b) (eqv? 'a 'b) (equal? 'a 'b) (eq? 3 3) (eqv? 3 3) (equal? 3 3) (eq? 3 4) (eqv? 3 4) (equal? 3 4) (eq? '(a) '(a)) (eqv? '(a) '(a)) (equal? '(a) '(a)) (eq? "abc" "abc") (eqv? "abc" "abc") (equal? "abc" "abc")In each case, be sure you can explain the results obtained.
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/151.fa98/lab-predicates.html