# 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

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

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

Explanation: Patterns can contain elements called pattern variables.

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

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

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

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

7. What is the output of the given statement?

```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

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

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)

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

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

Sanfoundry Global Education & Learning Series – LISP Programming Language.