lundi 24 septembre 2018

Prolog if then with negative condition

I have a complex program, a part of which looks somewhat like this:

check_list([]).
check_list(X|List) :-(try_something(X) -> write(1);write(0)),nl,check_list(X).

The problem is that, when my list gets very large, Prolog gives me "Ressource error: insufficient memory". I thought the problem might be somewhere in the if-then-clause. So I tried the following:

check_list([]).
check_list(X|List) :-(\+try_something(X) -> write(0);write(1)),nl,check_list(X).

With that, the problem is gone (or at least it only appears with much much bigger lists). However, I have no clue why. What is so different in the two versions? Should both be the same?

Aucun commentaire:

Enregistrer un commentaire