In typical Prolog the simplest way would be to use aggregate: <div><br></div><div><a href="http://www.swi-prolog.org/pldoc/doc_for?object=section(2,'A.1',swi('/doc/Manual/aggregate.html'))">http://www.swi-prolog.org/pldoc/doc_for?object=section(2,'A.1',swi('/doc/Manual/aggregate.html'))</a></div>
<div><br><a href="http://www.swi-prolog.org/pldoc/doc_for?object=section(2,'A.1',swi('/doc/Manual/aggregate.html'))"></a></div><div><br></div><div>In Racklog you can simply use bag-of to generate a list of your facts satisfying some predicate, then sum it on the Racket side eg. using foldl.</div>
<div><br></div><div>Similar for Datalog - you can generate list by Datalog querying, then sum via regular Racket functions.</div><div><br></div><div><br></div><div><br></div><div><div class="gmail_quote">On Mon, Sep 19, 2011 at 11:25, Mark Carter <span dir="ltr"><<a href="mailto:mcturra2000@yahoo.co.uk">mcturra2000@yahoo.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">How do I create summing rules?<br>
<br>
Suppose I have the following facts:<br>
<br>
post(cash, 26) .<br>
post(cash, -16) .<br>
post(cash, 50) .<br>
post(beer, 20) .<br>
<br>
<br>
How do I create a rule "bal"<br>
bal(X, ???)<br>
such that the ??? gives me the sum of the second arguments in post satisfying the first argument X?<br>
<br>
Also, is there a way of writing floats, or is that out of the question?<br>
<br>
<br>
_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
<br>
</blockquote></div><br></div>