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!

I’m confused now why I said that because the file dialog hasn’t changed at all, it’s still what I think is the 30-year old XPCE dialog. Sorry to upload an image but just to be clear, this is what the dialog looks like:

That’s the new-file dialog in the editor, accessed by File > New… > Browse.

There’s also a ā€œnewā€ item in the console menu: File > New and while that opens a Windows Explorer window, it now gives me an error. I had to copy it manually because after I click the save or cancel button in the explorer window, SWI crashes:

31 ?- ERROR: [Thread main] @235576895175/epilog_frame: frame<-{open,save}_file: dialogg: An attempt was made to reference a token that does not exist.

This is with the latest stable version, 64 bits 10.1.5 on Windows.

Edit: also happens with the latest build on windows. I’m on widows 11 pro 64 bits.

Here’s something else. With the latest stable build for windows, when I click on the ā€œFileā€ menu in the editor (not the console) I get this message at the top-level:

33 ?- XopenImage(@ms_left_arrow_image/image)

In fact this seems to happen with every menu item in the editor, but only the first time any item is clicked. So if I click ā€œNewā€ I get the output above, then if I click ā€œCompileā€ there’s no output.

Version 10.1.4-36-gec0988dab-DIRTY, 64 bits.

Calling the SDL file dialog interface takes different parameters and not all places have been updated. At least the 30 year old thing still works :slight_smile:

I see. This worked. Still works fine on Linux and MacOS. The message does not come from Prolog/xpce but from Windows and seems to address some security limitation. I’ll try to look into this …

Thanks. Some old remain. Updated.

1 Like

Thanks! I’ll wait for the next daily build?

Meanwhile, I’m starting to worry you’re gonna want to kill me but there’s something else changed in the new environment.

Before the switch to epilog, I could CTRL+arrow key at the console and jump between ā€œwordsā€. This is no longer possible on windows, where CTRL+arrow key does nothing, and I have to slog through long queries with just the arrow keys one character at a time.

That’s the console. On the command line, I get a series of ;5D escapes and no movement.

I get the same behaviour on linux, or rather WSL running Ubuntu 22.04.

SWI version on windows: 10.1.4-36-gec0988dab-DIRTY
SWI version on Linux: 9.3.20-11-g96e0fabbd

Can I do something about this? That’s just the shell not recognising escape sequences, no?

Yes. This message is rather innocent though. The only consequence is that pullright menus show no arrow to indicate there is a pullright.

Well, I think you are at a safe distance not to worry too much :slight_smile: Improving the user experience is (I think) quite important.

That is because the command line editor is now based on libedit rather than being a Windows GUI application. There seem to be a half-baked standard to pass modifiers using escape sequences. But, libedit does not implement this (which is why you see part of the uninterpreted escape sequence) and Epilog does not send it. The latter is surely quite easy to add, but not very useful without extending libedit. At some point I’ll consider that.

Meanwhile, libedit accepts Emacs sequences, so Alt-b and Alt-f (or ESC b and ESC f) move backward or forwards over a word. Also useful are Ctrl-A and Ctrl-E that move to the start or the end of the command.

That is really serious. It seems this was introduced by moving from SDL 3.2 to SDL 3.4. I am now trying to see whether claude can come with a work-around. It seems complicated :frowning: It it fails there seem to be three ways out

  • Revert to xpce’s native file dialog :frowning:
  • Switch back to SDL3.2 and report an issue with SDL. This is a little complicated though as it requires building SDL3 for Windows on Linux or switch back to Fedora 42. But, that is nearly EOL and switches back to an older GCC that produces a slower Prolog :frowning:
  • Bypass SDL3 for the file dialog and call the native Windows file dialog. That is how it used to be, but means more Windows specific code, something I wanted to get rid of :frowning:
1 Like

After about 15 minutes and endless commands, Claude indeed managed to nail the issue. It is a bug in SDL3.4, reported as `SDL_ShowOpenFileDialog`'s `default_location` handling of multiple levels of missing paths causes `callback` to be invoked twice on Windows (SDL 3.4.2) Ā· Issue #15194 Ā· libsdl-org/SDL Ā· GitHub. There is a PR for fixing this. Claude however managed to find a dirty but simple and effective work around. Sometime I want to throw the AI through the window, but this time I am pretty impressed and it saved me a lot of annoying work. Note that I started using ChatGPT. This failed miserably finding the actual cause as it got on the wrong track due to the misleading error message. It then suggested several work arounds for something that was not the problem, so it got nowhere.

