需要在堆栈外以及断言和动态上求解

时间:2016-04-09 19:26:34

标签: prolog

这是我的程序,我遇到了运行foul(X)的问题。 另外我想问一下断言和动态的用法。 还有其他方法可以在用户端将数据写入数据库吗?(不输入代码)。

%! program name: what to eat tonight
%! author: bearharry
%! database part 
%! characteristics
:- discontiguous char/2.
char(pork,redmeat).
char(beef,redmeat).
char(bird,whitemeat).
char(bird,meat).
char(fish,whitemeat).
char(redmeat,meat).
char(chicken,bird).
char(duck,bird).
char(pepper,spicy).
char(salt,salty).
char(sugar,sweet).
char(soysauce,salty).
char(vinegar,sour).
char(rice,carbohydrates).
char(saffron,spice).
char(bread,gluten).
char(herbs,spice).
char(bread,carbonhydrates).
char(shrimp,seafood).
char(bun,bread).
char(coleslaw,cabbage).
char(vegetable,vegatable).
char(lettuce,vegetable).
char(kaiserroll,bread).
char(onion,vegatable).
char(probvolonecheese,cheese).
char(garlic,spice).
char(relish,vegatable).
char(bittergourd,bitter).
char(squid,seafood).
char(pickle,vegatable).
char(cheese,cheese).
char(ketchup,sour).
char(chili,spicy).
char(mayonaise,protein).
char(mayonaise,sour).
char(mayonaise,sweet).
%! ingredient layer1
ingredient(pork).
ingredient(beef).
ingredient(chicken).
ingredient(duck).
ingredient(herbs).
ingredient(meat).
ingredient(shrimp).
ingredient(bun).
ingredient(coleslaw).
ingredient(lettuce).
ingredient(kaiserroll).
ingredient(onion).
ingredient(probvolonecheese).
ingredient(mastard).
ingredient(relish).
ingredient(pickle).
ingredient(cheese).
ingredient(squid).
ingredient(garlic).
ingredient(bittergourd).
ingredient(egg).
subtype(whitemeat).
subtype(redmeat).
subtype(bird).
subtype(bread).
condiment(pepper).
condiment(salt).
condiment(sugar).
condiment(soysauce).
condiment(vinegar).
condiment(spice).
condiment(ketchup).
condiment(chili).
condiment(mayonaise).
%! ingredient 
contain(zafranipulao,[rice,saffron]).
contain(vegetablepulao,[rice,vegetable]).
contain(vegetablebiryani,[rice,vegetable,herbs]).
contain(dumpukhtbhandar,[rice,meat]).
contain(shrimpbriyani,[rice,shrimp,herbs,spices]).
contain(carolinaporksandwich,[pork,bun,spice,coleslaw]).
contain(thehogheaven,[pork,sausage,bun]).
contain(openfacedleannmean,[turkey,toast,spice,coleslaw]).
contain(pulledchickenbreastsandwich,[chicken,mayonaise,lettuce,ketchup]).
contain(thezmansandwich,[beef,probvolonecheese,onion,kaiserroll]).
contain(hotdog,[mastard,relish,onion,tomato,pickle,pepper,bun]).
contain(chillcheesedog,[onion,chili,cheese,bun]).
contain(burger,[beef,lettuce,tomato,onion,pickles,ketchup,mayonaise,bun]).
contain(baconburger,[bacon,mayonaise,lettuce,tomato,bun]).
contain(char-broiledchickensandwich,[chicken,bun,mayonaise,tomato,lettuce]).
contain(garlicsaltandpeppersquidballs,[squid,garlic,salt,pepper]).
contain(bittermelonfriedbeef,[bittergourd,beef,salt]).
contain(bitterscrambledeggs,[bittergourd,egg,salt]).
contain(scrambledeggswithshrimps,[egg,shrimps]).
contain(porkscrambledeggs,[pork,egg]).
%! dish layer1 
dish(zafranipulao).
dish(vegetablepulao).
dish(vegetablebiryani).
dish(dumpukhtbhandar).
dish(shrimpbriyani).
dish(carolinaporksandwich).
dish(thehogheaven).
dish(openfacedleannmean).
dish(pulledchickenbreastsandwich).
dish(thezmansandwich).
dish(hotdog).
dish(chillcheesedog).
dish(burger).
dish(baconburger).
dish(char-broiledchickensandwich).
dish(garlicsaltandpeppersquidballs).
dish(bittermelonfriedbeef).
dish(bitterscrambledeggs).
dish(scrambledeggswithshrimps).
dish(porkscrambledeggs).
%! restaurant selling
sell(hoilok,garlicsaltandpeppersquidballs).
sell(hoilok,bittermelonfriedbeef).
sell(hoilok,bitterscrambledeggs).
sell(hoilok,porkscrambledeggs).
sell(hoilok,scrambledeggswithshrimps).
sell(portillo,hotdog).
sell(portillo,chillcheesedog).
sell(portillo,burger).
sell(portillo,baconburger).
sell(portillo,char-broiledchickensandwich).
sell(deewanbanquet,zafranipulao).
sell(deewanbanquet,vegetablepulao).
sell(deewanbanquet,vegetablebiryani).
sell(deewanbanquet,dumpukhtbhandar).
sell(deewanbanquet,shrimpbriyani).
sell(joeskansacity,carolinaporksandwich).
sell(joeskansacity,thehogheaven).
sell(joeskansacity,openfacedleannmean).
sell(joeskansacity,pulledchickenbreastsandwich).
sell(joeskansacity,thezmansandwich).
%! restaurant layer2
rest(portillo).
rest(hoilok).
rest(deewanbanquet).
rest(joeskansacity).
%! dynamics
:- dynamic foulchar/1.
%!:- dynamic rchar/1.
foulchar(vegetables).
%! rules
%! inherit of characteristics
char(Sth,Char) :-
    (   (ingredient(Sth);subtype(Sth);condiment(Sth)),
        char(Sth,Subtype),
        char(Subtype, Char));
    (   dish(Sth),
        contain(Sth,Ingredients),
        member(Ingredient,Ingredients),
        char(Ingredient,Char);
    (   rest(Sth),
        sell(Sth,Dish),
        char(Dish,Char))).
%! foul dish if it contain characters that fouled through foulchar(char)
%! or foulin(Ingredient)
% ! foul restaurant if it doesen't sell dish that is not fouled or
% provide food that with the required characteristic.
%! foulchar(Char):-assert(foulchar(Char)). 
%! rchar(Ingredient):-assert(rchar(Char)).
foul(Sth) :-
     dish(Sth),
     foulchar(X),
     char(Sth, X).
foul(Sth) :-
    foulin(Ingredient),
    contain(Sth,Ingredients),
    member(Ingredient,Ingredients). 
foul(Sth) :-
       rest(Sth),
       sell(Sth,Dish),
       not(foul(Dish)).
%! foul(Sth) :-
%!  rchar(X),
%!  not(char(Sth,X))).
%! list the dish that can be made with the ingredient provided,
listdish(X,Avaliables) :-
    contain(X,Ingredients),
    subset(Ingredients,Avaliables).
%! list the restaurant left
listrest(Restaurant) :-
    sell(Restaurant, Dish),
    not(foul(Dish)),
    not(foul(Restaurant)).

0 个答案:

没有答案