Ok. That's my problem. I need to implement a predicate that sums up all the prices of the products in the list. But, for now, I'm not getting any further with it. What am I doing wrong? Thanks in advance.
domains
state = reduced ; normal
database
producte (string, integer, state)
predicates
nondeterm calculate(integer)
clauses
% ---> producte( description , price , state )
producte("Enciam",2,normal).
producte("Llet",1,reduced).
producte("Formatge",5,normal).
calculate(Import):-
producte(_,Import,_).
calculate(Import):-
producte(_,Import,_),
calculate(Import2),
Import=Import2+Import,!.
Goal
calculate(I).
Disclaimer: I'm a bit daft when it comes to prolog. Also, I don't have access to a prolog interpreter right now.
The canonical example, sum of a list:
making a list with findall/3:
Vals has your list you want to sum.
Update: per your comment, I'm a bit out of my depth without access to an interpreter.
What I think this does:
uses your single goal
I
, which receives the result of summing your Vals list, which is generated by findall. But it's been so long since I've used prolog that I may not even have the syntax right for doing what I want. However, a small variation should accomplish what you want with a single goal.The findall part :
The sum_list part :
I guess something along these lines should work according to visual-prolog doc but I kinda don't wanna install visual-prolog to test it...