Type T Array (1..10) of Integer S T A: T B: T C: S D: Array (1..10) of Integer
Type T Array (1..10) of Integer S T A: T B: T C: S D: Array (1..10) of Integer
Type T Array (1..10) of Integer S T A: T B: T C: S D: Array (1..10) of Integer
Compiler can evaluate this expression in either lazy order (condition is evaluated before expression) or eager order
(condition and expression are evaluated together). Most programming languages follow lazy order evaluation.
Explain with example what may be the problem with eager order evaluation?. 4M
Q2. Languages such as Java, C++ and C# provides explicit parametric polymorphism and Languages such as ML,
Smalltalk, and some scripting languages support implicit parametric polymorphism i.e. functions naturally accept
arguments of any type that supports the operations applied to them by the function. Discuss the strengths and
weakness of explicit and implicit parametric polymorphism. 4M
Q3. Meaning of the keywords value, ref, result, and name when associated with parameters is given below
value: pass by value, ref: pass by reference, result: pass by value result and name: pass by name. 10M
void function 1(ref a, ref b, result c, result d) int function2(int name i, int value start, int value stop, int name
{ expr) { int
a= a+b+c+d; ret=0; i=start;
b= a+b+c+d; while(i!=stop){ ret =ret + expr; i=i+1) } return(ret);
c= a+b+c+d; }
d= a+b+c+d; void main( ) { int x =2,y; y= function2(x,0,5,x,x); }
a= a+b+c+d; a) For each iteration of the loop, write values of i, ret, and expr.
} i ret expr
void main( ) Before Loop:
{ Iteration 0:
int x =1;y=2; Iteration 1:
function(x,y,x,x); Iteration 2:
} Iteration 3:
What is the value of x and y when main( ) Iteration 4:
completes its execution? b) What is the value of x and y when main( ) completes its
execution?
Assume that the arguments are copied back
from left to right.
Q4. Consider the scheme like program given below. Give output for different combinations of variable binding and
binding of functions arguments. 8M
(define x 0)
(define y 0)
(define (f z) (display ( + z y))
(define (g f) (let ((y 10)) (f x)))
(define (h) (let ((x 100)) (g f)))
(h)
Variable binding Function argument binding Output
Static Dynamic Shallow Deep
☺ ☺
☺ ☺
☺ ☺
☺ ☺
Q5. In the following code, which of the variables will a compiler consider to have compatible types under structural
equivalence? Under strict name equivalence? Under loose name equivalence? 3M
type T = array [1..10] of integer
S=T
A:T
B:T
C:S
D : array [1..10] of integer
Q6.
Q6a.The Let construct is not a fundamental scheme primitive. Give a lambda expression that has the same effect as
the following Let expression: (let ((v1 e1) (v2 e2)) x) 3M
Q8. Perform β-reduction using lazy and eager evaluation order on the λ-expression as much as possible. 10M
(λabc. abc)( λxy. x)(( λf. fff)( λg. g))(( λwv. wv)( λt. t)( λu. u))
Q8. Complete the following program which convert prefix expression to infix expression 5M
(define infix
(lambda (expr)
(if (list? expr)
(cond
((= 2 (length expr)) (list (car expr) (infix (Q8a))))
((= 3 (length expr))
(list (infix (cadr expr)) (car expr) (infix (Q8b)))
) (else expr)
)
expr Sample Input: (infix '(+ (+ (^ (- x) 2) (* 2 x)) 1))
) Sample Output: '((((- x) ^ 2) + (2 * x)) + 1)
)
)
Q9. Define a scheme function pairwise that accepts a function f and returns a function that accepts an even number
of arguments, applies f to successive pairs of arguments, and returns the list of results; an empty list should be
returned if the number of arguments is odd. 7M
((pairwise +) 1 2 3 4 5 6) produces (3 7 11)
a. Give the run time stack right before the helper_three returns. Show static and dynamic link. 5M
b. Give the reference pair (chain offset, local offset) for each variables at Position 1and Position 2 in the functions.
3M
Q14. We had written a recursive version of sum-list to perform summation of all elements in the list. Was that tail
recursive? if no, modify the function to be tail recursive. 5M
Discuss the strength and weakness of tail-recursive and not tail-recursive functions. 2M