Two documentation aids are defined herein:
doc/2 declarations can be used to document predicates and other parts of the program source in place of (or in combination with) the normal comments that are typically inserted in the code (and they are ignored by the compiler in the same way as classical comments). However, they are much preferred to classical comments because they are more structured and they are machine-readable, and can thus also be used to generate printed or on-line documentation automatically, using the lpdoc automatic documentation generator.
Note that in addition to the more structured doc/2 declarations and mark-up language described here, these declarations can also be written in a wiki (markdown) style -- see doccomments for details.
:- module(...,...,[assertions]). :- use_package(assertions).
Note that in strings, each \ character must be escaped (with \, \\), so to get one backslash four backslashes (\\\\) have to be used, i.e., in a string \\\\ is used to represent \\, and that is the command that will output a \ character.
@command
(followed by either a space or {}), or
@command{body}
where command is the command name and body is the (possibly empty) command body. Alternatively, \ can be used instead of {} (escaped if appears in strings).
The set of commands currently admitted can be found in the documentation for the predicate stringcommand/1.
Usage:docstring(Text)
Text is a documentation string.
In order to make it possible to produce documentation in a wide variety of formats, the command set is kept small. The names of the commands are intended to be reminiscent of the commands used in the LaTeX text formatting system. Both ``@'' and ``\'' are allowed in command names. Note that ``\'' needs to be escaped in strings, which makes the source less readable. In such case it is recommended using ``@'' (and, in any case, many ideas in LaTeX were taken from scribe, where the escape character was indeed @!).
The following are the currently admissible commands.
The following commands are used to format certain words or sentences in a special font, build itemized lists, introduce sections, include examples, etc.
The following commands are used to mark certain words or sentences in the text as concepts, names of predicates, libraries, files, etc. The use of these commands is highly recommended, since it results in very useful indices with little effort.
The following commands are used to introduce bibliographic citations and references to sections, urls, email addresses, etc.
The following commands are used to format text in mathematical .
The following commands are used to include code or strings of text as part of documentation. The latter may reside in external files or in the file being documented. The former must be part of the module being documented. There are also commands for inserting and scaling images.
The following commands can be used to insert accents and special characters.
Usage:stringcommand(CO)
CO is a structure denoting a command that is admissible in strings inside assertions.
version_descriptor([]). version_descriptor(version(Version,Date)) :- version_number(Version), ymd_date(Date). version_descriptor(version(Version,Date,Time)) :- version_number(Version), ymd_date(Date), time_struct(Time).
Usage:version_descriptor(Descriptor)
Descriptor is a complete version descriptor.
filetype(module). filetype(user). filetype(include). filetype(package). filetype(application). filetype(part). filetype(documentation).
Usage:filetype(Type)
Type describes the intended use of a file.
stability_level(devel). stability_level(alpha). stability_level(beta). stability_level(prod). stability_level(devel(L)) :- docstring(L). stability_level(alpha(L)) :- docstring(L). stability_level(beta(L)) :- docstring(L). stability_level(prod(L)) :- docstring(L).
Usage:stability_level(Level)
Level describes a level of stability.
Usage 1::- doc(CommentType,TitleText).
Provides a title for the module, library, or application. When generating documentation automatically, the text in TitleText will be used appropriately (e.g., in the cover page as document title or as chapter title if part of a larger document). This will also be used as a brief description of the manual in on-line indices. There should be at most one of these declarations per module.
:- doc(title,"Documentation-oriented assertions").
Usage 2::- doc(CommentType,SubtitleText).
Provides a subtitle, an explanatory or alternate title. The subtitle will be displayed under the proper title.
:- doc(title,"Dr. Strangelove"). :- doc(subtitle,"How I Learned to Stop Worrying and Love the Bomb").
Usage 3::- doc(CommentType,SubtitleText).
Provides additional subtitle lines. This can be, e.g., an explanation of the application to add to the title, the address of the author(s) of the application, etc. When generating documentation automatically, the text in SubtitleText will be used accordingly. Several of these declarations can appear per module, which is useful for, e.g., multiple line addresses.
:- doc(subtitle_extra,"A Reference Manual"). :- doc(subtitle_extra,"Technical Report 1/1.0").
Usage 4::- doc(CommentType,LogoName).
The name of the logo image for the manual.
Usage 5::- doc(CommentType,AuthorText).
Provides the author(s) of the module or application. If present, when generating documentation for the module automatically, the text in AuthorText will be placed in the corresponding chapter or front page. There can be more than one of these declarations per module. In order for author indexing to work properly, please use one author declaration per author. If more explanation is needed (who did what when, etc.) use an acknowledgements comment.
:- doc(author,"Alan Robinson").
Usage 6::- doc(CommentType,Text).
Provides the physical and electronic address, or any other contact information for the authors of the module or application.
:- doc(address,"Syracuse University").
Usage 7::- doc(CommentType,AckText).
Provides acknowledgements for the module. If present, when generating documentation for the module automatically, the text in AckText will be placed in the corresponding chapter or section. There can be only one of these declarations per module.
:- doc(ack,"Module was written by Alan, but others helped.").
Usage 8::- doc(CommentType,StabilityText).
Provides a stability level for the module. If present, when generating documentation for the module automatically, the level of stability of the module will be documented. There can be only one of these declarations per module. The second argument should be an atom, out of a number of predefined stability levels. The text included is predefined for each level. Alternatively, one of the admissible atoms can be used as the functor with a single argument, which contains the text to be included.
:- doc(stability,devel). :- doc(stability,alpha). :- doc(stability,beta). :- doc(stability,prod). :- doc(stability,alpha("My own comment on stability.")).
Usage 9::- doc(CommentType,CopyrightText).
Provides a copyright text. This normally appears somewhere towards the beginning of a printed manual. There should be at most one of these declarations per module.
:- doc(copyright,"Copyright @copyright{} 2001 FSF.").
Usage 10::- doc(CommentType,SummaryText).
Provides a brief global explanation of the application or library. The text in SummaryText will be used as the abstract for the whole manual. There should be at most one of these declarations per module.
:- doc(summary,"This is a @@bf@{very@} important library.").
Usage 11::- doc(CommentType,CommentText).
Provides the main comment text for the module or application. When generating documentation automatically, the text in CommentText will be used as the introduction or main body of the corresponding chapter or manual. There should be at most one of these declarations per module. CommentText may use sections if substructure is needed.
:- doc(module,"This module is the @@lib@{comments@} library.").
Usage 12::- doc(CommentType,CommentText).
Provides additional comments text for a module or application. When generating documentation automatically, the text in CommentText will be used in one of the last sections or appendices of the corresponding chapter or manual. There should be at most one of these declarations per module. CommentText may use subsections if substructure is needed.
:- doc(appendix,"Other module functionality...").
Usage 13::- doc(CommentType,CommentText).
Provides a description of how the library should be loaded. Normally, this information is gathered automatically when generating documentation automatically. This declaration is meant for use when the module needs to be treated in some special way. There should be at most one of these declarations per module.
:- doc(usage,"Do not use: still in development!").
Usage 14::- doc(CommentType,Section).
Insert a program section with name Section. Sectioning commands allow a structured separation of the program into parts. The division is only for documentation purposes, so visibility and scope of definitions is not affected by sectioning commands.
:- doc(section,"Main Steps of the Algorithm").
Usage 15::- doc(CommentType,SubSection).
Insert a program subsection with name SubSection (see program section command for more details).
:- doc(subsection,"Auxiliary Definitions").
Usage 16::- doc(CommentType,SubSubSection).
Insert a program subsubsection with name SubSubSection (see program section command for more details).
:- doc(subsubsection,"Auxiliary Definitions").
Usage 17::- doc(PredName,CommentText).
Provides an introductory comment for a given predicate, function, property, type, etc., denoted by PredName. When generating documentation for the module automatically, the text in Text will be used as the introduction of the corresponding predicate/function/... description. There should be at most one of these declarations per predicate, function, property, or type.
:- doc(doc/2,"This declaration provides one of the main means for adding @@concept@{machine readable comments@} to programs.").
Usage 18::- doc(CommentType,CommentText).
Documents a known bug or planned improvement in the module or application. Several of these declarations can appear per module. When generating documentation automatically, the text in the Text fields will be used as items in an itemized list of module or application bugs.
:- doc(bug,"Comment text still has to be written by user.").
Usage 19::- doc(Version,CommentText).
Provides a means for keeping a log of changes. Version contains the version number and date corresponding to the change and CommentText an explanation of the change. Several of these declarations can appear per module. When generating documentation automatically, the texts in the different CommentText fields typically appear as items in an itemized list of changes. The emacs Ciao mode helps tracking version numbers by prompting for version comments when files are saved. This mode requires version comments to appear in reverse chronological order (i.e., the topmost comment should be the most recent one).
:- doc(version(1*1+21,1998/04/18,15:05*01+'EST'), "Added some missing comments. (Manuel Hermenegildo)").
Usage 20::- doc(CommentType,VersionMaintenanceType).
Defines the type of version maintenance that should be performed by the emacs Ciao mode.
:- doc(version_maintenance,dir('../version')).
Version control info is kept in directory ../version. See the definition of version_maintenance_type/1 for more information on the different version maintenance modes. See the documentation on the emacs Ciao mode in the Ciao manual for information on how to automatically insert version control doc/2 declarations in files.
The version maintenance mode can also be set alternatively by inserting a comment such as:
%% Local Variables: %% mode: CIAO %% update-version-comments: "off" %% End:
The lines above instruct emacs to put the buffer visiting the file in emacs Ciao mode and to turn version maintenance off. Setting the version maintenance mode in this way has the disadvantage that lpdoc will not be aware of the type of version maintenance being performed (the lines above are comments for Prolog). However, this can be useful in fact for setting the version maintenance mode for packages and other files meant for inclusion in other files, since that way the settings will not affect the file in which the package is included.
Usage 21::- doc(CommentType,PredName).
This is a special case that is used to control which predicates are included in the documentation. Normally, only exported predicates are documented. A declaration :- doc(doinclude,PredName). forces documentation for predicate (or type, property, function, ...) PredName to be included even if PredName is not exported. Also, if PredName is reexported from another module, a declaration :- doc(doinclude,PredName). will force the documenation for PredName to appear directly in this module. Finally, predicates whose name starts with $ (often used for internal predicates) are not documented by default and doinclude should be used to force their inclusion.
:- doc(doinclude,p/3).
Usage 22::- doc(CommentType,PredName).
A different usage which allows the second argument of :- doc(doinclude,...) to be a list of predicate names.
Usage 23::- doc(CommentType,PredName).
This is similar to the previous usage but has the opposite effect: it signals that an exported predicate should not be included in the documentation.
:- doc(hide,p/3).
Usage 24::- doc(CommentType,PredName).
A different usage which allows the second argument of :- doc(hide,...) to be a list of predicate names.
Usage 25::- doc(CommentType,FileType).
Provides a way of defining the intended use of the file. This use is normally easily inferred from the contents of the file itself, and therefore such a declaration is in general not needed. The exception is the special case of include files and Ciao packages, which are typically indistiguishable from normal user files (i.e., files which are not modules), but are however quite different in their form of use (they are loaded via include/1 or use_package/1 declarations instead of ensure_loaded/1) and effect (since they are included, they 'export' operators, declarations, etc.). Typically, it is assumed by default that files which are not modules will be used as include files or packages. Thus, a doc/2 declaration of this kind strictly only needs to be added to user-type files.
Example:
:- doc(filetype,user).
There is another special case: the value part. This filetype is used to flag files which serve as introductions to boundaries between major parts in large documents. See Splitting large documents into parts for details.
Usage 26::- doc(CommentType,FileName).
Do not document anything that comes from a file whose name (after taking away the path and the suffix) is FileName. This is used for example when documenting packages to avoid the documenter from including documentation of certain other packages which the package being documented uses.
:- doc(nodoc,regtypes).
version_number(Major*Minor+Patch) :- int(Major), int(Minor), int(Patch).
Usage:version_number(Version)
Version is a complete version number
ymd_date(Y/M/D) :- int(Y), int(M), int(D)..
Usage:ymd_date(Date)
Date is a Year/Month/Day structure denoting a date.
time_struct(Hours:Minutes*Seconds+TimeZone) :- int(Hours), int(Minutes), int(Seconds), atm(TimeZone).
Usage:time_struct(Time)
Time contains time information.
version_maintenance_type(on). version_maintenance_type(off). version_maintenance_type(dir(Path)) :- atm(Path).
The automatic maintenance of version numbers is typically done by the Ciao emacs mode.
Usage:version_maintenance_type(Type)
Type is a type of version maintenance for a file.