LISP Questions & Answers – Procedure Definitions – 2

This set of LISP MCQs focuses on “Procedure Definitions – 2”.

1. In LISP, symbol represents a _____
a) Data type
b) Data type and data object
c) Data structure
d) Any of Data type, data object and data structure
View Answer

Answer: d
Explanation: In LISP programming, Symbols can be considered all of these. Mostly these are known as data objects and sometimes are also known as data structures or data types.

2. Which primitive is used to define a procedure?
a) defun
b) defpro
c) defin
d) def
View Answer

Answer: a
Explanation: defun is used for defining procedures. defun is the shorthand notation of deine function in LISP programming.

3. Can the parameters be passed to procedures in LISP?
a) No
b) Yes
View Answer

Answer: b
Explanation: Yes, the parameters can be passed to procedures. Parameter passing is the most important part of the procedures. Actual parameters are passed to the procedures while function invoking.
advertisement
advertisement

4. Can the actual parameters and formal parameters be of same name?
a) Yes
b) No
View Answer

Answer: a
Explanation: Yes, the actual and formal parameters can be of same name. The scope of the formal parameter remains within the procedure in this case.

5. Does value of an actual parameter change in the procedure?
a) Yes
b) No
c) Sometimes
d) None of the mentioned
View Answer

Answer: c
Explanation: The value of the actual parameter does not change only when the name of actual and formal parameters is same. In all other cases, the value of the actual parameter can change.

6. What is the output of the following LISP program? (NOTE: * means new line)

(defun b(p) (+ p p) )
* (setq z 1)
* (b z)

a) 2
b) 1
c) 3
d) error
View Answer

Answer: a
Explanation: The parameter z=1 is passed to the function named b and then within the function the p+p=2 is done. Thus, function will return 2 as an output of this program.
Output: 2
advertisement

7. What will be output of the following LISP program?

advertisement
(defun b(z) (+ z z) )
* (setq z 1)
* (write b z)

a) Error
b) 2
c) 1
d) no output
View Answer

Answer: b
Explanation: It has been shown here that the name of the actual and formal parameters can be same and there will not be any error. z=1 is given to function and then function will return z+z=2 as an output.
Output: 2

8. What will be stored in Z at A & B?

(defun b (z)
z 			(Position A)
(setf z '(u v)) )
* (setf z '(c d))
* (b z)
* z 			(Position B)

a) (C D) (C D)
b) (C D) (U V)
c) (U V) (U V)
d) (U V (C D)
View Answer

Answer: a
Explanation: The value of actual parameter do not change here because the name of actual parameter and formal parameter is same and thus the scope of variable z remains within the procedure and do not reflect the change out of the procedure.
Output: (C D)(C D)

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

(defun raw(p) (if (equal p '(not cooked)) (setq q 'YES) (setq q 'NO)))
(setq rice '(not cooked))
*(raw rice)

a) YES
b) NO
c) NIL
d) T
View Answer

Answer: a
Explanation: Rice is given the value “not cooked”. function raw is given the rice as parameter. In the function, the if statement will check if ‘(not cooked) is equal to rice using equalp predicate. As equalp returns T so the function will execute the if part of the statement, that is, YES and print it on the output.
Output: YES.

10. What is the value of (cons q 4) after the execution of this LISP program?

(defun multiply(p q) (* p q))
*(cons 4 (multiply 2 4))

a) (8 . 8)
b) (4 . 4)
c) (4 . 8)
d) (8 . 4)
View Answer

Answer: c
Explanation: In this program function name is used as an argument. p and q will take the values 2 and 4 respectively. Then, function will return 2*4=8 as the value to one of the arguments of the cons. Then cons will make construct of 4 and 8 as (4 . 8)
Output: (4 . 8)

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.