1
votes

Could someone tell me what's wrong in my If else in my search, in the sublist.

Because when the size is 0, the conditional works, but if the value becomes 1,2 and 3 it presents an error, but the relational operators are not correct?

If the variable length has size = 0, the condition works, but if the variable length has size 3 it has an error.

Error is:

Exception: >=/2: Arguments are not sufficiently instantiated.

subList([], []). 
subList(List1,List2):-
      concatenate(List1,List2,Result1),
      equalelements(Result1,Result2),
      counting(Result2,Length),
      Length =< 2
   -> false
   ;  Length >= 3
   -> true.

searchdisease([],_).
searchdisease(Symptoms,Disease) :-
   disease(Ls, Disease),
   subList(Symptoms, Ls).

counting([ ],0).
counting([_| T], N) :-
   counting(T, N1),
   N is N1 + 1.

concatenate(L1, L2, NL) :-
   append(L1, L2, L12),
   msort(L12, NL).
1
Lenght is return variable of the size of the list, time it returns size 0, time it returns size 1 or size 2,3,4, etc. So I check if the size of the list is less than or equal to 2 or greater or equal to 3. - Chance
I have indented your rules: now you see that Length is uninstantiated for Length >= 3 - false
Length is the return of the predicate Counting, which returns a list size in the variable lenght. - Chance
I want a make a condition for the size of the list, just that. - Chance
@AndersonMendes: Please do not change the indentation: The way I changed it corresponds to what Prolog sees. You changed it to what you want, but what you have not written. - false

1 Answers

2
votes

This is a common problem with priorities of operators. Note that Prolog ignores the precise indentation you use. Instead it takes operators into account. So you need to add round brackets accordingly.

Most probably you want the following:

subList([], []). 
subList(List1,List2):-
   concatenate(List1,List2,Result1),
   equalelements(Result1,Result2),
   counting(Result2,Length),
   (  Length =< 2
   -> false
   ;  Length >= 3
   -> true
   ).

On the other hand, why not simply replace the comparisons for Length by a single goal: Length >= 3.