Search code examples
prologprolog-toplevel

Prolog : Never Ending Process


I am trying to use get_coeff_value() but the process never end.

get_coeff_value(Val,[],[]).
get_coeff_value(Val, [X|T],Coeff_List):- 
    get_coeff_value(Val,T,Coeff_List1),
    get_val(Val,[X], Coeff),
    insert_end(Coeff_List1, Coeff, Coeff_List).

command : get_coeff_value('H', ['H'-5, 'C'-2], Coeff).

I tried get_val() and insert_end() both end perfectly. However this one display :

command result

It gives me the answer I am waiting for but it never stops the process.


Solution

  • This looks the same as what happens if you query e.g. ?- member(X, [1,2,3]). ; your code has left choicepoints and the Prolog toplevel has found one solution but has not explored the whole search space of your code, so it is waiting for your input.

    Press ? to see the help, ; or space to continue searching for more answers, or a to abort the search and stop there.

    SWI Prolog help on pressing ?

      Possible actions:
      ; (n,r,space,TAB): redo              | t:         trace&redo
      *:                 show choicepoint  | c (a,RET): stop
      w:                 write             | p:         print
      b:                 break             | h (?):     help