Prolog Max List Length

515 views
Skip to first unread message

MrClscopelliti

unread,
Aug 28, 2015, 12:40:15 PM8/28/15
to SWI-Prolog
I'm practicing with Prolog doing some exercise from "learn prolog now".
I notice that when the length list is higher than 10 elements,the output on the screen is cut to 10 elements and after ....How can I fix this?
Thanks.

Eyal Dechter

unread,
Aug 28, 2015, 1:10:34 PM8/28/15
to MrClscopelliti, SWI-Prolog
As a convenience, the top level REPL displays query results to a default maximum depth of 10. This can be changed using set_prolog_flag/2 and the flag answer_write_options. See: http://www.swi-prolog.org/pldoc/doc_for?object=current_prolog_flag/2

example:

=============

?- length(Xs, 11).

Xs = [_G2720, _G2723, _G2726, _G2729, _G2732, _G2735, _G2738, _G2741, _G2744|...].

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

true.

?- length(Xs, 11).

Xs = [_G2720, _G2723, _G2726, _G2729, _G2732, _G2735, _G2738, _G2741, _G2744, _G2747, _G2750].

=============
Eyal

--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at http://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.

Eyal Dechter

unread,
Aug 28, 2015, 1:11:42 PM8/28/15
to MrClscopelliti, SWI-Prolog
Sorry, you don't have to switch portray to false: 

==========


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

true.


?- length(Xs, 11).

Xs = [_G2720, _G2723, _G2726, _G2729, _G2732, _G2735, _G2738, _G2741, _G2744, _G2747, _G2750].


===========

MrClscopelliti

unread,
Aug 28, 2015, 2:43:34 PM8/28/15
to SWI-Prolog
Thanks Eyal.
It works.
Now,how can I make this change permanent?
I see I can modify the file swipl.rc,but I don't want to make mistakes.
Any suggestion?.

Luigi

MrClscopelliti

unread,
Aug 28, 2015, 2:50:19 PM8/28/15
to SWI-Prolog
Thanks Eyal.It works.
I was wondering how to set it permanent.
I can modify the swipl.rc file,but I don't want to make mistakes.
Any suggestion?
Thanks.

Eyal Dechter

unread,
Aug 28, 2015, 3:10:09 PM8/28/15
to MrClscopelliti, SWI-Prolog
The correct file is .swiplrc on Unix and swipl.ini on Windows. see: http://www.swi-prolog.org/pldoc/man?section=initfile

These are just regular prolog files, so you can just put in the file:

:- set_prolog_flag(answer_write_options,  [quoted(true), portray(true), max_depth(20), spacing(next_argument)]).

--

Jan Wielemaker

unread,
Aug 29, 2015, 7:33:21 AM8/29/15
to Eyal Dechter, MrClscopelliti, SWI-Prolog
On 08/28/2015 09:09 PM, Eyal Dechter wrote:
> The correct file is .swiplrc on Unix and swipl.ini on Windows.
> see: http://www.swi-prolog.org/pldoc/man?section=initfile
>
> These are just regular prolog files, so you can just put in the file:
>
> :- set_prolog_flag(answer_write_options, [quoted(true), portray(true),
> max_depth(20), spacing(next_argument)]).

In most cases, simple type 'w' to the answer. That will reprint the
answer without limits. Type 'p' to get back to normal mode. You can
also do

?- goal(Answer), writeq(Answer).

or whatever write predicate you like. I'd only change the default if
you think 10 is just a bit too little.

Cheers --- Jan
Reply all
Reply to author
Forward
0 new messages