i need to write a code that should access to list that created. but i don’t know how, i read this question: How do I store and access a list within a variable in Prolog?
but it wasn’t my problem I create the list with this code:
p([Head|Tail]):-
read(Head),
p([Tail|Taile]).
my_write([Head|Tail]):- write(Head),nl,my_write(Tail).
and i need created list. what should i do ? it’s make me confuse.
try
Prolog is designed more for symbolic processing, IO, being based on side effects, it’s often error prone.
Please note that read/1 it’s actually a very powerful ‘parser’, being able to process generalized Prolog terms (structures, expressions, list, with arbitrary nesting).
At EOF, SWI-Prolog return the atom ‘end_of_file’, hence the test you see n the code.