Write 'n flush

I’d like to write a dot as a progress indicator for some computation. I noticed that write/1 doesn’t flush immediately, so i get nothing, and then many dots at the end of the computation.

I looked for write options in the documentation, but didnt find anything …

How can i get the dots show immediately –

thank you,

Dan

Does this not work?
http://www.swi-prolog.org/pldoc/man?predicate=flush_output/1

ah, yes … i didnt see it …

thank you

One of the hardest things is finding stuff. I have myself many times failed to find things that were right in front of my face (asking if keysort/2 is stable stands out in my memory as one of the more embarrassing examples) . At some point I even suspected that Jan reads my questions, then re-writes the documentation and the git history, then tells me “it is right there in the documentation”, as a practical joke.

Here are a few tricks (my kids call them “lifehacks”, which seems to be an example of the euphemism treadmill):

Reading the source

This is useful and sometimes necessary. It is difficult and time consuming, but educational. It doesn’t directly solve the problem, but you can search the code using full text search, for example, inside the swipl-devel root directory:

$ grep -r '\<flush\>' | less
man/builtin.doc:    \termitem{flush}{}
library/tty.pl:   format('    Your choice? ~T', [clear_display, flush]),
library/tty.pl:tty_action(flush) :-
library/win_menu.pl:    [ 'Opening ~w ... '-[Url], flush ].
library/backcomp.pl:            flush/0,
library/backcomp.pl:%!  flush is det.
library/backcomp.pl:flush :-

and so on. By a stroke of pure luck, the first few lines already suggest there is indeed something called “flush”. It would require additional investigation, but at least we have a lead.

Of course, this is an overkill and last resort (which is why I mentioned it first).

Using the search function of the SWI-Prolog website

I realize this is a bit counter intuitive, but bear with me. Here is what happens if I open the home page and start typing “flush” in the search bar:

I got lucky again: just blindly typing “flush” in the search bar I get few hits that make me hopeful that I am getting close to what I need.

Finding with the browser

This is a habit that was admittedly not easy to get into. If I feel like I should be close to what I am looking for, but can’t seem to find it, just hit Ctrl+F on your keyboard and start typing. For example, when I was looking at keysort/2, had I done that, I would have seen:

Similarly, if you go to the aptly named “Input and output” section of the manual, and try to find “flush”, you get immediately thrown to:

… and suddenly flushing the output is only a click away!


I am sure that there are many other tips and tricks people could provide on the topic of finding stuff. This is already turning into a blog post and this was definitely not my intent.

2 Likes

Google search does reasonably well, most of the time:
https://www.google.com/search?q=swipl+flush

But not always, e.g.: https://www.google.com/search?q=swipl+dict

1 Like

I have a guess about why finding stuff on the SWI-Prolog website is hard.

My guess: Readers have difficulty because most paragraphs in the SWI-Prolog website have too many ideas. That is, those paragraphs talk about several topics at once.

For example, this is how I would have written the documentation of keysort/2:

Sort a list of pairs.

List must be a list of …

Duplicates are not removed.

Sorting is stable

as opposed to the current state:

Sort a list of pairs. List must be a list of … Duplicates … Sorting is stable

That is, I would write four paragraphs instead of one.

However, the same source file is also used to generate printable PDF documents. Thus there are two conflicting requirements: to be scannable on screen, and to look pretty on paper.

Typographically, short paragraphs look ugly: They look jagged on paper. But I think when we have to choose between readability and typography, I think we should choose the former.