CSE221 Structure and Interpretation of Computer Programs IV Semester CSE (Ettimadai)
CSE221 Structure and Interpretation of Computer Programs IV Semester CSE (Ettimadai)
Total Marks: 50
Duration: 2 hours
Part A (5 X 2 = 10 Marks)
1. Translate the following expression into Scheme expression. (2/3 + 4/9)÷(5/11 – 4/3)
2. Define a procedure smaller that takes two numbers as arguments and returns the smaller of them
using the special form if. Also rewrite the same procedure using cond.
3. Construct the following procedure (define (divides? a b) (= (remainder b a)
0)) using lambda.
4. Provide some of the “rights and privileges” of first-class procedures.
5. Give the box-and-pointer representation of (cons (cons 1 2) (cons 3 (cons 4
5))).
Part B (4 X 5 = 20 Marks)
6. Define necessary procedures that compute the sum of the squares of integers from a through b.
7. Define necessary procedures that compute the Least Common Multiple (LCM
) of given two numbers. (Hint: LCM of given two numbers a and b can be calculated as
ab/GCD(a,b) where GCD(a,b) is the Greatest Common Divisor of a and b which is equal to
GCD(b,r) where r is the remainder when a is divided by b.
(let ( (a (+ 4 7)))
(let ( (b (* a 5)))
(+ a b)))
B) Complete the <body> of the following procedure that computes the sum of the squares of a and
b
(define (sum-square a b)
(let ( (+ *)
(* +))
(<body>) ))
9. Given the following procedure repeated, what will be the value of the expression
((repeated square 2) 5) assuming that the procedure square computes the square of a
given number?
(define (repeated p n)
(cond ( (= n 0) (lambda (x) x))
( (= n 1) p)
( else (lambda (x) (p ((repeated p (- n 1)) x))))))
Part C (2 X 10 = 20 Marks)
10. Write necessary procedures (constructor, selectors and rules of operations) for doing
arithmetic operations viz. addition, subtraction and multiplication for complex numbers of the form
a+ib.
11. Imagine that there is a primitive procedure called counter with no arguments, that
returns 1 the first time you call it, 2 the second time and so on. Supposing that the counter has not
been called until now, show with necessary details the outputs of the following procedure calls each
using both applicative and normal order evaluation.
b) (square (counter))
where the definitions for above procedures times and square are as follows.