LISP Questions & Answers – Predicates – 2

This set of LISP Questions and Answers for Entrance exams focuses on “Predicates – 2”.

1. Which of the following is used by member primitive to compare arguments?
a) =
b) equalp
c) equal
d) eql
View Answer

Answer: d
Explanation: Eql is used by member argument to compare between its two arguments. Eql is one of the equality predicates and is used to test for numbers and symbols of the same type.

2. Which among these are the data type predicates?
a) atom
b) symbolp
c) listp & numberp
d) atom, symbol, listp & numberp
View Answer

Answer: d
Explanation: Atom, symbolp, listp, numberp all are considered as data type predicates. Atom is used check if an argument is atom or not. Similarly, symbolp is used to check symbols, listp to check lists and numberp to check whether the argument is a number or not.

3. What is the use of zerop?
a) To check object is zero
b) To check object is NIL
c) To make non-zero object to zero
d) It is same as integerp
View Answer

Answer: a
Explanation: It is the predicate used to check whether the argument is zero or not. It will show T (true) only if the argument is numeric zero, that is, 0 and NIL in all other cases.
advertisement
advertisement

4. Integerp and Zerop will be same __
a) When argument is not an integer or equal to 0
b) When argument is not equal to 0
c) When argument is a negative integer
d) When argument is a negative integer and not 0
View Answer

Answer: a
Explanation: Both integerp and zerop will be same when both will show either T or NIL. Both will show T when argument is 0 and NIL when argument is not an integer.

5. What will be the output of the following LISP statement?

Note: Join free Sanfoundry classes at Telegram or Youtube
(evenp (zerop (* 0 234)))

a) T
b) NIL
c) error
d) 0
View Answer

Answer: c
Explanation: Error will occur because zerop will give T as an argument to evenp which is not a number and hence evenp will not work.
advertisement

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

(evenp -4234234)

a) T
b) NIL
c) Number is too large
d) Error
View Answer

Answer: a
Explanation: evenp work on negative numbers also. As the number is even so, the output is T.
Output: T
advertisement

7. What is the output of the following LISP statement? (NOTE: Here * refers to a new line)

(defun rock() (setq p 8))
*(cons NIL (oddp (rock)))

a) NIL . NIL
b) ERROR
c) T . NIL
d) NIL
View Answer

Answer: d
Explanation: Cons primitive is used to make construct of two arguments given to it. Generally, the cons of A & B is (A . B) but for two NILs it will show only NIL.
Output: NIL

8. What will be the output of the following statement?

(cons (T NIL))

a) Error due to T and NIL are not lists
b) T
c) NIL
d) T . NIL
View Answer

Answer: b
Explanation: The cons of T & NIL is not (T . NIL). In this statement the T will dominate above NIL and thus T . NIL gives T on construct.
Output: T

9. What will be the output of the following program?

(defun root() (setq qw 'a))
*(equalp (root) 'a)

a) (cons NIL NIL)
b) T
c) NIL
d) Error
View Answer

Answer: b
Explanation: The function root will return ‘a after execution. Now, this is given as argument to equalp predicate. As both the arguments are ‘a so, the equalp will return T as output.
Output: T

10. What will be the output of the following statement?

(cons (car '(a b)) (cdr '(p q)))

a) P . Q
b) A . B
c) A . Q
d) A . P
View Answer

Answer: c
Explanation: car will give the first element of the list. So, one argument becomes A. cdr will give all elements except first element of the list. So, the second argument becomes Q. The cons of A and Q becomes A . Q
Output: A . Q

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.