250+ TOP MCQs on Procedure Definitions and Answers

LISP MCQs on “Procedure Definitions”.

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

Answer: d
Clarification: In LISP programming, Symbols can be consered 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

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

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

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

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

Answer: c
Clarification: 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

  250+ TOP MCQs on S-Expression and Answers

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

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

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

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

Answer: b
Clarification: 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)

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

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

  250+ TOP MCQs on Predicates and Answers

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)

Answer: c
Clarification: 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)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top