简体   繁体   中英

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM