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?
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).
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].
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 .
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With