LISP Multiple Choice Questions 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
Answer: a
Clarification: 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
Answer: c
Clarification: 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
Answer: b
Clarification: Procedures should report on what is going on when they encounter unexpected situations.
4. Which causes procedures to print their arguments and values?
a) Time
b) Describe
c) Trace
d) Break
Answer: c
Clarification: 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
Answer: d
Clarification: To evaluate forms, break is used which will stops evaluation and we can evaluate forms.
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
Answer: b
Clarification: This statement will reoccur over the statement again and again.
Output:
4
7. 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 test)))
a) 4
b) 5
c) 6
d) 7
Answer: d
Clarification:
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
Answer: c
Clarification: 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
Answer: d
Description: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
Answer: d
Clarification: 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
