This set of LISP Multiple Choice Questions & Answers (MCQs) focuses on “Setq and Setf”.
1. In the syntax (setf arg1 arg2), what is arg1?
a) Value to be set
b) Variable on which value is set
c) Set of lists
d) Set of elements forming a list
Explanation: The arg1 or argument 1 is like a variable in which value is stored. The arg1 can be anything like a symbol, a list or maybe the first element of a list, etc.
2. In the syntax (setf arg1 arg2), what is arg2?
a) A variable
b) A value to be set on arg1
c) It is the definition of arg1
d) A formula
Explanation: In general, the arg2 or argument2 is the value that is to be set on arg1. It can be a number, a list, a symbol, a formula, etc.
3. What is the notation used for writing LISP Syntax?
d) Different notations for different LISP Primitives
Explanation: Prefix notation is always used in LISP Syntax. It doesn’t change for different LISP Primitives. That is infix and postfix notations are not used.
4. What can be used as an argument for a primitive?
a) Atoms and List
b) Another LISP programs
c) A user-defined function
d) Atoms, List, Another LISP program, Used-defined function
Explanation: These all can be used as an argument for a primitive. Arguments depend on the type of primitive used. Example for arithmetic operators: numbers are used. For list functions: lists are used.
5. Choose correct statement about arg1 of setq syntax.
a) It is a list
b) It is a symbol in which value is stored
c) It is an arithmetic operator
d) It is a primitive
Explanation: In (setq arg1 arg2), the arg1 is like a variable in which value is stored. It can be a symbol. The value of arg2 got stored in it.
6. What is the value of q after this statement?
(setf q 2)
Explanation: Setf will give the value 2 to q. And q being a variable stores the value in it. And hence it’s value becomes 2.
7. What is the value of p after this statement?
(setq p (+ 3 4))
Explanation: (+ 3 4) evaluates to 7 and then p is given the value 7.
8. What will be the value of p after the following statement?
(setq p '(a b c d))
a) A B C D
b) B C D
Explanation: The list is the arg2 of the setq primitive. This list is being stored in the variable p, where p is the arg1 of the setq. There will not be any error as everything is correct.
Output: A B C D
9. What will be stored in tap after the execution of the following statement?
(setf tap (car '(plastic wood)))
c) PLASTIC WOOD
Explanation: The primitive car is used which will take out the first element of the list. So plastic is finally supplied as the value to be stored in variable tap.
10. Choose the correct output statement among these.
(setq float 3.33)
Explanation: The floating-point values are also being stored in the variables with the help of setq. And it also shows no error.
Sanfoundry Global Education & Learning Series – LISP Programming Language.