Prolog Commenting
Basics
Prolog supports both multi‑line and single‑line comments.
Multi‑line comments use C‑style comment delimiters:
Note that SWI‑Prolog allows
/*...*/
delimiters to be nested inside each other, something
that C (and the Prolog ISO standard) do not. You're welcome to write nested multi‑line
comments in class, however, since we are using SWI‑Prolog.
For single‑line comments, Prolog uses the percent sign (
%
) as the comment delimiter:
Documenting Predicates
For documenting predicates, we will use a Prolog adaptation of Javadoc‑style comments.
Place the comment for a predicate above the first fact or rule for that predicate:
First, notice that we cannot determine the argument names, argument types, or parameter
modes just by looking at the facts and rules defining the predicate, since these are not
explicitly declared in Prolog. As a result, the predicate documentation must begin with one
a
declaration header
that defines the argument names, types, and modes. This declaration
header includes one or more lines that show alternative
instantiation patterns
for a
predicate‑‑that is, indicating different ways the predicate may be called with variables or
with bound values in different parameter positions. Each line should use the same formal
parameter names for the arguments appearing in the predicate. Arguments can also
include a colon (:) and type specifier to indicate the expected type of that parameter.
Typically, arguments are usually one of the following:
+ArgName
A
bound
value, which is often considered an
incoming
value ("in" mode) provided by the
caller.
-ArgName
/* This is
a multiline
comment. */
% This is a single line comment.
/**
* concat(+List1 : list, ?List2 : list, ?List3 : list).
* concat(?List1 : list, ?List2 : list, +List3 : list).
*
* Succeeds if the third list is the concatenation of the first two.
*
* @param List1 The first (left) list to join.
* @param List2 The second (right) list to join.
* @param List3 The list containing all the elements of List1
* followed by all the elements of List2.
*/
concat([], List, List).
concat([Head | Tail], List, [Head | Rest]) :-
concat(Tail, List, Rest).