How to make it write all of a list

I’m using: SWI-Prolog version 9.3.31.

I want the code to: make the interpreter write lists without “…”.
E.g. it should write “[did, she]” instead of “[did|…]”.

Is there a way to do this with version 9.3.31 ?

In older versions of Swi Prolog, I could press the “w” key to start “write_mode”.

This would make it write lists in full, instead of shortening them to “[myatom|….]” for example.

So pressing “w” would stop it writing a list like this:

?- myrule(A).

A = test([did|…]).

?-

This no longer works. When I press the “w” key, it still says “[write]”, as shown here, next, but it doesn’t change how it writes lists.
For example, after I press “w”, it says “[write]”, but when I enter the next input, it still writes some terms like “test([myatom|…])”.

?- day(A).
A = monday ;
A = tuesday ;
A = wednesday ;
A = thursday [write]
A = thursday ;
A = friday ;
A = saturday ;
A = sunday.

?-

% your code here
1 Like

You can do the following:

Option A: use write

(ins)?- length( L, 100).
L = [_, _, _, _, _, _, _, _, _|…].

(ins)?- length( L, 100),write(L).
[_315186,_315192,_315198,_315204,_315210,_315216,_315222,_315228,_315234,_315240,_315246,_315252,_315258,_315264,_315270,_315276,_315282,_315288,_315294,_315300,_315306,_315312,_315318,_315324,_315330,_315336,_315342,_315348,_315354,_315360,_315366,_315372,_315378,_315384,_315390,_315396,_315402,_315408,_315414,_315420,_315426,_315432,_315438,_315444,_315450,_315456,_315462,_315468,_315474,_315480,_315486,_315492,_315498,_315504,_315510,_315516,_315522,_315528,_315534,_315540,_315546,_315552,_315558,_315564,_315570,_315576,_315582,_315588,_315594,_315600,_315606,_315612,_315618,_315624,_315630,_315636,_315642,_315648,_315654,_315660,_315666,_315672,_315678,_315684,_315690,_315696,_315702,_315708,_315714,_315720,_315726,_315732,_315738,_315744,_315750,_315756,_315762,_315768,_315774,315780]
L = [
, _, _, _, _, _, _, _, _|…].

Option B: change the options:

(ins)?- set_prolog_flag( answer_write_options, [quoted(true), portray(true), max_depth(500), spacing(next_argument)]).

true.

(ins)?- length( L, 100).
L = [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _].

The use of portray/1 (print) vs plain write and the max_depth option has been decoupled. If you type ?, you get

  Possible actions:
  ; (n,r,space,TAB): redo              | t:           trace&redo
  *:                 show choicepoint  | . (c,a,RET): stop
  w:                 write             | p:           print
  +:                 max_depth*5       | -:           max_depth//5
  b:                 break             | h (?):       help

So, if the answer is short, use +. Repeat until you see enough. The idea is to avoid flooding the output. The default of 10 is indeed sometimes a bit short, but it is unlikely that you want 10 million elements printed to the console. For example, I think you prefer this output over waiting for long to flood the terminal:

105 ?- numlist(1, 10 000 000, L), sum_list(L, Sum).
L = [1, 2, 3, 4, 5, 6, 7, 8, 9|...],
Sum = 50_000_005_000_000.
4 Likes

Thank you Frank and Jan.

You have answered my question fully.