Aggregate solution over multiple facts

前端 未结 2 716
你的背包
你的背包 2021-01-26 11:38

Trying to create a predicate (timePeriod/2) that calculates the time period between two dates for a specific fact. I\'ve managed to do this by myself, but face issu

2条回答
  •  余生分开走
    2021-01-26 12:15

    SWI-Prolog has a nice library to handle aggregation: it builds upon standard 'all solutions' predicates like findall/3,setof/3,bagof/3, so you should first grasp the basic of these (as Boris explained in his answer). With the library, a single query solves your problem:

    timePeriod(PS,X) :-
        aggregate(sum(P), B^E^(popStar(PS,B,E),P is E-B+1), X).
    

提交回复
热议问题