问题1
如何将weatherInfo(X,Y)与airDensity(X,Y)相结合,使其成为1列表。如果可能的话我希望是这样的。
:- dynamic analize/3
outlook(Sunny).
outlook(Overcast).
outlook(Rain).
temperature(Hot).
temperature(Mild).
temperature(Cool).
humidity(Normal).
humidity(High).
windy(True).
windy(False).
weatherInfo(Sunny,Mild).
weatherInfo(Sunny,Cool).
weatherInfo(Overcast,Hot).
weatherInfo(Overcast,Mild).
weatherInfo(Overcast,Cool).
weatherInfo(Rain,Mild).
weatherInfo(Rain,Cool).
airDensity(Normal,False).
airDensity(Normal,True).
airDensity(High,False).
airDensity(High,True).
prediction(Result):-
analize([],[], _).
analize([H1|T1], [H2,T2], Result),
append(T1, [H2,T2], Result),
assertz([H1|T1], _, [H2,T2]),
Result =.. [[H1|T1], [H2,T2]),
write(L1, L2),
analize(NewT, NewL, Result).问题2
我需要删除旧数据,但我不知道该在哪里做。是在附加后还是在追加之前?
发布于 2013-09-01 20:07:55
一般性评论:Sunny是一个变量,所以outlook(Sunny).断言Sunny的任何值都是可以接受的。要获得有意义的信息,您需要outlook(sunny).等。
Q1:还不清楚,为什么要断言/撤回子句,CapelliC指向findall的指针是您最需要的。
Q2:重新启动prolog解释器可以清除所断言的事实。如果您想在会话中这样做,缩回/1可能会派上用场(否则您需要分别撤回每个事实)。
https://stackoverflow.com/questions/18559053
复制相似问题