Line endings with ensure_loaded/1

Recently in swipl-8.2.1/windows/64-bit we ran into issues when some part of our tool chain decided to replace line endings <cr><lf> with <cr><cr><lf>. This caused swipl to silently ignore the files, and I had similar issues on bsd. I can’t tell if this is expected behavior, and if so, what is the reason for ignoring silently?

Best regards - Nikolaj

… ok, I see my text changed when posting - line endings in our files were changed from CR-LF to CR-CR-LF… inserting an additional CR before the line ending.

I fixed it by fencing the text with backquotes, e.g. `.

See: Markdown (I know the reference is to another site but the Markdown is basically the same as used with Discourse).

Thank you :slight_smile:

This is normally how Prolog works. Remember that Prolog is a logic language that is made up of only predicates, and predicates return either true or false (think silently fail).

Take a look at the results of the Google search swi prolog 'fail silently'

Since you did not give specifics it is hard to give specific advise.

If you want errors then perhaps look at must_be/2.

Sorry - when I consult my prolog source files from disk, all clauses in the files are ignored when my line endings are bad. Swipl doesn’t complain about it.

How exactly did you try to consult the files?

Thanks, that puts a different perspective on the problem. Now it makes more sense.

Might be a bug, I will try to reproduce it and if so, then I am sure Jan W. will reflect upon this with info or a fix.

I use ensure_loaded(<filename>).

All the compile predicates in the end call load_files/2. Simple thing doesn’t reproduce:

?- open('', write, Out), format(Out, 'a(1).\r\r\na(2).\r\r\n', []), close(Out).

And then

?- [x].
?- a(X).
X = 1 ;
X = 2.

Seems totally normal. Also what I’d expect: Prolog doesn’t care about white space. In DOS line mode it strips \r from the input, but that is all AFAIK. So, please come with something to reproduce this.

1 Like

Using SWI-Prolog on Windows 10
SWI-Prolog (threaded, 64 bits, version 8.3.6)

Created a file that loads correctly with consult/1.
Then using Notepad++ converted the /r to /r/r.
consult/1 worked correctly on this file.

Then restarted the top level.
ensure_loaded/1 worked correctly on this file.

The file contained


Checking to see if the fact was loaded.

?- listing(fact).


I will return once I can reproduce it; it’s been a while since I saw it myself, so I need a colleague on vacation to reproduce. As I recall, we use goal_expansion to tweak database, and messing up line endings would cause the expanded goals to disappear.

Minimal and reproducible working examples