Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWI-Prolog - show long list

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?

like image 768
TamarG Avatar asked Nov 22 '11 18:11

TamarG


People also ask

How do I show a full list in Prolog?

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).

How do I make a list on SWI Prolog?

If you want to create a list of consecutive numbers from 1 to N you can use builtin predicates findall/3 and between/3 this way: do_list(N, L):- findall(Num, between(1, N, Num), L). ?- do_list(5,L). L = [1, 2, 3, 4, 5].

How do I get all the solutions in Prolog?

An all-solutions predicate like findall/3 might do the trick: list_parents(P, L) :- findall(Parent, parent(Parent, P), L). Simply put, findall/3 finds all bindings for Parent in the 'backtrack-able' goal parent(Parent, P) , and puts all bindings of Parent into the list L .

How do I assign a list in Prolog?

In Prolog, you establish bindings (or assert facts into the dynamic store, which is a tar pit for beginners). Something similar could be achieved in a Prolog fashion by doing something like this: frob(cat, List, Result) :- append([cat], List, Result). frob(dog, List, List).


1 Answers

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.

like image 107
philonous Avatar answered Oct 12 '22 23:10

philonous