Reputation: 11830
I'm trying to convert from this notation:
A and (B or C) equ A and B or A and C)
to standard logical notation i.e. things like and(A,B), or(A,B), neg(A)...
I thought that I nice way of doing it would be using DCGs (I made up this question because I want to practice DCGs). Any ideas why my conversion isn't working? So far I've just written the disjunction and the case when we get a variable. The answer I want should be or(atom(X),atom(Y)).
convert1(atom(X)) --> [X], {var(X)},!.
convert1(or(X,Y)) --> convert1(X), [or], convert1(Y).
test_convert1( F ) :-
phrase( convert1( F ), [X, or, Y] ).
Upvotes: 0
Views: 286
Reputation: 363727
There's a syntax error in test_convert1/1
. It should read
test_convert1(F) :-
phrase(convert1(F), [X, or, Y]).
Upvotes: 1
Reputation: 5351
Your code includes two mistakes:
X
from the parsed list.A working version is:
convert1(atom(X)) --> [X], {var(X)}, !.
convert1(or(X,Y)) --> convert1(X), [or], convert1(Y).
Upvotes: 1