How to read an array "list" & print it in prolog ? I need to :- Prompt user to insert an array The user some how tells me that He's finished Then I print it
I just can't think of how to make this in a predicate.
How to read an array "list" & print it in prolog ? I need to :- Prompt user to insert an array The user some how tells me that He's finished Then I print it
I just can't think of how to make this in a predicate.
Is this what you would like to have?
1 ?- p(X).
|: a.
|: b.
|: c.
|: d.
|: end.
Code:-
X = [a, b, c, d].
This is how one can implement this behaviour:
p(X) :- read(A), q(A,X-[]).
q(end,X-X) :- !.
q(A,[A|X]-Y) :- read(B), q(B,X-Y).