Does PLDoc have a way to incorporate unit tests akin to Python's doctest?

In looking at the LPN proxy code and thinking about one of the goals of the original question,

it is just a small intuitive leap to realize that the same concept of extracting source code of LPN to generate working SWISH consoles could be applied to the SWI-Prolog documentation. So instead of just adding example source code to the SWI-Prolog documentation which would be read as static code, instead it could have the gear icon added and then a user could click on the gear to launch a SWISH console and play with the predicate. That would be nice.


Details for those not up on this concept.

Originally there was a paper for learning Prolog called Learn Prolog Now.

That evolved into a poplar web site: LPN

Then an enhanced version was created (Notice) that scans the LPN HTML pages for Prolog source code and converts the Prolog source code into an active component with a link, shown as a gear

image

that converts the source code into a SWISH console.

The code that scans the HTML is in lpn-swish-proxy


Example from enhanced LPN, 5.3 Arithmetic and Lists

So this Prolog code in the original LPN site

len([],0).
len([_|T],N) :- len(T,X), N is X+1.

becomes this in the enhanced web site

image

and when the gear is clicked

the Prolog source code is loaded into a SWISH console ready to be run.

2 Likes