0

I want to create a list from facts like:

table(mickel).
table(harris).
table(wolfgang).
table(yanis).
table(antti).
table(peter).
table(jeroen).
table(johan).
table(luis).
table(eric).

But i don't want to use built-in rules or predicates, unless i define them by myself. The result almost is like that:

?- seats(Seats).
Seats = [yanis,antti,peter,jeroen,johan,luis,eric,michel,
harris,wolfgang]

I don't know what to do,please help.

aragon
  • 114
  • 1
  • 8
  • I think you should start by looking at a Prolog tutorial and pay particular attention to list processing examples (there are [some examples with source](http://www.ic.unicamp.br/~meidanis/courses/mc336/2009s2/prolog/problemas/) online). Then make an attempt at a solution to your problem and show what you've tried and where you get stuck. – lurker Mar 09 '15 at 19:12
  • You say, " i don't want to use built-in rules or predicates, unless i define them by myself". Do you mean that you want to implement your own Prolog? –  Mar 09 '15 at 20:04

1 Answers1

0

You must create your own findall predicate, this post may help:

seats(L) :- find([], L), !.

find(Acc, Loa) :- table(Y), uList(Y, Acc, AccNew), find(AccNew, Loa).
find(Acc, Acc).

uList(X, [], [X])  :- !.
uList(H, [H|_], _) :- !, fail.
uList(X, [H|T], [H|Rtn]) :- uList(X, T, Rtn).

Consult:

?- seats(L).
L = [mickel, harris, wolfgang, yanis, antti, peter, jeroen, johan, luis|...].
Community
  • 1
  • 1
Yasel
  • 2,920
  • 4
  • 40
  • 48