testing your code
Here are some tips on testing your Prolog code.
And here are some tips on writing recursive procedures in Prolog that include some tips on debugging (in example 3).