Assignment 6 Problem I – Scheme


Rate this product

Assignment 6
Problem I – Scheme
Write Scheme programs that generate the following lists as output using only
cons as the list building operator:
1. ‘((c (e f (b))) g b)
2. ‘((g) ((((h) i)) (a f)) d)
3. A list l that contains three items: the atom ’g’,
the division operator ’/’, and the atom ’6’ such that
((cadr l) 18 9) evaluates to 2.
Note that cadr is composed of car and cdr such that (cadr l) = (car
(cdr l)).
Problem II – Scheme
Write the following functions on lists in Scheme. The semantics of the functions is described through examples.
1. Get nth digit of an integer
(define getnthdigit
(lambda (m n)

(getnthdigit 32145 1) — 5
(getnthdigit 32145 2) — 4
Note: You can use Scheme build-in function ”modulo” and ”floor”.
2. (define rev
(lambda (l)

(rev ‘(e((b)(c d)(((f)))))) — ‘(((((f)))(d c)(b))e)
Note: Do not use the Scheme build-in function ”reverse”.
3. Position of first occurrence of k in list
(define positionof
(lambda (k lst)

(positionof ‘c ‘(c b d c e f)) — 1
Note: You may want to define a helper function

Open chat
Need help?
Can we help you?