SWI-Prolog how to show entire answer (list)?

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

?- string_to_list("I'm a big blue banana in space!", C).
C = [73,39,109,32,97,32,98,105,103,32,98,108,117,101,32,98,97,110,97,110,97,32,105,110,32,115,112,97,99,101,33].

there should be somewhere here on SO the same answer... I'm using the last SWI-prolog release, just compiled...


If you are finding yourself using string_codes/2 or atom_codes/2 a lot, reconsider your approach. You can use chars in place of codes and avoid the SWI-specific string datatype altogether. All this, by setting a Prolog flag:

?- set_prolog_flag(double_quotes, chars).
true.

?- Chs = "Codes are unreadable!".
Chs = ['C', o, d, e, s, ' ', a, r, e|...].

This is more readable than [67, 111, 100, 101, 115, 32, 97, 114, 101|...], but it still does not solve your problem. However, you can now display such answers compactly using library(double_quotes).

?- use_module(double_quotes).
true.

?- Chs = "Codes are unreadable!".
Chs = "Codes are unreadable!".

?- Chs = "Codes are unreadable", Chs = [C|Chs2].
Chs = "Codes are unreadable",
C = 'C',
Chs2 = "odes are unreadable".

With this setting you can process text much more conveniently. It also fits nicely with DCGs.


Just to put the comment by @mat in an answer:

?- string_codes("string_to_list/2 is deprecated; use string_codes/2!", Codes)
   ;
   false.
Codes = [115, 116, 114, 105, 110, 103, 95, 116, 111|...] /* press w */ [write]
Codes = [115, 116, 114, 105, 110, 103, 95, 116, 111, 95, 108, 105, 115, 116, 47, 50, 32, 105, 115, 32, 100, 101, 112, 114, 101, 99, 97, 116, 101, 100, 59, 32, 117, 115, 101, 32, 115, 116, 114, 105, 110, 103, 95, 99, 111, 100, 101, 115, 47, 50, 33] /* press enter */.

However, from here on all terms will be shown completely. This might get annoying.

What you can also do is just use one of the printing predicates:

?- ..., writeln(Codes).

but this is frowned upon for some reason. It is definitely useful if you have several bindings reported in an answer, but you only want to look at the full value of one of the variables:

?- numlist(1,1000,L),
   Codes = `This is a code list in SWI-Prolog V7`.
L = [1, 2, 3, 4, 5, 6, 7, 8, 9|...],
Codes = [84, 104, 105, 115, 32, 105, 115, 32, 97|...].

?- numlist(1,1000,L),
   Codes = `This is a code list in SWI-Prolog V7`,
   writeln(Codes).
[84,104,105,115,32,105,115,32,97,32,99,111,100,101,32,108,105,115,116,32,105,110,32,83,87,73,45,80,114,111,108,111,103,32,86,55]
L = [1, 2, 3, 4, 5, 6, 7, 8, 9|...],
Codes = [84, 104, 105, 115, 32, 105, 115, 32, 97|...].