Com S 342 meeting -*- Outline -*- * logical connectives (3.2) ------------------------------------------ LOGICAL CONNECTIVES (3.2) problem: verbosity (define member? ;; TYPE: (-> (T (list T)) boolean) (lambda (e ls) (if (not (null? ls)) (if (equal? e (car ls)) #t (member? e (cdr ls))) #f))) solution: (define member? ;; TYPE: (-> (T (list T)) boolean) (lambda (e ls) TERMS short-circuit evaluation conditional-evaluation ------------------------------------------ ... (and (not (null? ls)) (or (equal? e (car ls)) (member? e (cdr ls)))))) Q: Can or evaluate all its arguments? What would happen? no, it would loop bring out importance of short-circuit evaluation ------------------------------------------ SYNTAX OF LOGICAL CONNECTIVES ::= SEMANTICS ------------------------------------------ ... (or {}*) | (and {}*) | ... ... (or ) = #f (or e1 e2 ...) = (if e1 #t (or e2 ...)) (and ) = #t (and e1 e2 ...) = (if e1 (and e2 ...) #f) Actually, in Scheme anything not #f is true, so or is a bit more complex in reality, see the book Q: What's this like in other languages? in C? in Pascal? || and && in C, not | and & Pascal has no equivalent cor, cand in Algol 68? and_then, or_else in Ada ------------------------------------------ FOR YOU TO DO Rewrite the following using "and" and "or" (define foo? ;; TYPE: (-> (datum) boolean) (lambda (x) (if (pair? x) (if (number? (car x)) #t (number? (cdr x))) #f))) Define the predicate is-application? : (-> (datum) boolean) to test whether a datum is a list of length two. ------------------------------------------