SWI-Prolog lynx library - doc error, I guess

At

The documentation for “lynx”, weirdly titled “Title for pldoc(dir_index)”

the predicate trim_line/2 is mentioned.

This predicate does not exist! The correct name is trim_spaces/2.

Defined in file library/lynx/format.pl, module text_format.

Additionally, would it be possible to move this predicate to an autoloaded library? It’s rather useful.

library(readutil)

seems like the right place. Or maybe

library(dcg/basics)

I am not finding that to be the case on my system. Using Windows 10.

Welcome to SWI-Prolog (threaded, 64 bits, version 8.1.24)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- use_module(library(lynx/format)).
true.

?- string_codes(" a b c ",Codes_in),trim_line(Codes_in,Codes_out),string_codes(Line,Codes_out).
Codes_in = Codes_out, Codes_out = [32, 97, 32, 98, 32, 99, 32],
Line = " a b c ".

In the documentation if you click on image at the end of the line it will take you to the source code.

What I did not expect based on just the name (trim_line) was that it does not remove space codes or characters, but space tokens, e.g. Remove leading and trailing white space (b(_,_)) tokens from a line. so moving trim_line/2 is not something I would vote for.

Thanks Eric.

I’m using 8.1.19-37-gc4fb81227 (Thus, dev branch, the stable branch has 8.0.3 still)

?- use_module(library(lynx/format)).
true.

?- string_codes(" a b c ",Codes_in),
trim_line(Codes_in,Codes_out),
string_codes(Line,Codes_out).

ERROR: Unknown procedure: trim_line/2 (DWIM could not correct goal)

Damn you DWIM!

But:

?- string_codes(" a b c ",Codes_in),
|    trim_spaces(Codes_in,Codes_out),
|    string_codes(Line,Codes_out).
Correct to: "text_format:trim_spaces(Codes_in,Codes_out)"? yes
Codes_in = Codes_out, Codes_out = [32, 97, 32, 98, 32, 99, 32],
Line = " a b c ".

So I may be ahead of the documentation.

1 Like

Searching the documentation for trim_spaces does not show trim_spaces.

image

Search Documentation: trim
                      trim
                      trim_line/2
                      trim_stacks/0
                      trimcore/0
                      trimcore/0

Searching the SWI-Prolog source at GitHub I also do not find trim_spaces.

I did find normalize_space/2 (src)

Welcome to SWI-Prolog (threaded, 64 bits, version 8.1.24)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- normalize_space(string(String)," a b c ").
String = "a b c".

:slightly_smiling_face:

I would say that you are behind the documentation.


Your version 8.1.19-37 has a release date of 12/15/2019


AFAIK the online documentation is updated with the Git code and may be there before a release is done.


On Feb 13, 2020 (02/13/2020) format.pl was updated with trim_line/2 which also removed trim_spaces/2 (history)
Commit b392c20e58e77d729aa880c132d393ee7a58ec30


On Feb 15, 2020 (02/15/2020) Release 8.1.22 occurred with the changes to format.pl. In checking the notes the only related item I found is

AUTOLOAD: Support HTML to text conversion (lynx subdir of library).

Since SWI-Prolog is open source it was possible to find and put the details in this post.


Since my system has version 8.1.24 (03/04/2020) the changes made to format.pl are on my system. :slightly_smiling_face: