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.
When Prolog is searching for possible matches and a cut “!” is encountered,
all existing backtrack points will be removed.
What does the built-in predicate cut (!) do?
Remove all existing backtracking points.
What does the built-in predicate fail do?
Return false.
The built-in Prolog predicate repeat always…
succeeds and adds a backtracking point.
What does the following code do?
go :- repeat, get(X), write(X), nl, fail.
It takes a character from the keyboard, prints it, and exits if the character is NOT printable.
What is the key difference between the semantic web and the syntactic web?
Semantic web better supports automatic processing and integration of web information.
How is Prolog related to the semantic web?
Prolog is frequently used for writing the parsers of the semantic description language.