[mod.ai] Preliminary notes on Turbo Prolog

cugini@NBS-VMS.ARPA.UUCP (05/16/86)

             Quickie Review of Turbo Prolog

This is a rough set of notes about Turbo Prolog (hereafter TP). 
It is a *linguistic* comparison of TP vs. the Clocksin & Mellish
book (CM) and Pereira's CProlog (CP).  It is based mostly on a
reading of the TP manual, not live experimentation with the
product itself.  There is no evaluation of performance, nor much
of the programming environment provided by TP. 

TP is related to, but by no means compatible with, either CM or CP.
In the list below, I've put TP/CP differences first, and then
TP enhancements.


1. Declarations.

Structures must have the types of their arguments declared.  That
is, you can't just toss in compound terms in facts and rules.
The functors for all predicates must be declared, together with
role names for each of the arguments, in a PREDICATES section,
like this:

predicates
  person(name, height, weight, hair_color)
  name2(last, first)
  name3(last, first, middle)

and each role must declare from which domain(s) it is drawn,
in a DOMAINS section (which must precede the predicates section);
very relational databasy:

domains
  name = name2(last, first); name3(last, first, middle)
         /* name is either a name2 or name3 structure.  */
  first, middle, last = symbol
         /* first, middle, and last are all (atomic) symbols. */
  height = integer
  weight = real
  hair_color = symbol

What's normally thought of as the regular program is contained
in a CLAUSES section, following the two above.

There are five primitive atomic data types (integer, real, char,
string, symbol), and everything is built from these.

A given domain may consist of a single primitive type or a
disjunction of compound types, but *not* a disjunction of
primitive types.  Since lists are declared like this:
  
   numlist = integer*  /* numlist is a list of integers  */

it appears that lists must be relatively homogeneous, ie,
must contain elements of either a single primitive type, or
a few compound types.  The whole flavor is much more that of
compilation, data definition, Pascal, and type-checking, than of
the usual interpreted, free-spirited CP or CM.  Thus TP stresses
documentation, security, and efficiency, but disables some
dynamic data building features.


2. Declaring the use of Arguments.

When an argument may be passed unbound from one sub-goal to
another, it must be declared as a *reference* whatever, back up
in the domain declarations to tell TP to pass it be reference,
since TP otherwise assumes it can be passed by value (i.e.
already instantiated), eg:

domains
   height = reference integer  /* height is a pointer to an integer */
   tree =   reference node(integer, tree, tree)  
               /* note recursive structure */


3. No meta-logical probing of the DB.

There is nothing like CP's predicates: =.., functor, arg,
clause, or current_functor for fiddling with the current
program's clauses.  In general, there's is no run-time
inspection or building of rules. Assert and retract work
only for facts.


4. There are no user-defined operators, nor CP's expand_term
for pre-processing.


5. Syntax shuffling - 

TP                   CP
---------            --------
bound, free          nonvar, var
<                    @<        /* for strings and symbols */
=                    is        /* numeric computation */
=                    =:=       /* numeric test */
equal                =         /* term unification */
bitand, bitor        /\, \/
bitnot               \
bitleft, bitright    <<, >>

Also, all rules for the same predicate must be lexically
contiguous, and you can use the keywords "and", "or", and "if"
instead of the symbols ",", ";", and ":-".

6. TP implements CM's findall, rather than CP's setof and bagof.

7. TP has lots of features for handling files and I/O.
Its predicates for input (read_x), however, expect to know
the type of object, eg, readint, readreal.  TP doesn't have
CP's get for single character input. It does have readln
to read an entire line into a string.

8. TP has goodies to handle (fixed-format) databases on
disk.  Eg, dbassert/dbretract add/delete facts to/from
an external (permanent) database.

9. TP has features for program modularization.  Each module
can be compiled independently, and has its own name space,
eg, for domains and predicates.  There is also a way to set up
global domains and predicates visible to all modules.

10. TP handles character-strings as a full-fledged data-type.
Also it has functions for conversion among the primitive types.

11. TP has predicates to control graphics, windows, sound, etc.

12. The TP editor is Wordstar-like, not especially Prolog-oriented.


The opinions expressed herein have been officially approved and
sanctioned by the Supreme Court, both houses of Congress,...
no, no, only kidding, only kidding, actually I didn't even
consult with them - please don't blame anyone but me.

John Cugini <Cugini@NBS-VMS> 
Institute for Computer Sciences and Technology
National Bureau of Standards
------