Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: Counting propositions

Re: Counting propositions

From: Bart Demoen <bmd_at_cs.kuleuven.ac.be>
Date: Fri, 18 Jun 2004 13:47:52 +0200
Message-ID: <1087559272.660474@seven.kulnet.kuleuven.ac.be>


x wrote:

> p(1).
> p(2).
> p(3).
>
> s(X):-r(X,[]).
>
> r(R,L):-q(X,L),r(R,[X|L]).
> r(L,L).
>
> q(X,L):-p(X), not(member(X,L)).
>
> member(X,[X|_]).
> member(X,[_|L]):-member(X,L).
>
> It is possible to write a "pure" Prolog predicate that return the number of
> elements that make p(X) true ?
> (without using findall, bagof, setof, assert, etc.)

Is the following "pure" enough for you ?

numberofs(N) :- alls(L,[]), length(L,N).

alls(L,In) :-

         (s(X), not(member(X,In)) ->
             alls(L,[X|In])
         ;
             L = In
         ).

(the same was posted not long ago ...)

Cheers

Bart Demoen Received on Fri Jun 18 2004 - 06:47:52 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US