I'm quite new to prolog, so any mercy for idiotic mistakes is most welcome! I have this assignment, and during its course I have to make this function work properly. The goal is to increment K each time all three connections occur (meaning 'con(H, Li)' for i=1, 2, 3 ; these are pre-existing arguments).
ismember([], L1, L2, L3, 0, K).
ismember([H|T], L1, L2, L3, E, K):-
ismember(T, L1, L2, L3, E, K),
((con(H, L1), con(H, L2), con(H, L3)) -> K is E + 1 ); K is E.
Now I try to run the code, and the first iteration of con(x, y) works fine (all three connections exists, so when I use trace, K seems to take value 1). In the next iteration however, the first connection does not exists, which in my mind would mean that the code would skip the middle part and go straight to 'K is E'. This is not the case, when I trace it two memory slot values appear: "_8230 is _9204" instead of "K is E" (I put two random memory addresses for the sake of the example). Why does prolog do this? Have I got the idea of the if-argument in Prolog all wrong, or do you think it has something to do with the rest of the code?
Thanks!
Aucun commentaire:
Enregistrer un commentaire