For Programmers: Free Programming Magazines  


Home > Archive > Prolog > May 2006 > count of result sets









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author count of result sets
Marten Lehmann

2006-05-24, 7:04 pm

Hello,

lets say I have to following facts:

(* name, type of my small zoo *)
animal(river, dog);
animal(bouncy, mouse);
animal(spring, mouse);

How can I count the occurences of a certain criteria and use them in
another condition? e.g. "Which animal-types do I have in my small zoo,
that exists more or equal to two times?" With the given facts, "mouse"
should be returned.

Regards
Marten
Pierpaolo BERNARDI

2006-05-24, 10:02 pm

On Wed, 24 May 2006 17:52:50 +0200, Marten Lehmann <lehmannmapson@cnm.de> wrote:

> Hello,
>
> lets say I have to following facts:
>
> (* name, type of my small zoo *)
> animal(river, dog);
> animal(bouncy, mouse);
> animal(spring, mouse);
>
> How can I count the occurences of a certain criteria and use them in
> another condition? e.g. "Which animal-types do I have in my small zoo,
> that exists more or equal to two times?" With the given facts, "mouse"
> should be returned.


====
animal(river, dog).
animal(bouncy, mouse).
animal(spring, mouse).

animal_at_least(N,AnimalType) :-
setof(Name,animal(Name,AnimalType),L),
length(L,LL),
LL >= N.
====

?- animal_at_least(2,A).

A = mouse ;

No


P.


--
Anything below this line is being added by the newsserver

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com