next up previous contents index
Next: Sample Session Up: Using the System Previous: Loading/consulting and reconsulting programs

Style Checking and Warnings

     bsphackfloatpenalty -Mii floatpenalty-Miii parmoderrfloatpenalty@ nextcurrboxfreelist currbox-2floatpenalty@ fltovf currboxtempboxa tempboxa @floatesphackbsphackfloatpenalty -Mii floatpenalty-Miii parmoderrfloatpenalty@ nextcurrboxfreelist currbox-3floatpenalty@ fltovf currboxtempboxa tempboxa @floatesphack CLP( tex2html_wrap_inline4020 ) programs can be optionally checked against some stylistic conventions, also called style checking. The purpose of the style checking is to give a warning that the program may potentially contain some common ``bugs'' when the style rules are not followed. It is important to remember that these are merely warnings and a program may be perfectly correct otherwise. There are three different kinds of style checking that can be applied -- single_var, discontiguous, name_overload.gif The option all covers all three styles. By default, style checking is on and individual style checking can be turned on (off) with style_check/1 (no_style_check/1), e.g. no_style_check(all) turns off all style checking.

The different style conventions are as follows:

single_var -- This warns if a variable is used only once within a rule and may possibly indicate that a variable has been mispelled. Anonymous variables (_) and also variables prefixed with an underscore are ignored. An example error is the rule ``p(X, Y)'' gives the following warning message:

Warning: Style check, singleton variables, rule 1 of q/2
+++ X, Y

discontiguous -- This style check assumes that all the different rules defining a predicate occur contiguously within a file and warns if there is another intervening rule. Common bugs which can result when this style check is not followed can be mispelling the name of a rule, or substituting a ``.'' to end a rule when a ``,'' was meant to continue the rule, e.g. the program ``p(X) :- X > 0. q(X). p(0) :- r(X).'' where there the intent is for a comma to be before q/1 gives the following warning message:

Warning, ;SPMlt;stdin;SPMgt;:1: Style check, p/1 is not contiguous

name_overload -- This checks whether the same predicate name is defined with different arities. While it is not uncommon to have different predicates of different arities with the same name, it may also be indicative of an incorrect number of arguments, e.g. the program ``p(0,0). p(1). p(2,2).'' gives the following warning message:

Warning: rule overloading, same name, different arity:
+++ p/1, p/2
(Note that when this option has been disabled and then re-enabled, then rules which were defined before style checking was enabled will also generate warnings. The additional warnings can be disabled by using the special system predicate $clear_style_check/0. style_check(all_reset) also does this, clearing all previous warnings and turns on style checking.)

Another kind of warning is given when a rule is defined in more than one file. The basic unit of compilation is a single file and all the occurences of rules for a predicate have to be defined within the same file. The exception is that when a file is being reconsulted, then the new definitions replace the old ones. The compiler will simply ignore all additions to an existing previously compiled predicate and by default a warning is given. See also warning/1 to control whether warnings are given. bsphackfloatpenalty -Mii floatpenalty-Miii parmoderrfloatpenalty@ nextcurrboxfreelist currbox-4floatpenalty@ fltovf currboxtempboxa tempboxa @floatesphack


next up previous contents index
Next: Sample Session Up: Using the System Previous: Loading/consulting and reconsulting programs

Alan Borning
Fri Oct 8 12:51:18 PDT 1999