简体   繁体   中英

Prolog: how to combine 2 predicate become 1 list only

Question 1

How do I combine weatherInfo(X,Y) with airDensity(X,Y) to make it into 1 list. I want it to be something like this if possible.

     :- 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).

Question 2

I need to do delete old data but I don't know where I'm supposed to do it. Is it after append or before append?

A general comment: Sunny is a variable, so outlook(Sunny). asserts that any value of Sunny is acceptable. To get meaningful information you need to outlook(sunny). etc.

Q1: It is not clear, why you want to assert/retract clauses, CapelliC's pointer to findall is most certainly what you need.

Q2: Restarting your prolog interpreter clears the facts you asserted. If you want to do this within a session, retractall/1 might come in handy (otherwise you need to retract each fact seperately).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM