Summary: The Scheme language includes the expressions "and", "or", and "not". When these are applied to Boolean values ( #t and #f), the results follow the conventions from mathematics. Thus, (and A B) is true if both A and B are true and false otherwise. (or A B) is true (#t) if either A is true or B is true (or both). not applied to any true value produces false (#f), and (not) applied to false (#f) returns true (#t).
More generally, "and" and "or" may take as many arguments as desired. "and" is true if all arguments are true, and "or" is true if any of the arguments is true.
Important Note: Scheme is reasonably liberal in its evaluation of expressions, in that anything that is not explicitly false (#f) is considered true.
Scheme's cond statement uses expressions to determine what action is to be taken. This is illustrated in the following procedure:
(define type-of-number (lambda (A) (cond ((< A 0) "the number is negative") ((> A 0) "the number is positive") (else "the number is zero") ) ) )Within this cond expression, (< A 0) is first examined. If it is true, the clause "the number is negative" is evaluated and returned. [Evaluation of the cond expression is finished.] If, however, the expression (< A 0) is false, then evaluation proceeds with the next expression (> A 0). Again, if this expression is true, the following expression "the number is positive" is evaluated, and evaluation of cond is completed. But if this expression also is false, then we move to the next part of cond. else signifies that if we get this far, then the action that follows should be evaluated.
Scheme's if expression uses a conditional expression to determine which of two actions to take. This is illustrated in the following procedure:
(define is-negative (lambda (A) (if (< A 0) "the number is negative" "the number is nonnegative" ) ) )
Steps for this Lab:
(and #t #t) (and #f #t) (and #t #f) (and #f #f) (and #t #t #t #t) (and #t #t #f #t) (or #t #t) (or #f #t) (or #t #f) (or #f #f) (or #t #t #t #t) (or #f #t #f #f) (or #f #f #f #f) (not #t) (not #f)In each case, explain why Scheme produced the result given.
(and 'cat #t) (and #f 'cat) (and 'cat #f) (and #f #f) (and #t #t 'cat #t) (and #t #t #t 'cat) (and #t #t #t 'cat 'dog) (or #t 'cat) (or 'cat #t) (or #f 'cat) (or 'cat #f) (or 'cat 'dog) (or #f #f) (not 'cat)In each case, state why you think Scheme produces the result given. Generalize the results to indicate what values and, or, and not return when they are applied to non-Boolean values.
(define not-and (lambda (A B) (not (and A B))))Explain why this procedure evaluates the logical expression "Not (A And B))".
This may be done with the copy or cp command as follows:
cp ~walker/153/labs/smallest.ss .This command should be executed in an hpterm window. Within this command, the final dot . is an abbreviation for your current directory. Thus, in this expression, you are telling the machine to copy (cp) the current file ~walker/153/labs/smallest.ss to your current directory. The new file will appear in your directory with the same name, smallest.ss. If you wanted the program to have a different name (e.g., my-program.ss), then you could change your copy command to:
cp ~walker/153/labs/smallest.ss my-program.ss
(if (???1) "A is smaller than both B or C." #then clause (;;; the else clause -- A is not smaller if (???2) #second condition within cond "B is smaller than both A and C." ;;; the second else cause -- B is not smaller either ??? etc. ) )
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/153.sp00/lab-cond-if.html