: (define x 4)
: (define y (cons 3 (cons x '())))
: y
??? BLANK 1a. ???
: (let ((x 3)
(y (* x 2)))
(+ x y))
??? BLANK 1b. ???
: (cond
((not (= x 4)) (error ``oops''))
((> x 4) (+ x (car y)))
((= x 4) (cdr y))
(else (* 2 x)))
??? BLANK 1c. ???
: (define (sum term a next b)
(if (> a b)
5
(+ (term a) (sum term (next a) next b))))
: (sum (lambda (z) (* 2 z))
10
(lambda (z) (* 10 z))
1000)
??? BLANK 1d. ???
\#t
if there are exactly 2 distinct values among them.
Your first line should look like this:
(define (twovals? a b c) ...
3a. (3 4 9)
3b. ((4 5) (3 9))
3c. (17 ((9)) . 5)
a,
b, and c
are bound to the lists of Question
3a, 3b, and 3c repectively.
car, cdr, and a
that returns the value 9.
car, cdr, and b
that returns the value 9.
car, cdr, and c
that returns the value 9.
reverse that takes a list as
an argument and returns a list of the same elements
in reverse order. For example:
: (reverse (list 1 4 9 16 25))
(25 16 9 4 1)
repeated that takes a function
f, a positive integer n and a list of numbers
lis, and returns the list of numbers resulting
from applying f to each element of lis n
times. The first line of your definition and a sample
of how it should work is as follows:
: (define (repeated f n lis) ...
: (repeated (lambda (x) (+ x 1)) 3 '(4 5 6))
(7 8 9)
: (repeated square 2 '(0 1 2 3))
(0 1 16 81)
Write 2 versions of repeated: one that generates an iterative
process and one that generates a recursive process.
For each version, describe the time and space requirements
(using Theta(...) notation). Your answer should be
in terms of n ; you may
assume that the lis has constant size.
(define (test n) (define (pair x) (cons x x)) (pair (random n)))Recall that (random n) returns a random number between 0 and n-1.
: (define (f g) (g 2))
: (f square)
4
: (f (lambda (z) (* z (+ z 1))))
6
: (f f)
??? WHAT DOES THE INTERPRETER DO HERE? EXPLAIN. ???