LISP Multiple Choice Questions on “Iteration”.
1. Which is a general strategy for controlling how a computation evolves?
a) Recursion
b) Mapping
c) Iteration
d) None of the mentioned
Answer: c
Clarification: Iteration is sa to be one kind of control strategy and it is a general strategy for controlling how a computation evolves.
2. Which proves a way to write simple counting-oriented iteration procedures?
a) Do
b) Dotimes
c) Recursion
d) Iteration
Answer: b
Clarification: Dotimes proves a way to write simple counting-oriented iteration procedures.
3. What will happen if a dotimes form has no result form?
a) Nil
b) T
c) Both Nil & T
d) Nothing
Answer: a
Clarification: If a dotimes form has no result form, the dotimes will return nil and its purpose is to arrange for se effects.
4. What will be occupied in the first part of DO?
a) Procedures
b) List
c) Iterators
d) List of parameters
Answer: d
Clarification: The first part of a DO is always occupied by a list of parameters that are all bound to initial values.
5. Which are evaluated before initial binding?
a) All initialisation forms
b) Iterations
c) Procedures
d) None of the mentioned
Answer: a
Clarification: All initialization forms are evaluated before before inital binding.
6. What is the output of the given statement?
span class="sy0"> * (prog1 (setf a 'x) (Setf b 'y) (setf c 'z))
a) X
b) Y
c) Z
d) XYZ
Answer: a
Clarification: The statement contains prog1 which is used to print the first value of the given list.
Output:
X
7. What is the output of the given statement?
span class="sy0"> * (defun dotimes-expt (2 4) (let ((result 1)); (dotimes (count 4 result); (setf result (* 2 result)))));
a) 2
b) 4
c) 8
d) 16
Answer: d
Clarification: This statement will calculate the power in given terms.
Output:
16
8. What is the output of the given statement?
span class="sy0"> * (setf freezing 32 boiling 212)
a) 32
b) 212
c) Both 32 & 212
d) None of the mentioned
Answer: b
Clarification: This statement will return last value always.
Output:
212
9. What is the output of the given statement?
span class="sy0"> * (setf cheers '(cheer cheer cheer)) * (setf loop-count 0) * (loop (when (endp cheers) (return loop-count)) (setf cheers (rest cheers)) (setf loop-count (+ loop-count 1)))
a) 0
b) 2
c) Cheers
d) 3
Answer: d
Clarification: This statement will count the number of times does the cheers appears by loop.
Output:
3
10. What is the output of the given statement?
span class="sy0"> * (progn (setf a 'x) (setf b 'y) (Setf c 'z))
a) X
b) Y
c) Z
d) XYZ
Answer: c
Clarification: This statement will make the use of progn to print last value in the given list.
Output:
Z
