due 10/4/99
Try these questions out before section. First try to figure out the answers in your head. Then try typing them into the scheme interpreter.
Given the following definitions:
(define x 10) (define y 44) (define foo '(1 2 3)) (define bar '(a b c))what are the results of the following pieces of scheme code:
What are the results of the following pieces of code?
(if #f 5 10)
(if (or #t #f) 5 10)
(if #t (if #f 2 3) 10 )
(define x 3) (cond ((= x 1) 44) ((= x 2) (+ 5 50)) ((= x 3) (* 6 11)) (else (- 80 3)) )
(let ((x 5) (y 10) ) (+ x y) )
These are some sample problems that we will be discussing in section.
pi => 3.14159 (circle-area 2) => 12.56636 (circle-area 10) => 314.159
(fact 0) => 1 (fact 4) => 24
(define p1 (make-point 5 10)) => p1 (x-point p1) => 5 (y-point p1) => 10
(positive-only '()) => () (positive-only '(1 2 -3 4)) => (1 2 4) (positive-only '(-1 -2 -3)) => ()
Complete the following. You do not have to handle errors in input gracefully; however, if you want to you may use the error primitive function; e.g. (error "error in input"). Do not forget to turn in a print out of your source code as well as example executions of your code on test cases.
In the example output given below, we abbreviate make-point as mp. As well, when we show function output, we assume a two element list implementation of points. That is (make-point 1 2) => (1 2).
(closer-than? (mp 2 0) (mp 8 2)) => #t (closer-than? (mp -5 1) (mp 5 -1)) => #f
For example:
(partition-points (mp 3 0) (list (mp 1 0) (mp 3 0) (mp 4 0))) => (((1 0)) ((3 0) (4 0)))
For example:
(quicksort-points (list (mp 3 0) (mp 2 0) (mp -4 0) (mp 1 0))) => ((1 0) (2 0) (3 0) (-4 0))