Hi all,

While Doing a Prolog college assignment, I faced the following strange problem:

occured_once(X, List) is true iff X occured once in List:


occured_once(X, [X]).
occured_once(H, [H | T]) :-
        \+ member(H, T).

occured_once(X, [H | T]) :-
        \+ X = H,
        occured_once(X, T).


Compiling and executing above snipped, here's some queries:

| ?- occured_once(1, [1, 2, X]).

no
| ?- occured_once(1, [1, 2, 3]).

true ? 

yes


So How come first test says that no X satisfy the first query, while it says
that the second query is true (same query substiuting X with 3) ?.

$ gprolog --version
Prolog top-Level (GNU Prolog) 1.2.18

Thanks,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com



_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to