質問

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

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

When I try to use it with this example :

m([1,2,3,4,5,6,7,8,9,10],L)

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!

役に立ちましたか?

解決

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.

他のヒント

Both the toplevel query/answer loop as the debugger abbreviate long complex terms. They do this to avoid endless pages of output. In fact, they write using write_term/3 which takes an option-list as argument. The option list for answers printed by the Prolog toplevel is in the prolog-flag toplevel_print_options and the one for the debugger is in debugger_print_options. Initially both have the value given below:

?- current_prolog_flag(toplevel_print_options, X).

X = [quoted(true), portray(true), max_depth(10), spacing(next_argument)].

To change the default settings: Add a set_prolog_flag/2 directive in your prolog personal initialisation file (see PlInitialisation) to change the default the above mentioned prolog flags.

Just go to the settings -> user init file ... ->

And change max_depth(10) like this:

 :- set_prolog_flag(toplevel_print_options,
             [quoted(true), portray(true), max_depth(100)]).

There also other options you can use in PlInitialisation file that are commented already.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top