Variable not printing the entire value Prolog

277 views Asked by At

If I assign something like process([[baby],[boy],[[is]dancing],[with],[[the][family]]],A), then it gives output as

A = [[baby],[boy],[[is]dancing],[with],[[..][..]]].

I want it to show all the values on terminal. Something like A = [[baby],[boy],[[is]dancing],[with],[[the][family]]].

2

There are 2 answers

0
gusbro On

The problem is that the toplevel is truncating the list when they are shown. You can configure the depth of the maximum nesting with the prolog flag toplevel_print_option, with option max_depth(0), with 0 meaning to show everything.

The helper procedure will modify the prolog flag to change only max_depth to 0, leaving the other options unchanged:

set_toplevel_flags:-
  current_prolog_flag(toplevel_print_options, Opts),
  (select(max_depth(_), Opts, TOpts) -> NOpts=TOpts ; NOpts=Opts),
  set_prolog_flag(toplevel_print_options, [max_depth(0)|NOpts]).
0
Eugene Sh. On

Use the current_prolog_flag/2 predicate with the toplevel_print_options flag. Something like this:

?- current_prolog_flag(toplevel_print_options, X).

X = [quoted(true), portray(true), max_depth(10), spacing(next_argument)].

You can modify the max_depth option value, or alternatively you can type w after getting the abbreviated answer, and prolog will print the answer fully. Pressing p will restore the original format. To make the Prolog wait wor your input after printing the answer, you might want to add some non-determinism to the query by appending ; true. to it. For more information see here.