Re: how to make a list
- From: "Andrew" <someone@xxxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 14:53:06 GMT
"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
.
- Follow-Ups:
- Re: how to make a list
- From: Jan Wielemaker
- Re: how to make a list
- References:
- how to make a list
- From: erhan
- how to make a list
- Prev by Date: how to make a list
- Next by Date: Re: how stop the search in a data base?
- Previous by thread: how to make a list
- Next by thread: Re: how to make a list
- Index(es):
Relevant Pages
|
|