prolog - Sum from backtrackable predicates or facts -


I am trying to add different values ​​at once, suppose I have this:

 Facts (fruits, apples, 10) facts (fruits, pears, 20) facts (vegetable, tomatoes, 15)   

Now, my The problem is that if I want to add weight to all fruits, what have I done so far:

  printwhite (types): - facts (type, _, r), (type = 'fruit '-> right; wrong), * Here I want to weigh all the fruits Got to add, type = Fruit *   

No idea about anyone how to solve it?

See the documentation for your ProLal implementation for built-in bill bagof / 3 and A more or less standard library means that a list (available in SWI-Prolog, is available as sumlist / 2 ):

 ? - bagf (w, name ^ facts (fruit, name, w), ws), index (ws, yoga). Ws = [10, 20], yoga = 30.? - bagf (w, name ^ facts (meat, name, w), ws), index (ws, bm). false.   

The second query fails, because there is no meat product in your database, you can either leave it (you may want to know that there are no specific types of products ) Or use findall / 3 :

 ? - Finder (W. Facts (meat, _, W), WS), Index (WS, Yoga). If you use SWI-Prolog, then  library (total) :  
   code>? - Total (zodiac (w), name ^ facts (fruit, name, w), w_sume). W_sum = 30.   

You can use aggregate_all / 3 as the findall / 3 for behavior:

 ? - Total (zodiac (w), name ^ facts (meat, name, w), w_ueum) False. ? - Total-sum (zodiac (w), name ^ fact (meat, name, w), w_ueum) W_sum = 0.   

If you type in index / 2 If you do not want to use (or you do not have permission), then you add two numbers (integer or floats):

  yoga A + B  < / Pre> 

So you have to figure out how to "fold" the list.

Edit:

For example, using findall / predicate type_totalweight (Type, _, W., WS), Index (WS, Weight): 3 :

  Type_toolweight (type, weight )    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -