LISP Questions & Answers – Lexical Variables

This set of LISP Multiple Choice Questions & Answers (MCQs) focuses on “Lexical Variables”.

1. Which makes it possible to define sophisticated generator procedures that produce new values?
a) List
b) Variables
c) Encapsulation
d) None of the mentioned
View Answer

Answer: c
Explanation: Encapsulation makes it possible to define sophisticated generator procedures that produce new values each time they are called.

2. Which primitive enables you to define one procedure inside another?
a) Do
b) List
c) Primitive
d) Labels
View Answer

Answer: d
Explanation: The labels primitive enables you to define one procedure inside another.

3. Which helps to produce nested fences?
a) Lets
b) List
c) Label
d) None of the mentioned
View Answer

Answer: a
Explanation: Lets helps to produce nested fences.
advertisement
advertisement

4. Which do not produce nested fences?
a) Variables
b) Procedure calls
c) Fences
d) All of the mentioned
View Answer

Answer: b
Explanation: Procedure calls do not produce nested fences.

5. Which makes nameless procedures into lexical closures?
a) $
b) #
c) #’
d) *
View Answer

Answer: c
Explanation: #’ makes it possible to produce nameless procedures into lexical closures.

6. What is the output of the given statement?

span class="sy0"> * (defun first-of-first-with-labels (l) (labels ((aux (m) (first m))) (first (aux 1))))
* (first-of-first-with-labels '((a b) (c d)))

a) A
b) B
c) C
d) D
View Answer

Answer: a
Explanation: This statement will produce the result as first given variable.
Output:
A
advertisement

7. What is the output of the given statement?

advertisement
span class="sy0"> * (defun power-of-two () (setf previous-power-of-two (* previous-power-of-two 2)))
* (power-of-two)
* (power-of-two)

a) 1
b) 2
c) 4
d) None of the mentioned
View Answer

Answer: c
Explanation: This statement will compute the power of two by executing certain number of times.
Output:
4

8. What is the output of the given statement?

span class="sy0"> * (defun square (list-of-numbers) (mapcar #'(lambda (n) (*n n)) list-of-numbers))
* (square '(1 2 3))

a) 9
b) 1
c) 3
d) 1 4 9
View Answer

Answer: d
Explanation: This statement will compute the square of all given numbers.
Output:
(1 4 9)

9. What is the output of the given statement?

span class="sy0"> * (setf square-procedures #'(lambda (n) (* n n)))
* (funcall square-procedure 2)

a) 1
b) 2
c) 3
d) 4
View Answer

Answer: d
Explanation: This statement will compute the procedure of square using the given statement.
Output:
4

10. What is the output of the given statement?

span class="sy0"> * (setf g1 (let ((previous-power-of-two 1)) #'(lambda () (setf previous-power-of-two (*previous-power-of-two 2)))))
* (g1)

a) G1
b) 0
c) Let
d) Error
View Answer

Answer: d
Explanation: This statement will create an error because of lag in number of arguments.

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.