In typical Prolog the simplest way would be to use aggregate: 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'))> 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. Similar for Datalog - you can generate list by Datalog querying, then sum via regular Racket functions. On Mon, Sep 19, 2011 at 11:25, Mark Carter <mcturra2...@yahoo.co.uk> wrote: > How do I create summing rules? > > Suppose I have the following facts: > > post(cash, 26) . > post(cash, -16) . > post(cash, 50) . > post(beer, 20) . > > > How do I create a rule "bal" > bal(X, ???) > such that the ??? gives me the sum of the second arguments in post > satisfying the first argument X? > > Also, is there a way of writing floats, or is that out of the question? > > > _________________________________________________ > For list-related administrative tasks: > http://lists.racket-lang.org/listinfo/users > >
_________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users