LISP Multiple Choice Questions on “Procedure Definitions”.
1. Which is used to build the lisp procedures?
a) Data
b) Primitives
c) Definition
d) None of the mentioned
Answer: b
Clarification: Lisp procedures are formed by using lisp primitives and it is the primary purpose of procedure definition.
2. Which primitive removes all but the last element from the list?
a) Last
b) First
c) Remove
d) Revoke
Answer: a
Clarification: “Last” is used whenever there is a requirement of only last element of list.
3. What is a symbol thought of as a name for a place to store value?
a) Data
b) Variable
c) Parameters
d) None of the mentioned
Answer: b
Clarification: A variable is a symbol thought of as a name for a place to store value.
4. How many types of variables are available in lisp?
a) 1
b) 2
c) 3
d) 4
Answer: b
Clarification: There are two kinds of variables available in lisp. They are lexical variable and special variable.
5. What are the variables that are bound and that have values assigned to them?
a) Data
b) Variable
c) Parameters
d) None of the mentioned
Answer: c
Clarification: The parameter of a procedure are variables that are bound and have values assigned to them.
6. What is the output of the following statement?
span class="sy0"> * (setf meals '(breakfast lunch tea dinner)) * (cons (first meals) (last meals))
a) Breakfast
b) Lunch
c) Dinner
d) Both Breakfast & Dinner
Answer: d
Clarification: The statement will print the first and last value of the list because of the condition.
Output:
(BREAKFAST DINNER)
7. What is the output of the following statement?
span class="sy0"> * (setf whole-list '(monday tuesday wednesday thursday fray)) * (defun both-ends ()(setf whole-list (cons (first whole-list) (last whole-list))))
a) Monday
b) BOTH-ENDS
c) Fray Monday
d) Monday Fray
Answer: b
Clarification: The function defun is used to return the procedure name only.
Output:
BOTH-ENDS
8. What is the output of the following statement?
span class="sy0"> * (defun both-ends-with-special ()(setf whole-list (cons (first whole-list) (last whole-list)))) * (setf whole-list '(monday tuesday wednesday thursday fray)) * (both-ends-with-special)
a) Monday
b) Fray
c) Wednesday
d) Both Monday & Fray
Answer: d
Clarification: The value of whole-list is erected when a form involving both-ends-with-special is evaluated.
Output:
(MONDAY FRAY)
9. What is the output of the following statement?
span class="sy0"> * (setf meals '(breakfast lunch tea dinner)) * (first meals)
a) Breakfast
b) Lunch
c) Tea
d) Dinner
Answer: a
Clarification: The keyword first is used to print the first item of the list.
Output:
(BREAKFAST)
10. What is the output of the following statement?
span class="sy0"> * (setf x 'outse) * (let ((x 'inse) (y x)) (list x y))
a) Outse
b) Inse
c) Inse Outse
d) Outse Inse
Answer: c
Clarification: This statement is used to reverse the list.
Output:
(INSE OUTSE)
