SWI-Prolog - show long list
Asked Answered
I

5

33

I'm using SWI-Prolog and I'm trying to print a list but if the list has more than 9 items - it look like that -

[1, 15, 8, 22, 5, 19, 12, 25, 3|...] 

is there a way to show the whole list?

Inchoation answered 22/11, 2011 at 18:23 Comment(0)
T
38

Have a look at: http://www.swi-prolog.org/FAQ/AllOutput.html

The simple solution is to type w after the answer is given, i.e.:

?- n_queens_problem(10,X).
X = [1, 3, 6, 8, 10, 5, 9, 2, 4|...] [write]
X = [1, 3, 6, 8, 10, 5, 9, 2, 4, 7] 

After you have pressed the "w"-key "[write]" is displayed at the end and the full solution appears in the next line.

Tantalic answered 4/1, 2014 at 14:14 Comment(3)
This doesn't work if prolog is only returning one answer.Herein
If the query succeeds deterministically, you can simply write: ?- solution(S) ; true., i.e., simply append ; true to introduce a choice-point. Then, you also get the opportunity to press w.Axolotl
you simply type w in the outputKilocycle
E
16

I've found two ways.


1.

?- set_prolog_flag(answer_write_options,[max_depth(0)]).
true.

Then do your command that is printing a truncated list.

(set_prolog_flag documentation)


2.

?- atom_chars(goodbye_prolog, X) ; true.

(AllOutput documentation)

Put ; true. at the end of the call that results in a long list. Then push the w key on your keyboard. The result is:

?- sudoku([_,_,2,3,_,_,_,_,_,_,_,_,3,4,_,_], Solution); true.
Solution = [4, 1, 2, 3, 2, 3, 4, 1, 1|...] [write]
Solution = [4, 1, 2, 3, 2, 3, 4, 1, 1, 2, 3, 4, 3, 4, 1, 2] ;
true.
Eutrophic answered 29/4, 2016 at 22:55 Comment(0)
L
4

If prolog returns only one answer, you can make it wait by typing "; true." after the predicate. Then, if you press "w", you will get to see the whole list as written in the doc : http://www.swi-prolog.org/FAQ/AllOutput.html

Lycopodium answered 17/2, 2016 at 2:5 Comment(0)
D
2
?- createListSomehow(List), print(List), nl.

will do it neatly enough. That's what I do.

Variation:

?- use_module(library(pprint)). %load a library to do pretty-printing
?- createListSomehow(List), print_term(List,[]), nl.

The [] argument to print_term is an (empty) list of options. For more information, see documentation.

Dutybound answered 17/2, 2016 at 20:43 Comment(0)
P
1

If you want that SWI-Prolog will show the whole list by default you can add this line to your init file:

:- set_prolog_flag(answer_write_options,[max_depth(0)]).

You can modify the init file easily from the GUI (Settings => User init file).

Poeticize answered 25/7, 2020 at 11:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.