Wiki Discussion: Using WSL on Windows with SWI-Prolog

Example of using SWI-Prolog 8.3.4 on Unbuntu 18.04 on WSL 2 and accessing a Prolog source file on Windows 10


Steps to use the SWI-Prolog pack callgraph

  1. Start WSL 2
    Since I have it on the task bar a click on the icon starts it up.

  2. Install graphviz

$ sudo apt-get install graphviz
  1. Locate the Windows directory of the source file to be used as input for callgraph.

  2. Change to the Windows directory

groot@WINDOWS-8B295QT: cd "/mnt/c/users/groot/documents"
  1. Start swipl
groot@WINDOWS-8B295QT:/mnt/c/.../documents$ swipl
  1. Install pack callgraph
?- pack_install(callgraph).
  1. Load callgraph
?- use_module(library(callgraph)).
  1. Load source file using consult/1.
?- [rfc5234_structures].
  1. Use callgraph on source file.
?- module_dotpdf(rfc5234_structures,[]).
  1. Open PDF file in same directory as source file.

Using module_dot/2 the file will be output as a dot file which can be converted to SVG.

rfc5234_structures

Note: To better see or resize the image open it in a new Internet browser tab.

Personal note on uploading SVG files

Discourse does not look for the height and width values beyond the first hundred charters or so.

<svg width="1338pt" height="1268pt"

When graphviz generates an SVG it puts a comment before the height and width which puts the height and width beyond what Discourse will seek. So by simply deleting the comment from the SVG file, which is text, and then saving the file, Discourse will then see the height and width and not complain.

Personal note on printing

Trying to print an SVG from an Internet browser or even just trying to print an SVG file loaded into another application just does not seem to work. Only one page is printed which is a fraction of the entire SVG.

A better way to print the image is to convert the output to a PDF file and then print.
Using Adobe Acrobat is a reasonable way to open the PDF for printing.
To print from Adobe Acrobat, use the menu options to access the print dialog, i.e. File -> Print.
Then in the middle of the dialog click on Poster.
Select Tile Scale and using the keyboard up and down arrows look to the right at the preview to see how the image will be printed. As you scale the number of pages needed to print will change.
Once the scale is set, click Print.


Since these were not cut and paste copies of the actual commands they may have some errors.

Note: The reason WSL 2 was used instead of using Windows 10 is that the pack callgraph uses pack swipe which exclusively uses Linux pipes. Trying callgraph on Windows 10 will only result in errors.


Side note:

Some SWI-Prolog packs rely on MinGW or MSYS and will report an error like

ERROR: Cannot find MinGW and/or MSYS.
ERROR: source_sink `path(make)' does not exist

While the pack will not work directly on Windows, installing the pack as demonstrated in this post is a viable workaround if you can use WSL 2. Remember that many organizations may not allow for the installation of WSL in which case this is not a viable workaround.