1

Here is my code:

getMin([Y|List1],X):-
    getMin(List, Y, X).

getMin([A|List],B,X):-
        A=<B,
        getMin(List,A,X);
        B=<A,
        getMin(List,B,X).
getMin([],X,X).

When entering getMin/3 A is supposed to be 1 as I understand, but at A=< B I get "Arguments are not sufficiently instantiated" error. Why and how to fix it?

I also found this but since I'm very new to Prolog, I don't realize where exactly they got the error there and why the argument where not instantiated there. (There are lot's of other similar posts but it is hard to make the connection between other a bit different programs and yours.)

Community
  • 1
  • 1
Vitali Pom
  • 602
  • 1
  • 8
  • 29
  • Similar to your other question, try to make the `;` better visible by indentation. Also note, that you get 2 answers for `getMin([1,1],X)` which is not incorrect, but inefficient. – false Jul 28 '12 at 18:58

1 Answers1

1

There is a typo in first rule head: List1 instead of List. If you would use SWI-Prolog, its syntax highlight facility would help you to spot such problems.

edit here you can see what i mean the image with List1 and List highlighted

test, after the correction:

?- getMin([4,2,6,1,3],X).
X = 1 ;
false.
CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • Just a small question, what are the marking facilities you mentioned above? I do use SWI Prolog and everything is black or blue and it didn't help me to notice the problem. – Vitali Pom Jul 28 '12 at 09:05
  • I pasted your code in a SWI-source, and the variables List List1 was highlighted, i.e. singleton. I'll add an image to the answer... – CapelliC Jul 28 '12 at 09:07