3

The typical workflow in unix is to use a pipeline of filters ending up with a pager such as less. E.g. (omitting arguments)

grep | sed | awk | less

Now, one of the typical workflows in the swi-prolog's command line is asking it to give the set of solutions for a given conjunction like

foo(X),bar(X, Y),qux(buz, Y).

It readily gives me the set of soutions. Which can be much longer than the terminal window. Or a single query

give_me_long_list(X).

can give a very long list again not fitting on the screen. So I constantly find myself in situations where I want to slap |less at the end of the line.

What I am looking for is a facility to open in a pager a set of solutions or just a single large term. Something similar to:

give_me_long_list(X), pager(X).

or

pager([X,Y], (foo(X),bar(X, Y),qux(buz, Y))).
false
  • 10,264
  • 13
  • 101
  • 209
Alexander Gorshenev
  • 2,769
  • 18
  • 33
  • 1
    What about adjusting the terminal to scroll? Usually hundreds if not thousands of lines can be in the scroll buffer. Prolog could also be run in Emacs to provide unlimited scrolling. Use Emacs *shell* mode or some extension such a [ediprolog](http://www.logic.at/prolog/ediprolog/ediprolog.html). – frayser Nov 20 '10 at 00:36
  • use `portray_clause` and the terminal to scoll? – Patrick J. S. Sep 25 '14 at 12:01
  • have already looked into library([solution_sequences](https://www.swi-prolog.org/pldoc/man?section=solutionsequences)), specifically **reduced/3** ? – CapelliC Feb 22 '21 at 19:40
  • At least, SWI permits to enter SPACE to see the next answer. This was inspired by less/more/pg – false Feb 22 '21 at 22:56

1 Answers1

1

This is not a complete solution, but wouldn't it be rather easy to write your own pager predicate? Steps:

  1. Create temp file

  2. dump X into temp file with the help of these or those predicates

    (I haven't done any I/O with Prolog yet, but it doesn't seem too messy)

  3. make a system call to less <tempfile>

Felix Dombek
  • 13,664
  • 17
  • 79
  • 131