CS 227 lecture -*- Outline -*- * predicates (p. 23 ff) ** type predicates *** the problem Scheme objects are of several types: numbers, symbols, pairs to make sure procedure is passed the right kind of data, need to be able to tell what type each argument is. *** boolean #t is true #f is false no need to quote ------------- THE BOOLEANS def: a boolean value is either true or false. def: a boolean object is either #t or #f def: a predicate is a function of type (-> () boolean) ------------- *** predicate procedure that asks a true/false question result is a boolean *** type predicates, spend a little time on null? go quickly through the rest, giving examples (have them call out answers) use with several types -------------- TYPE PREDICATES null?: (-> (datum) boolean) pair?: (-> (datum) boolean) number?: (-> (datum) boolean) symbol?: (-> (datum) boolean) boolean?: (-> (datum) boolean) procedure?: (-> (datum) boolean) -------------- draw connection of these to types ** equality predicates tests for different types more specific tests are faster if they work ------------------ EQUALITY PREDICATES SPECIFIC, FAST eq?: (-> (symbol symbol) boolean) = : (-> (number number) boolean) eqv? : (and (-> (symbol symbol) boolean) (-> (number number) boolean) (-> (boolean boolean) boolean)) equal?: (-> (datum datum) boolean) GENERAL, SLOWER ------------------- eqv? means equal value... * show how to play the car-cdr game (load "/home/cs227/homework/data/car-cdr-game-example.so")