LISP Questions & Answers – Setq and Setf

«
»

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
View Answer

Answer: b
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.
advertisement

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
View Answer

Answer: b
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?
a) Prefix
b) Infix
c) Postfix
d) Different notations for different LISP Primitives
View Answer

Answer: a
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
View Answer

Answer: d
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
View Answer

Answer: b
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?

advertisement
(setf q 2)

a) 2
b) 22
c) 222
d) 3
View Answer

Answer: a
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.
Output: 2

7. What is the value of p after this statement?

(setq p (+ 3 4))

a) 7
b) 3
c) 4
d) Error
View Answer

Answer: a
Explanation: (+ 3 4) evaluates to 7 and then p is given the value 7.
Output: 7

8. What will be the value of p after the following statement?

advertisement
(setq p '(a b c d))

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

Answer: a
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)))

a) PLASTIC
b) WOOD
c) PLASTIC WOOD
d) Error
View Answer

Answer: a
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.
Output: PLASTIC.

10. Choose the correct output statement among these.

(setq float 3.33)

a) 3.33
b) FLOAT
c) Error
d) 3
View Answer

Answer: a
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.

advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn