Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

less-like pager for (swi) prolog

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))).
like image 945
horsh Avatar asked Dec 09 '25 08:12

horsh


1 Answers

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>

like image 168
Felix Dombek Avatar answered Dec 11 '25 20:12

Felix Dombek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!