0

To begin with - this is coursework so I can't post code. This is more about how prolog outputs its answers rather than "is my code right"?

I'm creating a predicate that returns all simple paths between a graph, given a list of edges.

For example, paths(a, X) will return all the possible paths that start with a.

Say my KB is: edge(a,b). edge(b,c). edge(c,d). edge(d,f).

Then I should get X = [[a], [a,b], [a,b,c], [a,b,c,d], [a,b,c,d,f]] - and I do. The problem is, if the output is longer, then it doesn't show every possible output - the output is shown as follows:

Paths = [[b],[b,c],[b,c,d],[b,c,d,a],[b,c,d,e],[b,c,d,f],[b,c,d,f|...]] ? 

y

Is there any way I can make my interpreter explicitly show everything? The last list is incomplete - it should show [b,c,d,f,g]. For the record, I'm using SICSTUS

false
  • 10,264
  • 13
  • 101
  • 209

2 Answers2

2

You are seeing answers printed by the toplevel that have been abbreviated. In SICStus, the precise way of printing at the toplevel is determined by the Prolog flag toplevel_print_options which is initially:

?- current_prolog_flag(toplevel_print_options, Options).
   Options = [quoted(true),numbervars(true),portrayed(true),max_depth(10)].

To remove the depth limit for writing set (e.g. in your .sicstusrc).

 :- set_prolog_flag(toplevel_print_options,
        [quoted(true),numbervars(true),portrayed(true),max_depth(0)]).

(As a beginner, rather avoid to use side-effectful built-ins as much as you can - even if you "only" print terms. This is a distraction you can easily avoid.)

false
  • 10,264
  • 13
  • 101
  • 209
1

This is just a printing habit of prolog when lists get long, it only prints some prefix. try adding a print(Paths) goal. That should show you the actual, non-truncated, list.

tobyodavies
  • 27,347
  • 5
  • 42
  • 57
  • 1
    @user2832891: This gives unexpected values for terms that need quoting. And does not take variable names into account... – false Oct 16 '15 at 09:32