LISP Questions & Answers – Rules For Good Programming

This set of LISP Multiple Choice Questions & Answers (MCQs) focuses on “Rules For Good Programming”.

1. Which arranges for one object to be placed on another?
a) Put-on
b) Put-up
c) Variable
d) List
View Answer

Answer: a
Explanation: Put-on arranges the object one after the another in lisp.

2. How the put-on will succeed in lisp?
a) No error
b) All procedures failed
c) All sub-procedures succeeds
d) None of the mentioned
View Answer

Answer: c
Explanation: Put-on will succeed only if all its sub-procedures succeed.

3. Which should report when lisp is encountered with unexpected situations?
a) List
b) Procedures
c) Variables
d) None of the mentioned
View Answer

Answer: b
Explanation: Procedures should report on what is going on when they encounter unexpected situations.
advertisement
advertisement

4. Which causes procedures to print their arguments and values?
a) Time
b) Describe
c) Trace
d) Break
View Answer

Answer: c
Explanation: Trace causes procedures to print their arguments and values.

5. Which stops evaluation so that you can evaluate forms?
a) Time
b) Describe
c) Trace
d) Break
View Answer

Answer: d
Explanation: To evaluate forms, break is used which will stops evaluation and we can evaluate forms.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. What is the output of the given statement?

span class="sy0"> * (defun count-atoms (expression);
  (if (atom expression)
  1
  (+ (count-atoms (first expression))
  (count-atoms (rest expression)))))
* (count-atoms '((this is)))

a) Count-atoms
b) 4
c) Count
d) None of the mentioned
View Answer

Answer: b
Explanation: This statement will reoccur over the statement again and again.
Output:
4
advertisement

7. What is the output of the given statement?

advertisement
span class="sy0"> * (defun count-atoms (expression);
  (if (atom expression)
  1
  (+ (count-atoms (first expression))
  (count-atoms (rest expression)))))
*(count-atoms '((this is) (a test)))

a) 4
b) 5
c) 6
d) 7
View Answer

Answer: d
Explanation:
0: (COUNT-ATOMS ((THIS IS) (A TEST)))
1: (COUNT-ATOMS (THIS IS))
2: (COUNT-ATOMS THIS)
2: COUNT-ATOMS returned 1
2: (COUNT-ATOMS (IS))
3: (COUNT-ATOMS IS)
3: COUNT-ATOMS returned 1
3: (COUNT-ATOMS NIL)
3: COUNT-ATOMS returned 1
2: COUNT-ATOMS returned 2
1: COUNT-ATOMS returned 3
1: (COUNT-ATOMS ((A TEST)))
2: (COUNT-ATOMS (A TEST))
3: (COUNT-ATOMS A)
3: COUNT-ATOMS returned 1
3: (COUNT-ATOMS (TEST))
4: (COUNT-ATOMS TEST)
4: COUNT-ATOMS returned 1
4: (COUNT-ATOMS NIL)
4: COUNT-ATOMS returned 1
3: COUNT-ATOMS returned 2
2: COUNT-ATOMS returned 3
2: (COUNT-ATOMS NIL)
2: COUNT-ATOMS returned 1
1: COUNT-ATOMS returned 4
0: COUNT-ATOMS returned 7
Output:
7

8. What is the output of the given statement?

span class="sy0"> * (defun current (n);
  (if (= n 1)
  1
  (+ (minus-one n) (minus-two n))))
* (defun minus-one (n)
  (current (- n 1)))
* (defun minus-two (n)
  (current (- n 2)))

a) Minus-one
b) Minus-two
c) Error
d) None of the mentioned
View Answer

Answer: c
Explanation: Because of the given statement the control stack will be exhausted.

9. What is the output of the given statement?

span class="sy0"> * (setf symbol-example '(a b c))
* (describe 'symbol-example)

a) A
b) B
c) C
d) Description of symbol-example
View Answer

Answer: d
Explanation: Describe is used to print the information about the current procedure or variable.
Output:
COMMON-LISP-USER::SYMBOL-EXAMPLE
[symbol]

SYMBOL-EXAMPLE names an undefined variable:
Value: (A B C)

10. What is the output of the given statement?

span class="sy0"> * (defun count-atoms (expression);
  (if (atom expression)
  1
  (+ (count-atoms (first expression))
  (count-atoms (rest expression)))))
* (time (count-atoms '((this is))))

a) 4
b) Depending on your compiler
c) Error
d) Both 4 & Depending on your compiler
View Answer

Answer: d
Explanation: This statement will print the information about the compilation and resource used.
Output:
0: (COUNT-ATOMS ((THIS IS)))
1: (COUNT-ATOMS (THIS IS))
2: (COUNT-ATOMS THIS)
2: COUNT-ATOMS returned 1
2: (COUNT-ATOMS (IS))
3: (COUNT-ATOMS IS)
3: COUNT-ATOMS returned 1
3: (COUNT-ATOMS NIL)
3: COUNT-ATOMS returned 1
2: COUNT-ATOMS returned 2
1: COUNT-ATOMS returned 3
1: (COUNT-ATOMS NIL)
1: COUNT-ATOMS returned 1
0: COUNT-ATOMS returned 4
Evaluation took:
0.001 seconds of real time
0.000000 seconds of total run time (0.000000 user, 0.000000 system)
0.00% CPU
14 forms interpreted
1,654,235 processor cycles
43,976 bytes

4

Sanfoundry Global Education & Learning Series – LISP Programming Language.

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.