Take the 2-minute tour ×

i have the predicate m(L,L) and i want it to return the list that it takes. The code is this :

m([H|T],[H|L]) :- m(T,L).

When i try to use it with this examble :


i get this as an answer :

L = [1, 2, 3, 4, 5, 6, 7, 8, 9|...].

(i noticed that if i try it with less elements its ok.) why is this happening and the list is unfinished?

How can i avoid this?

Sorry if its a really stupid question but i've searched the web and i couldn't find any documentation that can help me understand... Thank you!

share|improve this question
Please format your code next time. –  Carl Norum Jan 12 '12 at 23:32
Your program is correct. It looks like a formatting issue in your Prolog environment, where it shortens long lists for display purposes. –  dasblinkenlight Jan 12 '12 at 23:35
add comment

1 Answer

up vote 3 down vote accepted

The list is finished - the output is just getting truncated for visualization purposes. If you write a predicate that prints out your list, you'll see that it's complete. I'm guessing you're using SWI prolog, which means you can check out this link for ways to change the display settings.

share|improve this answer
Thank you very much.You were totally right.It was SWI prolog's.. –  user1146636 Jan 12 '12 at 23:45
No problem - just accept the answer once your timeout runs down! –  Carl Norum Jan 12 '12 at 23:51
add comment

Your Answer


