Reputation: 297
I have this facts:
morpheme(a,82).
morpheme(r,83).
And i have this rule:
foo(er,Start) :-
morpheme(a,Start), morpheme(r,I), I is Start+1,
not(morfema(_,J)), J is I+1.
When I ask the query:
foo(er,82).
I got "false" (wrong answer) instead of "true" (correct answer).
In the query I've tried to say that: "if there is a morpheme AR in the start position "Start" and there are no more morphemes in higher positions (higher than Start+1), then fires the rule".
I tried using \+ and cut-fail (http://stackoverflow.com/questions/3850563/writing-prolog-statement-with-not-operator) but no success :(
I think that the problem is located in the way i wrote the rule.
Thanks in advance!!!
Upvotes: 1
Views: 172
Reputation: 297
Thanks False! That solved the problem. The modified code is below:
morpheme(a,82).
morpheme(r,83).
not(X) :- \+ X.
foo(er,Start) :-
morpheme(a,Start), I is Start+1, morpheme(r,I),
J is I+1, not(morpheme(_,J)).
Upvotes: 0
Reputation: 10102
Typo: morfema / morpheme.
But the deeper problem is the variable J
: At the point in time when the negation is tried, J
is an uninstantiated variable. Only afterwards, it gets the value you expect.
So exchange the two goals - and better use \+
in place of not!
The \+
means: not provable at this point in time. It therefore reveals a bit the way how Prolog programs are executed.
There is another problem in your program: You may move I is Start+1
one to the left. In this manner the morpheme(r,I)
will be a ground goal. It might be executed faster.
Upvotes: 1