kkbum
kkbum

Reputation: 61

How to return the result of a list in Prolog?

I have a list of items, which is in a method. I'm using another method to call out the list but I do not want to input the list inside that method. How can I solve this?

foo([a,b,c,d,e]).   
hi:- read(X),member(X,[a,b,c,d,e]).

?- hi.
|: a.
true.

I want to change the list in the go(X), using the foo(X) but it does not work. I know that foo(X) returns [a,b,c,d,e].

foo([a,b,c,d,e]).   
hi:- read(X),member(X,foo(X)).

k

Upvotes: 0

Views: 354

Answers (1)

skyboyer
skyboyer

Reputation: 23705

first associate list with variable then use it in member():

hi:- read(X),foo(Y), member(X,Y).

in Prolog rules do not return value. they checks(if variable has already associated with value or constant is passed) or associate(if variable passed has not been associated yet)

Upvotes: 2

Related Questions