[comp.lang.prolog] PROLOG Digest V4 #82

PROLOG-REQUEST@SU-SCORE.ARPA (Chuck Restivo, The Moderator) (12/07/86)

PROLOG Digest             Monday, 8 Dec 1986       Volume 4 : Issue 82

Today's Topics:
                     Programming -  Comment Style
----------------------------------------------------------------------

Date: 7 Dec 86 06:04:14 GMT
From: Bruce T. Smith <ihnp4!inuxc!iuvax!bsmith@ucbvax.Berkeley.EDU>
Subject: comment style

I like that kind of comment, too.  In the Prolog systems I've used, 
they are only comments, so it's safe to extend it a bit.

For example:

1) Give multiple specifications when appropriate.  E.g., foo(+X,-Y)
   and foo(-X,+Y) might make sense for a clause, and are not the
   same as foo(?X,?Y).

2) For some patterns of instantiated variables a particular argument
   may be ignored.  I use a prefix '_', like the anonymous variable.

3) Use types, e.g., foo(+Int,-Float).

-- Bruce T. Smith

------------------------------

Date: 3 Dec 86 12:22:01 GMT
From: R. Innis <mcvax!ukc!its63b!csrdi@seismo.css.gov>
Subject: Style

In Prolog Digest V4 #80 John Cugini <cugini@nbs-vms.arpa> writes:

  Many of these predicates expect certain of their arguments to be
  instantiated upon invocation.  When such restrictions apply it is
  usually the leading arguments which are thought of as input (and
  hence instantiated), and the trailing arguments as output (and
  hence allowed to be uninstantiated).

A standard way (at least, in Edinburgh) of denoting the status of 
arguments to a Prolog predicate is to include a comment line before 
the body of the clause, in which arguments expected to be instantiated
are prefixed by '+', uninstantiated arguments by a '-', and arguments 
where it doesn't matter (or where either can be used) by '?'. For 
example,

%% Append(+L1, +L2, -L3)

indicates the status of the arguments to the usual use of the standard
'append' clause. To illustrate further uses, further comments could be
added, viz:

%% Append(+L1, -L2, +L3) is the calling pattern for finding if L1 is a
member %% of L3. (?L2 would also be acceptable).

In use, I've found that this notation makes Prolog code much easier to
read and understand, which given some of what is possible in Prolog is
a very desirable attribute. What say anyone else?

-- Rick Innis

------------------------------

End of PROLOG Digest
********************