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
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
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
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.
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
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?
(evenp (zerop (* 0 234)))
a) T
b) NIL
c) error
d) 0
View Answer
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.
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
Explanation: evenp work on negative numbers also. As the number is even so, the output is T.
Output: T
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
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
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
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
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.
To practice all areas of LISP for Entrance exams, here is complete set of 250+ Multiple Choice Questions and Answers on LISP Programming Language.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Practice Computer Science MCQs
- Check LISP Books
- Check Computer Science Books
- Apply for Computer Science Internship