# SWI-Prolog lynx library - doc error, I guess

**URL:** <https://swi-prolog.discourse.group/t/swi-prolog-lynx-library-doc-error-i-guess/1978>\
**Category:** SWI-Prolog web site and services\
**Created:** [March 7, 2020, 12:19pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-lynx-library-doc-error-i-guess/1978 "2020-03-07T12:19:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dtonhofer](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/dtonhofer/32/902_2.png) [@dtonhofer](https://swi-prolog.discourse.group/u/dtonhofer)\
**Post date:** [March 7, 2020, 12:19pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-lynx-library-doc-error-i-guess/1978/1 "2020-03-07T12:19:52Z")

</div>

At

[The documentation for “lynx”, weirdly titled “Title for pldoc(dir\_index)”](https://www.swi-prolog.org/pldoc/doc/_SWI_/library/lynx/index.html)

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)](https://eu.swi-prolog.org/pldoc/doc/_SWI_/library/readutil.pl)

seems like the right place. Or maybe

[library(dcg/basics)](https://eu.swi-prolog.org/pldoc/man?section=basics)

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [March 7, 2020, 12:54pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-lynx-library-doc-error-i-guess/1978/2 "2020-03-07T12:54:29Z")

</div>

> [@dtonhofer](#):
>
> the predicate `trim_line/2` is mentioned.
> 
> This predicate does not exist!

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

```prolog
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](https://www.swi-prolog.org/pldoc/doc/_SWI_/library/lynx/index.html) if you click on ![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/1X/0a1ac5568086658351ac3bbb5f1e9ae25846fdfc.png) 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.

---

<div class="post-metadata">

**Author:** ![dtonhofer](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/dtonhofer/32/902_2.png) [@dtonhofer](https://swi-prolog.discourse.group/u/dtonhofer)\
**Post date:** [March 7, 2020, 1:08pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-lynx-library-doc-error-i-guess/1978/3 "2020-03-07T13:08:13Z")

</div>

Thanks Eric.

I’m using `8.1.19-37-gc4fb81227` (Thus, [dev branch](https://www.swi-prolog.org/download/devel), the [stable branch](https://www.swi-prolog.org/download/stable) has 8.0.3 still)

```prolog
?- 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:

```prolog
?- 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.

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [March 7, 2020, 1:09pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-lynx-library-doc-error-i-guess/1978/4 "2020-03-07T13:09:21Z")

</div>

> [@dtonhofer](#):
>
> The correct name is `trim_spaces/2` .

Searching the documentation for `trim_spaces` does not show `trim_spaces`.

![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/1X/85d54b9b862e4d4e88a8d23199de3431bf55ae75.png)

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

```

[Searching](https://github.com/SWI-Prolog/swipl-devel/search?q=trim_spaces&unscoped_q=trim_spaces) the SWI-Prolog [source](https://github.com/SWI-Prolog/swipl-devel) at GitHub I also do not find `trim_spaces`.

I did find [normalize\_space/2](https://www.swi-prolog.org/pldoc/man?predicate=normalize_space/2) ([src](https://github.com/SWI-Prolog/swipl-devel/blob/c2b0232935f995aadff87e2cab76265dd1203818/src/os/pl-ctype.c#L684))

```prolog
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".

```

🙂

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [March 7, 2020, 1:47pm UTC](https://swi-prolog.discourse.group/t/swi-prolog-lynx-library-doc-error-i-guess/1978/5 "2020-03-07T13:47:32Z")

</div>

> [@dtonhofer](#):
>
> So I may be ahead of the documentation.

I would say that you are behind the documentation.

* * *

Your version 8.1.19-37 has a [release](https://github.com/SWI-Prolog/swipl-devel/releases) 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](https://github.com/SWI-Prolog/swipl-devel/blob/61a937543314cc59ab46b33dc9abaed8c39fe222/library/lynx/format.pl) was updated with `trim_line/2` which also removed `trim_spaces/2` ([history](https://github.com/SWI-Prolog/swipl-devel/commits/master/library/lynx/format.pl))  
Commit [b392c20e58e77d729aa880c132d393ee7a58ec30](https://github.com/SWI-Prolog/swipl-devel/commit/b392c20e58e77d729aa880c132d393ee7a58ec30)

* * *

On Feb 15, 2020 (02/15/2020) Release [8.1.22](https://swi-prolog.discourse.group/t/ann-swi-prolog-8-1-22/1867) 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. 🙂
