LISP Questions & Answers – Iteration

This set of LISP Multiple Choice Questions & Answers (MCQs) focuses 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
View Answer

Answer: c
Explanation: Iteration is said to be one kind of control strategy and it is a general strategy for controlling how a computation evolves.

2. Which provides a way to write simple counting-oriented iteration procedures?
a) Do
b) Dotimes
c) Recursion
d) Iteration
View Answer

Answer: b
Explanation: Dotimes provides 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
View Answer

Answer: a
Explanation: If a dotimes form has no result form, the dotimes will return nil and its purpose is to arrange for side effects.
advertisement
advertisement

4. What will be occupied in the first part of DO?
a) Procedures
b) List
c) Iterators
d) List of parameters
View Answer

Answer: d
Explanation: 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
View Answer

Answer: a
Explanation: All initialization forms are evaluated before before inital binding.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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
View Answer

Answer: a
Explanation: The statement contains prog1 which is used to print the first value of the given list.
Output:
X
advertisement

7. What is the output of the given statement?

advertisement
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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: c
Explanation: This statement will make the use of progn to print last value in the given list.
Output:
Z

Sanfoundry Global Education & Learning Series – LISP Programming Language.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.