how can i find all fields for prolog?

You are not using findall/3 correctly. For a list of all Codes, Values in a particular month separately:

get_months_data1(Month, Codes, Values) :-
    findall(Code, values1(Code, date(_, Month, _), _), Codes),
    findall(Value, values1(_, date(_, Month, _), Value), Values).
?- get_months_data1(03, C, V).
C = ['AAA', 'AAA'],
V = [1000, 2000].

?- get_months_data1(04, C, V).
C = ['AAA', 'BBB'],
V = [1350, 1500].

?- get_months_data1(05, C, V).
C = ['CCC'],
V = [950].

If you do not want duplicate entries like ['AAA', 'AAA'] above, you can also use setof/3. If you want them Code, Value together you can have:

get_months_data(Month, Data) :-
    findall(tr(Code, Value), values1(Code, date(_, Month, _), Value), Data).

This gives

?- get_months_data(03, D).
D = [tr('AAA', 1000),  tr('AAA', 2000)].

?- get_months_data(04, D).
D = [tr('AAA', 1350),  tr('BBB', 1500)].

?- get_months_data(05, D).
D = [tr('CCC', 950)].

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top