7. In the space below, complete the definition of add-between, which takes a lis
ID: 3667110 • Letter: 7
Question
7. In the space below, complete the definition of add-between, which takes a list ls and an expression x, and inserts x between every two elements of ls.
Consider the following calls below as examples of its usage.
>(add-between 'and ' (1 2 1 2))
(1 and 2 and 1 and 2)
>(add-between 'and '())
()
>(add-between 'and '(1 1))
(1 and 1)
>(add-between 'and '(1))
(1)
8. Consider the function foo below:
(define foo
(lambda (x y)
(cond
((null? x) y)
((memv (car x) y) (foo (cdr x) y))
(else (cons (car x) (foo (cdr x) y))))))
Which of the following is a better name for foo?
A.union
B. set difference
C.binary XOR
D.append
9. Consider the function bar below:
(define bar
(lambda (x f)
(cond
((not (pair? x)) (f x))
(else (cons (bar (car x) f) (bar (cdr x) f))))))
What is a better name for the the function bar?
A. map-tree
B. cons-cell-count
C. occurs?
D. constant #t (that is, a function which always returns true)
Explanation / Answer
8) Append
9)Map-Tree
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.