A list of n elements is commonly written as a sequence of n elements enclosed…
PYQ GATE 1987
A list of n elements is commonly written as a sequence of n elements enclosed in a pair of square brackets. For example. [10, 20, 30] is a list of three elements and [] is a nil list. Five functions are defined below:
car(l) returns the first element of its argument list l;
cdr(l) returns the list obtained by removing the first element of the argument list l;
glue(a,l) returns a list m such that car(m)=a and cdr(m)=l.
f(x,y) ≡ if x=[] then y else glue(car(x), f(cdr(x),y));
g(x) ≡ if x=[] then [] else f(g(cdr(x)), glue(car(x),[]));
What do the following compute?
f([32,16,8],[9,11,12])
g([5,1,8,9])
Attempted by 2 students.
Sign up free to check your answer
Sign up freeLoading lesson…

