【发布时间】:2014-12-15 19:02:19
【问题描述】:
我正在尝试将不同的值加在一起,假设我有这个:
%fact(Type, Name, Weight).
fact(fruit, apple, 10).
fact(fruit, pear, 20).
fact(vegetable, tomato, 15).
现在,我遇到的问题是,如果我想将所有水果的重量相加。到目前为止我做了什么:
printWeight(Type):-
fact(Type,_,R),
(Type = 'fruit'
-> true
; false
),
*Here I want to add the weight of all the fruits, in case Type = fruit*
有人知道如何解决这个问题吗?
【问题讨论】:
-
我假设在你的第一个代码片段中,你的意思是写
% fact(Type, Name, Weight).I.e。第一行是描述fact/3谓词的comment? -
是的,我就是这个意思。
标签: prolog