Progressing the SWI-Prolog environment

Some remarks (may have missed some)

  • The history file is determined by dir_history_file/2 in library(prolog_history). The name is not a hash, but the base32-encoding of the absolute file name. Upper or lower case should not matter. The predicate is bi-directional, so you can find the project directory from the file and the other way around.
  • Dealing with the old history is probably something that should be fixed. Should not be too hard. It will write in the new format though, so you cannot jump forward and backward easily. The libedit format uses a bit proprietary encoding of characters that is not easy to handle without libedit (at least, not for non-ASCII).
  • If you want to share the init.pl file, use e.g.,
:- if((current_prolog_flag(version, V), V >= 90333)).
<code>
:- endif.
  • The history is saved on program exit. How do you terminate Prolog? I normally use Ctrl-D (end-of-file) in the console. That seems to work fine. Note there is a flag save_history that should be set to true. If it is not, something is wrong …

Thanks! I missed that predicate, and the entire library too. I’ll go have a look.

I think if the history is only (easily) backwards compatible nobody will complain. I sure won’t. If I can get my old history in the new version that’s all I need. I think for most people they’ll tend to upgrade monotonically, as it were, but of course that’s something for the community to discuss.

I have two main ways that I usually terminate Prolog:

  1. enter ?- halt.
  2. Cause a catastrophic error.

I’m used to losing the last few lines of history when 2. happens.

I got the save_history flag set to true in v.9.3.24 and in v.9.3.33.

Btw, forgot to say:

Yeah, I think that’s nice to have

Edit: Actually, I think I didn’t understand what you mean by ā€œnumbered history accessā€. You mean by !<number>?

Btw, I noticed that in some SWI versions you get a number at the start of a new prompt line. I mean that if a query terminates and then the listener returns to the ?-, there’s a number at the start of the line like 2 ?- . I think I only see that in the OS terminal sessions, not in the IDE, but at this point I’m a bit confused about which version does what so I’d have to check, sorrry!

Is that query numbering related to the lines in the history file also?

Probably a lot of it should be rewritten. There is too much history in the history implementation :slight_smile: Now everything seems to have a solid common ground on all platforms, so we can delete and simplify a lot of stuff.

Thanks. I’ll check that out. Ctrl-D is shorter and (AFAIK) works.

History … Before all this began and commandline editors were not common, history was based on storing commands in the Prolog database and allow reused using !<expr>. Then commandline editors came into place. By default, the commandline editor takes over and !!, etc are gone. Using

 :- set_prolog_flag(history, 50).

Both are enabled and kept in sync. Given the current state it might be better to remove the old pure Prolog history and integrate !! expansion with the commandline editor. That would remove quite a bit of very old code :slight_smile:

1 Like

Hey, I wonder if I managed to confuse you with my awful sense of humour. I realise that my previous comment could be interpreted as saying that after halt I get a ā€œcatastrophic errorā€. What I meant was that I usually exit Prolog with halt, but sometimes I manage to crash the console so I ā€œterminate Prologā€ that way instead. I don’t think I’ve ever seen the console crash after halt.

Apologies if I confused you.

I was not confused :slight_smile: Actually, there is a problem with halt executed in the context of the Epilog consoles. Try

 swipl-win -g "mygoal,halt"

That does crash :frowning: I know why, but I still have to find an elegant solution.

P.s. Today’s Windows binaries give you a native file dialog for the Epilog file related actions. Works (for me) on Windows-11, MacOS and Fedora Linux using Gnome.

1 Like

Oh. OK, yeah, that crashes. Funny thing, I’ve seen something like that before but I think it was exit status 4. It happens occasionally but I’m not sure when.

Yay! I’m gonna try it. Thanks!

Edit: tried it, looks great!