0

I need to develop a predicate in Prolog able to compare a list against fact. In other words, if the names of the products residing in the list are all in the database(fact) as well, then it gotta say "yes", otherwise "no". The predicate obviously receives a list of the products names. At the moment, I've got this piece of code.

domains
    state =  reduced ; normal
    element = string
    list = element*
database
    producte (string, integer, state)
predicates
    nondeterm check(list)
clauses 
   % ---> producte( description , price , state )
    producte("Enciam",2,normal). 
    producte("Llet",1,reduced). 
    producte("Formatge",5,normal). 
    %unique case
    check([Name]):-
        producte([Name],_,_).
    %general case
    check([D|T]):-
        producte(D,_,_),
        check(T).
Goal
    check(["Enciam","Llet","Formatge"]).
cdeszaq
  • 30,869
  • 25
  • 117
  • 173
mkll
  • 41
  • 9
  • And the problem with what you've written so far is... what? – Scott Hunter Jan 05 '12 at 19:32
  • It works almost perfectly. The only problem is that doesn't verify all the products in the fact. I mean whether the list contains less products than the database, the predicate responds with a "yes" as well. – mkll Jan 06 '12 at 17:48

1 Answers1

0

Your base case for check looks for the product's name as a list instead of as a string.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101