Ch 5 Flashcards
Which of the following programming languages most closely follows the stored program concept?
C
Prolog is based on…
Predicate logic
There are three kinds of clauses in a Prolog program: facts, rules and goals.
A fact can be considered a special case of a rule.
What mechanism cannot be used for passing values between clauses within a Prolog rule?
Return value
If you want to pass multiple values out of a Prolog rule, which of the following methods is valid?
Use multiple named variables to hold the values.
A goal clause and a fact unify, if…
their predicates are the same,
their arities are the same,
and
their corresponding arguments match.
The arity of a predicate is…
the number of arguments of the predicate.
The scope of a Prolog variable is within…
a single rule.
A circular definition of a Prolog rule…
will cause a dead loop when no match can be found.
An anonymous variable in Prolog is a…
placeholder.
What is the output when the following Prolog goal is executed?
?-member(apple, [orange, apple, pearl]).
true?
Assume we have the following fact in a Prolog factbase:
child_of(mary, [amy, david, conrad]).
What is the output when the following Prolog goal is executed?
?- child_of(mary, [amy | T]).
T = [david, conrad]
Assume that we have the following fact in a Prolog factbase:
child_of(mary, [amy, david, conrad]).
What is the output when the following goal is executed?
?- child_of(mary, [amy | [H | [conrad]]]).
H = david
What is the output when the following Prolog goal is executed?
?- member(X, [81, 25, 9, 29,]), Y is X*X, Y<400.
X = 9 Y = 81
Given the following recursive rules in Prolog:
foo(X, [X]).
foo(X, [ _ | T]) :- foo(X, T).
The rules find…
whether an element is a member of a list.