LISP Questions & Answers – Pattern Matching

This set of LISP Multiple Choice Questions & Answers (MCQs) focuses on “Pattern Matching”.

1. Which procedure is used as key element in a backward chaining algorithm?
a) Matching
b) Unification matching
c) Verification
d) None of the mentioned
View Answer

Answer: b
Explanation: The unification matching procedure is a key element in a backward chaining.

2. What is the way of expressing an ordinary expression in terms of bits?
a) Datum
b) Data
c) Manipulation
d) Verification
View Answer

Answer: a
Explanation: The process of expressing an ordinary expression in terms of bits is called datum.

3. What is the name of elements present in patterns?
a) Variables
b) Patterns
c) Pattern variables
d) Pattern elements
View Answer

Answer: c
Explanation: Patterns can contain elements called pattern variables.
advertisement
advertisement

4. Which keeps variable binding on an association list?
a) Match
b) Compare
c) Equal
d) None of the mentioned
View Answer

Answer: a
Explanation: Match keeps variable binding on an association list.

5. Which is used to compare patterns and datums element by element?
a) Procedure
b) Compare
c) Equal
d) Matching
View Answer

Answer: d
Explanation: To compare patterns and datums element by element matching is used.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. What is the output of the given statement?

span class="sy0"> * (setf pattern-variable-expression '(? x))
* (setf datum 'apple)
* (setf bindings '((y red)))
* (second pattern-variable-expression)

a) X
b) Red
c) Apple
d) None of the mentioned
View Answer

Answer: a
Explanation: The result will be x because the second element is referred in pattern.
Output:
X
advertisement

7. What is the output of the given statement?

advertisement
span class="sy0"> * (setf pattern-variable-expression '(? x))
* (setf datum 'apple)
* (setf bindings '((y red)))
* (list (second pattern-variable-expression) datum)

a) x
b) Y
c) Apple
d) Both x & Apple
View Answer

Answer: d
Explanation: The elements from the given list is listed using the given statement.
Output:
(X APPLE)

8. What is the output of the given statement?

span class="sy0"> * (cons (list (second pattern-variable-expression) datum) bindings)

a) (X apple)
b) (Y orange)
c) (X apple) (Y orange)
d) None of the mentioned
View Answer

Answer: c
Explanation: This statement will list all the elements in datum and bindings.
Output:
((X APPLE) (Y RED))

9. What is the output of the given statement?

span class="sy0"> * (defun add-binding (pattern-variable-expression datum bindings) 
  (if (eq '_ (extract-variable pattern-variable-expression)) bindings (cons 
  (make-binding (extract-variable pattern-variable-expression) datum) bindings)))
* (add-binding '(? _) 'apple '((y red)))

a) X
b) Y
c) (X apple)
d) (Y red)
View Answer

Answer: d
Explanation: This statement is used for adding a binding in the pattern.
Output:
((Y RED))

10. What is the output of the given statement?

span class="sy0"> * (defun find-binding (pattern-variable-expression binding)
  (unless (eq '_(extract-variable pattern-variable-expression))
  (assoc (extract-variable pattern-variable-expression) binding)))
* (find-binding '(? _) '((x apple) (y red)))

a) X
b) Apple
c) T
d) Nil
View Answer

Answer: d
Explanation: This statement is used to find a binding in the given pattern.
Output:
NIL

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.