# Re: Counting propositions

From: x <x-false_at_yahoo.com>
Date: Fri, 18 Jun 2004 15:39:33 +0300
Message-ID: <40d2e184\$1_at_post.usenet.com>

"Bart Demoen" <bmd_at_cs.kuleuven.ac.be> wrote in message news:1087559272.660474_at_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 ?
I don't know. I have to think about it. Is a cut hidden somewhere ?

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

I think you wrote s(X) by mistake instead of p(X). The solution is similar to the wrong code I posted.

I'm not familiar with the exact meaning of -> and ; Why the two "solutions" r(X,[]) and alls(X,[]) give different answers ?

Sorry, I haven't watched comp.lang.prolog.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

• Usenet.com - The #1 Usenet Newsgroup Service on The Planet! *** http://www.usenet.com Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Received on Fri Jun 18 2004 - 14:39:33 CEST

Original text of this message