Article View: comp.lang.prolog
Article #2701Re: Counting things.
From: Tim Finin
Date: Fri, 03 Jul 1987 13:35
Date: Fri, 03 Jul 1987 13:35
20 lines
1233 bytes
1233 bytes
Counting the number of clauses in the DB unifying with a given term using SETOF/BAGOF is the "proper" way to do it. The other way this sort of thing is typically done it to use ASSERT/RETRACT to keep a counter in the DB and use a failure driven loop to find all the matches, as in: countClauses(X,_) :- assert(count(0)), clause(X,true), retract(count(N)), N2 is N+1, assert(count(N2)), fail. countClauses(_,N) :- retract(counter(N)). There is, as I recall, a definition of a predicate FINDALL in C&M which is similar to BAGOF and SETOF. Tim
Technical Details
Message-ID:
<1424@super.upenn.edu.upenn.edu>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rutgers!super.upenn.edu!linc.cis.upenn.edu!timReferences:
<8706240740.AA23829@ucbvax.Berkeley.EDU> <263@uvicctr.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rutgers!super.upenn.edu!linc.cis.upenn.edu!tim From: tim@linc.cis.upenn.edu (Tim Finin) Newsgroups: comp.lang.prolog Subject: Re: Counting things. Message-ID: <1424@super.upenn.edu.upenn.edu> Date: Fri, 3-Jul-87 09:35:43 EDT Article-I.D.: super.1424 Posted: Fri Jul 3 09:35:43 1987 Date-Received: Sat, 4-Jul-87 13:19:05 EDT References: <8706240740.AA23829@ucbvax.Berkeley.EDU> <263@uvicctr.UUCP> Sender: root@super.upenn.edu.upenn.edu Reply-To: tim@linc.cis.upenn.edu.UUCP (Tim Finin) Distribution: na Organization: University of Pennsylvania Lines: 20