PROLOG Digest V4 #82 
Author Message
 PROLOG Digest V4 #82

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

Today's Topics:
                     Programming -  Comment Style

Date: 7 Dec 86 06:04:14 GMT

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

Subject: Style

  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

%% 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

Wed, 19 May 1993 09:58:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. INFO-ADA Digest V93 #82

2. PROLOG Digest V4 #90

3. PROLOG Digest V4 #89

4. PROLOG Digest V4 #88

5. PROLOG Digest V4 #87

6. PROLOG Digest V4 #86

7. PROLOG Digest V4 #85

8. PROLOG Digest V4 #84

9. PROLOG Digest V4 #80

10. PROLOG Digest V4 #81

11. PROLOG Digest V4 #79

12. PROLOG Digest V4 #78


Powered by phpBB® Forum Software