Swi-Prolog, WASM and file extensions

I am stymied by the stupidest thing.

My server, over which I have no control, refuses to serve files with the extension .pl.

But SWI-Prolog in the browser turns [foo.pro] into a call to download foo.pro.

Is there a way to tell SWI pl via WASM, not to do that?

– Dave

self-reply: SWI-Prolog will not append an extension to an explicit URL.

The problem recurs, though, with use_module. If the top level file has :- use_module(‘foo.pro’), then prolog again asks for ‘foo.pro.pl’ to be downloaded.

The obvious solution, to use urls in the use_module call would make the code non portable, i.e., could not test locally, I think.

Not sure about the WASM version. Normally you can add a fact for user:prolog_file_type/2 to define alternative extensions as files of type prolog, e.g.

user:prolog_file_type(pro,   prolog).

Note that .prolog is already supported. It could be that the WASM version takes some shortcuts though as it redefines loading files.

… yes. See library(wasm), file_url/2. .pl is hard coded there. Unlike when using the local file system, we typically do not like to search for the URL by trying several options due to the potentially long round trip times.

We could of course get the extension from a hook or flag. As it is not desirable to have two though, this probably result in other issues :frowning: An alternative might be not to bother with adding .pl if there is already an extension. That would be inconsistent with the non-WASM version :frowning: Getting a sane server that does not block arbitrary extensions would be great. Perl is no longer that widespread AFAIK …

Thanks Jan, Glad we are still both doing Prolog after all the these years…

I am working on getting the server people to agree with what is the obvious solution to this specific issue.

However, in general, when I ask for something, and that thing exists, then I think that that is what I should get. If that thing does not exist, then it is helpful to try alternatives. This is the rule that dwim uses for predicates, for example.

I do think that not adding .pl if there is already an extension is a good idea, and I think that in the case of the non WASM version too (though that probably breaks years of convention).

Thanks – Dave

That of course is the weak point. What is an extension? One thing we can do for sure is to see whether one of the already defined extensions for Prolog files is present. That would allow for .prolog out of the box and after adding user:prolog_file_type(pro, prolog), also for .pro. I’ll add that.

edit oops. I see it is already defined that way for the WASM version. So, just add the clause for prolog_file_type/2 and you should be fine.

With user:prolog_file_type(prolog, prolog).

:- use_module(foo) foes not work, but use_module(‘foo.prolog’) does work, which is close enough for jazz.

Thanks – Dave

Note that that clause is already built-in. See

 ?- listing(prolog_file_type).