P.s. Triggered building the daily, so the last (March 12) should be ok.

2 Likes

Thanks, Jan. I got the daily build (10.1.5-2-gc829d651e-DIRTY)) and I’m trying it now. Seems like I managed to get it to freeze by clicking around the File > New dialogue, but that happened only once, otherwise everything seems to be working OK now, no error and no pullright menu message.

I also tried the Esc/Alt-b/f thing and it works so that’s good, I can get used to that. At the cost of getting Emacs thumb :laughing:

What’s the difference? I run Ubuntu on WSL but I dual-boot windows with Fedora on my main machine. What differences can I expect to see there?

Claude? Et tu Jan? :sweat_smile:

Between what and what? Fedora 42 uses SDL 3.2 and GCC 14 and Fedora 43 SDL 3.4 and GCC 15. We do not use any feature specific to SDL 3.4, but they changed the way the File Dialog is implemented for Windows and introduced a bug. GCC 15 produces somewhat faster code for Prolog. The SDL bug will probably hit us for a while as the fix is not yet in the main repo and Fedora 44 will be out soon.

SWI-Prolog build for Windows is created by cross-compiling using Fedora (in a Docker container). Originally I used Ubuntu for this, but Fedora has more ready to use dependencies for MinGW and more up-to-date compilers.

2 Likes

Thanks! I meant the difference between Fedora and Windows. I guess I could have just booted it up and found out. I think I’m on Fedora 42 btw, probably need to update at some point.

For running SWI-Prolog? From version 10, both versions pretty much have the same functionality. Running pure Prolog code has about the same performance. Thread management, I/O and graphics are a lot faster on Fedora. Not sure how much of that is lost by the WSL layer. My new dev machine is dual boot. The Fedora version feels a lot snappier than the Windows 11 version and text rendering is clearer.

Then there are some subtle differences in which predicates can be interrupted using thread signals and Ctrl-C. The Linux version used to be much more stable, but the work by @mgondan1 and @EricGT recently have fixed many issues in the Windows version.

2 Likes

That’s a good reason to spend more time on Fedora. But thanks to @mgondan1 and @EricGT for the work on the windows version!

2 Likes

3 posts were merged into an existing topic: Using Claude Code to create skills, commands, plans, … for SWI-Prolog

@jan I’ve been thinking about this comment I made in an offhand manner last time and it’s made me feel uncomfortable. I don’t want it to sound like I don’t respect your time. I guess it’s no secret that I don’t like LLMs but I’m glad that AI helped you save time. I’ve watched you for over a decade that I’ve been using SWI-Prolog and you’re like a bug-killing machine, I guess the result of having worked on this project for… isn’t it 30+ years now? So I would always think that if an AI can find a bug in 15 minutes, you can find it and squish in 5. But I guess this time it was something completely unrelated to SWI.

Anyway I didn’t want to give the wrong impression. I hope you know I respect and admire your work. Sorry if that sounds cheesy. I’m a very cheesy person, but more to the point I’ve had the time of my life since 2017, when I started my PhD studying ILP, and none of that would have been possible without your work on SWI. Because if I needed to write something like SWI myself to run my ILP algorithms, I could never do it. I would have ended up with some shitty academic prototype of Prolog just stable enough to write my papers on, and nothing more. SWI is an industrial-strength Prolog implementation and I thank my lucky stars that I started my PhD (not to mention, learned to program at all, much earlier than that) at a time when it existed.

So, I hope I didn’t offend you with my stupid joke. I have a weird sense of humour. Some people will say I don’t have a sense of humour.

1 Like

Not at all :slight_smile: Note that besides a bug killing machine, I’m also a bug generator :slight_smile:

And I use LLMs. Mostly because I want to understand what they can do and how I can best make use of them. I’m not sure it saves me time. Sometimes it clearly does, sometimes it clearly costs time as the LLM keeps looking in the wrong direction. And, sometimes the LLM can do work that I might be able to do just as fast, but which is very boring.

All in all, they are an ā€œinteresting companionā€ :slight_smile: Considering what they could do a year ago they improve incredibly fast.

2 Likes