Store and Display Result as a List in Prolog

Viewed 1394

I am trying to get an index and value based pair output in Prolog. Below is my Code:

tagit0(L) :-tagit0(L, 1).

tagit0([], _) :- nl.
tagit0([H|T], N) :-
     N1 is N + 1,
     format('tag (~w, ~w), ', [N1, H]),
     tagit0(T, N1).

Running this: ?- tagit0([a,b,c],0).

Gives: tag (1, a), tag (2, b), tag (3, c),

But i am looking for some output which is stored in a List and displayed Like:

L = [tag (1, a), tag (2, b), tag (3, c)]

2 Answers
Related