add some member to a list with prolog -


i have facts.i want make list of members of facts , show these members function.but don't know how it. try code :

hasdiabet(mina). hasvitamind(milk). hasvitamind(eggs). addto(x,l,[x|l]). hasvitamin(l):-hasvitamind(x),addto(x,l,l),hasvitamin(l). eat(y,x):-hasvitamind(x). 

here want make list of thing hasvitamind -> milk , egg. , show when write eat(mina,x). when test code output milk. please
in advance

some problems:

hasvitamin(l):-   hasvitamind(x), % x must uppercase variable   addto(x,l,l),   % never succeed, since prolog variable *immutable*   hasvitamin(l).  % recursing same input lead infinite loop 

from problem description, think should learn all solutions builtins.

try

?- findall(x, hasvitamind(x), l). 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -