Simple Facts and Rules
Prolog, Iteration 2
Work through Chapter 2 of Learn Prolog Now! (LNP!).
- Sections 2.1 & 2.2: read. Try interactively for your own edification.
- Section 2.3: do Exercises 2.1, 2.2, and 2.3, writing unit tests for each one. (See below.)
Unit Testing Hints
At least one example is taken from the documentation for PlUnit.
Exercise 2.1: Some of these assertions will seems silly (especially the early ones). For expressions with variables, add clauses to make the original expression true (if possible):
test(exercise2_1_8) :- food(X) = food(bread), X = bread.
Exercises 2.2 & 2.3: For expressions that
bind a variable to multiple values, use the
findall/3
:
test(member) :- findall(X, member(X, [a,b,c]), Xs), Xs == [a,b,c].
The expression in bold is the one under test.