white space

In writing code in Prolog or any other programming language, white space (blank lines, indentation, perhaps alignment of related data items) can be used to make the code easier to follow. Here are some suggestions:

Example. In moderate size browser windows, the bad example will have long lines that are folded by the browser, and the good example will not. In practice, you could make the lines in the good example rather longer - up to 75-80 characters.
GoodBad
% smallest(+ListOfNumbers, -Min)
%  binds Min to the smallest item
%  in the non-empty ListOfNumbers.
%  ListOfNumbers should be instantiated
%  at time of call.
smallest([FirstNum], FirstNum).
smallest([FirstNum | Rest], Min) :-
      smallest(Rest, MinRest),
      smaller(FirstNum, MinRest, Min).
 
% smaller(+First, +Second, -Smaller)
%  helper procedure for smallest.
smaller(A, B, A) :-
      A <= B.
smaller(A, B, B) :-
      B < A.
% smallest(ListOfNumbers, Min) binds Min to the smallest item in the non-empty ListOfNumbers. ListOfNumbers should be instantiated at time of call.
smaller(A, B, A) :- A <= B.
smaller(A, B, B) :- B < A.
% This is a helper procedure for smallest.
smallest([FirstNum], FirstNum).
smallest([FirstNum | Rest], Min) :- smallest(Rest, MinRest), smaller(FirstNum, MinRest, Min).

See also indentation and comments.