# Swi-Prolog, WASM and file extensions

**URL:** <https://swi-prolog.discourse.group/t/swi-prolog-wasm-and-file-extensions/7730>\
**Category:** General\
**Created:** [August 24, 2024, 8:39pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-wasm-and-file-extensions/7730 "2024-08-24T20:39:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://swi-prolog.discourse.group/u/Dave)\
**Post date:** [August 24, 2024, 8:39pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-wasm-and-file-extensions/7730/1 "2024-08-24T20:39:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://swi-prolog.discourse.group/u/Dave)\
**Post date:** [August 24, 2024, 9:34pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-wasm-and-file-extensions/7730/2 "2024-08-24T21:34:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [August 25, 2024, 7:23am UTC](https://swi-prolog.discourse.group/t/swi-prolog-wasm-and-file-extensions/7730/3 "2024-08-25T07:23:13Z")

</div>

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 ☹ 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 ☹ Getting a sane server that does not block arbitrary extensions would be great. Perl is no longer that widespread AFAIK …

---

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://swi-prolog.discourse.group/u/Dave)\
**Post date:** [August 25, 2024, 3:46pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-wasm-and-file-extensions/7730/4 "2024-08-25T15:46:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [August 26, 2024, 6:49am UTC](https://swi-prolog.discourse.group/t/swi-prolog-wasm-and-file-extensions/7730/5 "2024-08-26T06:49:39Z")

</div>

> [@Dave](#):
>
> if there is already an extension

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.

---

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://swi-prolog.discourse.group/u/Dave)\
**Post date:** [August 26, 2024, 4:11pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-wasm-and-file-extensions/7730/6 "2024-08-26T16:11:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [August 26, 2024, 4:14pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-wasm-and-file-extensions/7730/7 "2024-08-26T16:14:40Z")

</div>

> [@Dave](#):
>
> user:prolog\_file\_type(prolog, prolog).

Note that that clause is already built-in. See

```
 ?- listing(prolog_file_type).

```
