2
2
3
3
:- dynamic type/1, dividend/1, quality/1, highyield/1, category/1, sector/1, fund/1.
4
4
5
- select :- type(stock), dividend(yes), quality(rising), highyield(yes), assert(fund(sdy)).
6
- select :- type(stock), dividend(yes), quality(rising), highyield(no), assert(fund(pfm)).
7
- select :- type(bond), category(short), sector(broad), assert(fund(bsv)).
8
- select :- type(bond), category(medium), sector(broad), assert(fund(bnd)).
5
+ %select :- type(stock), dividend(yes), quality(rising), highyield(yes), assert(fund(sdy)).
6
+ fund(sdy) :- type(stock), dividend(yes), quality(rising), highyield(yes).
7
+ fund(pfm) :- type(stock), dividend(yes), quality(rising), highyield(no).
8
+ fund(bsv) :- type(bond), category(short), sector(broad).
9
+ fund(bnd) :- type(bond), category(medium), sector(broad).
9
10
10
11
% By adding this fact, when we set highyield=yes, we also get dividend=yes, thus leading us to fund(sdy).
11
12
dividend(yes) :- highyield(yes).
@@ -14,8 +15,10 @@ type(stock).
14
15
%dividend(yes).
15
16
quality(rising).
16
17
highyield(yes).
18
+ category(none).
19
+ sector(none).
17
20
18
- ?- select, fund(Which)
21
+ ?- fund(Which)
19
22
20
23
% Output: Which = sdy
21
24
*/
0 commit comments