This directory provides examples for the SWI-Prolog built-in predicates as well as the library. Examples are PlDoc (markdown) files with the following properties:
-
The file extension is
.md
. -
The file name can be the predicate name, optionally followed by the arity, e.g.,
append3.md
orhalt.md
. Without an arity it associates to a predicate with the same name, regardless of the arity. An example identified this way is the primary example, is displayed as first and always visible. -
They optionally have a title. The title is identified using a level-1 markdown title, e.g.
# Using append/3 for splitting lists
-
Code blocks are supposed to contain either valid program snippets or queries. Queries are identified e.g.,
?- member(X, [1,2,3]).
. If the next term looks like an answer is is ignored for indexing. Code blocks are cross-referenced and use to bind the example to predicates. -
Markdown text is analysed for predicate indicators, linking the example to the referenced predicates.
Examples are ordered according to the list below. Further versions may use more advanced ordering.
- file name
- reference in the title
- appearing as query
- called in some code block
- reference in the running text.
- Keep examples short
- Do not try to document the predicate as the documentation is already present.
This is a first prototype. Some ideas:
- Get examples from a Discourse Category rather than git?
- Embed SWISH, similar to LPN with SWISH
- Show/highlight the fragment of an example that refers to the predicate.
- Use HTML coloring of the code fragments with linking.