LISP Questions & Answers – LISP Primitives – 2

This set of LISP Questions and Answers for Aptitude test focuses on “LISP Primitives – 2”.

1. Choose the correct option for the output when lower or upper-case arguments are given in LISP.
a) Same output
b) Different output
c) LISP does not support lower case
d) LISP does not support upper case
View Answer

Answer: a
Explanation: LISP gives the same output for both the cases. In fact, LISP always gives output in upper case letters.

2. Which primitive can be used to create a list?
a) getf
b) setf
c) make
d) none of the mentioned
View Answer

Answer: b
Explanation: Setf is used to create the list. Getf is used to retrieve the data from list. Make is not a primitive in LISP.

3. What are the elements in list: tap in following LISP statement?

advertisement
advertisement
(setf tap '(water oil grease))

a) Water
b) Oil
c) Grease
d) Water oil grease
View Answer

Answer: d
Explanation: Setf is the primitive used to create a list. Tap will be initialised to water oil grease with the given statement.
Output: WATER OIL GREASE
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

4. Which primitive can be used to remove an element from List?
a) delete
b) cons
c) cdr
d) write
View Answer

Answer: a
Explanation: Delete is the primitive used to remove an element from list. The element to be removed is passed as an argument to delete primitive along with the list name from which element is to be deleted and delete will remove that element from list.

5. Which primitive can be used to add an element to List?
a) delete
b) cons
c) cdr
d) write
View Answer

Answer: b
Explanation: Cons is the primitive used to add an element to list. Cons take two lists as an argument and merge them to form a new list.
advertisement

6. What is the output of the following LISP program?

(setf chess '(king queen))
(write (cons 'rook chess))

a) rook king queen
b) king queen rook
c) king queen
d) rook
View Answer

Answer: a
Explanation: Cons is used to merge two lists provided to it as an argument. Here one list is rook and other is chess. So, cons will merge rook with chess at form a new list: rook king queen.
Output: ROOK KING QUEEN
advertisement

7. What is the output of the following LISP program?

(setf cricket '(bat ball racquet))
(write (delete 'racquet cricket))

a) bat ball racquet
b) bat ball
c) racquet bat ball
d) racquet
View Answer

Answer: b
Explanation: Delete is given racquet as an argument to delete it from list cricket. So, it will delete racquet from the list cricket to form a new list: bat ball.
Output: BAT BALL

8. What are 2 and 3 referred as in the following LISP statement?

(+ 2 3)

a) List
b) Arguments
c) It can be both List and argument
d) None of the mentioned
View Answer

Answer: b
Explanation: In LISP programming basic syntax, the first thing written is primitive and then arguments are written. So, in this way + is a primitive and 2,3 are arguments.

9. Are arithmetic operators primitives in LISP?
a) True
b) False
View Answer

Answer: a
Explanation: Yes, the arithmetic operators are primitives in LISP programming language. For example: in (/ 3 3) / is a primitive.

10. What is the output of (/ 6 3) and (- 6 4)?
a) 2 2
b) 1/2 2
c) 2 -2
d) 1/2 -2
View Answer

Answer: a
Explanation: Syntax of the LISP takes prefix expressions. So, 6/3=2 and 6-4=2 will be the outputs of the following statements.
Output: 2,2

Sanfoundry Global Education & Learning Series – LISP Programming Language.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

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.