am trying to print the elements of a list.... one per line using a predicate of arity 1 .... which I am able to do with the code:
display_list() :- !, write('\nThe list is empty'). % handles empty list display_list([H|T]) :- write(' '), write(H), nl, display_list(T).
The problem is: I want to have the sequence number of the list element in front of it: For example,
I am not able to able to do that.
The code I am writing is:
increment(X,Y) :- Y is X+1. display_list() :- !, write('\nThe list is empty'). display_list([H|T]) :- X = 0, increment(X,Y), write(Y),write(' '), write(H), nl, display_list(T).
11 ?- display_list([north, south, east]).
The list is empty
Also I keep on getting this 'The list is empty' everytime the elements are exhausted and not only when the input list is empty .....
Please advice ...... Thanks