Goals: This lab provides practice with Scheme predicates, including predicates that test the type of an expression or the equivalence of expressions.
Summary: The textbook discusses the following common Scheme predicates:
| Predicate | Example that returns #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 on the World Wide Web:
To find information on eq?, scroll down the table of contents to the main heading Standard procedures, and click on the subheader Booleans. When the Standard procedures ... Booleans 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.
Within Netscape Navigator, 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 bring up the Bookmarks menu and select the Add Bookmark operation.
Now, move to the Bookmarks menu again and note that the Revised^4 report ... is listed. In the future, you can return to this page just by selecting this bookmark.
#f, but a comparison with equal? returns
#t.
This document is available on the World Wide Web as
http://www.math.grin.edu/courses/Scheme/spring-1997/lab-predicates.html