Re: How to return clause in findall/3

From: reader (no-spam_at_sonic.net)
Date: 08/12/04


Date: Thu, 12 Aug 2004 19:59:51 GMT

rhapsody wrote:

> Hi, I am new to Prolog. What is the correct way of returning a list of
> clauses 'sc/3' to the variable X? Below is my codes:
> Database
> sc(symbol Sid,symbol Cid, integer ExamScore).
>
> Clauses
> sc("S1","C1",55).
> sc("S1","C2",60).
> sc("S1","C3",70).
> Goal
> findall(sc(),sc(X,_,_),List), X="S1", write(List), nl.
>
> Thanks in advance!
> Stanly
>
/*
   There is no such thing as a list of clauses in that sense,
but there is nothing to stop you from constructing a term that
has the same form as a clause.
*/
   DOMAINS
     Datum = datum(symbol Sid,symbol Cid, integer ExamScore).
     List = Datum*

    Predicates
      collect(List,List).
    Clauses
     collect(In,Out) :-
      retract(sc(Sid,Cid,ExamScore)),
      !,
      collect([datum(Sid,Cid,ExamScore)|In],Out).
     collect(In,In). /* Note: reverses order! */

   Goal
     collect([],List).

whence

List=[datum("S1","C3",70),datum("S1","C2",60),datum("S1","C1",55)]
1 Solution



Relevant Pages

  • Re: How to return clause in findall/3
    ... > sc(symbol Sid,symbol Cid, integer ExamScore). ...
    (comp.lang.prolog)
  • Re: SQL syntax over a network
    ... You can code in one database, ... to using multiple IN clauses for the data source. ... 'working' example is for Jet SQL or ADO 'ANSI' SQL: ... database identifier is what goes in the first string literal ...
    (microsoft.public.access.modulesdaovba)
  • Re: Prolog type overloading
    ... If I have in my database next, it means ... nextclauses. ... It's not always clever to be clever. ... I would use different names for different predicates. ...
    (comp.lang.prolog)
  • Re: SQL syntax over a network
    ... You can code in one database, ... > to using multiple IN clauses for the data source. ... > database identifier is what goes in the first string literal ...
    (microsoft.public.access.modulesdaovba)
  • Re: embedded SQL in COBOL
    ... I can't imagine specifying 200 different fields in the ... If you have 10 fields in your database, and the last 5 can be null, you'll have something like... ... The most common way is a copybook - we have a working-storage copybook for the data layouts, and a procedure copybook to do the select. ... In our network database, the database is defined with picture clauses, like COBOL is. ...
    (comp.lang.cobol)