Skip to content

Commit c8f5fe7

Browse files
author
Georgi Shopov
committed
Fix entry repetition in exercise 12.2
Every time we ecnounter a word that is already in the database we have to delete its old entry and create a new one.
1 parent 55e400b commit c8f5fe7

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

chapter-12/exercises.pl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
addWordToDatabase(W) :-
3131
word(W, X),
32+
retract(word(W, X)),
3233
Y is X + 1,
3334
assert( word(W, Y) ), !.
3435

@@ -80,10 +81,6 @@
8081
%% false.
8182

8283
%% partial output from ?- listing.
83-
word(foo, 1).
84-
word(bar, 1).
85-
word(baz, 1).
86-
word(bozz, 1).
8784
word(newline, 1).
8885
word(bozz, 2).
8986
word(bar, 2).

0 commit comments

Comments
 (0)