Re: how to make a list




"erhan" <eerisken@xxxxxxxxxx> wrote in message
news:1145970145.785893.116710@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

I want to make list of given facts in prolog.
For ex. 2 facts are given by clauses below:

teacher(erhan).
teacher(ali).

So, I want to make a list of [erhan, ali] by calling makelist(L).
how can I do this in prolog.
sorry, but I am a newbie and cant figure out how to do it?

thanks in advance...


bagof/3 should work

e.g.
teacher(erhan).
teacher(ali).

go:-
makelist(List),
write(List).

makelist(L):-
bagof(X,teacher(X),L).


bagof looks for all values of "X" that match "teacher(X)" and puts them in
"L"
Since "X" will match all values in the database you end up with
"List=[erhan, ali]"

/Andrew


.



Relevant Pages

  • Re: OO versus RDB
    ... There is a very simple mapping from RM to PROLOG. ... a representation based on predicates, ... 'connection' comes from the fact that PROLOG stores rules about facts ...
    (comp.object)
  • Re: Representing data structures in Prolog
    ... > the representation of knowledge with Prolog. ... I have several facts of the form. ... > object in object oriented languages. ... And create rules with multiple arguments to express more succinctly ...
    (comp.lang.prolog)
  • Re: database: prolog and relational
    ... I have on occasion seen Prolog referred to as "relational". ... A Prolog system effectively consists of a database ... of facts, a collection of predicates which tie the facts together (and ...
    (comp.lang.prolog)
  • Re: Representing data structures in Prolog
    ... > of a traffic control system. ... > of knowledge with Prolog. ... I have several facts of the form. ... > object in object oriented languages. ...
    (comp.lang.prolog)
  • Re: database: prolog and relational
    ... > The Prolog facts database is not relational for a couple of ... > database affects the evaluation of predicates. ... (I don't have a Prolog ... > did it last year for various mad reasons). ...
    (comp.lang.prolog)