03.06.2013 Views

Turbo Prolog

Turbo Prolog

Turbo Prolog

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

domains<br />

global domains<br />

database<br />

predicates<br />

global predicates<br />

goal<br />

clauses<br />

Table 11-1 Keyword Contents<br />

Zero or more domain declarations.<br />

Zero or more domain declarations.<br />

Zero or more database predicate declarations.<br />

One or more predicate declarations.<br />

Zero or more predicate declarations.<br />

Goal.<br />

Zero or more clauses (facts or rules).<br />

Usually, a program will require at least predicates and clauses sections. For large<br />

programs, a domains section will help you economize on code for the same reason<br />

that types are used in Pascal. (This is a system requirement if any of the objects in a<br />

<strong>Turbo</strong> <strong>Prolog</strong> program belong to domains of a non-standard type).<br />

For modular programming, the keywords domains and predicates can be prefixed<br />

with the word global, indicating that the subsequent domain declarations or predicate<br />

declarations affect several program modules globally (modular programming is discussed<br />

on page 152).<br />

A program can contain several domains, predicates, or clauses sections, provided<br />

the following restrictions are observed:<br />

• A program section must be prefaced with the corresponding keyword (domains,<br />

database, predicates, clauses, or goal).<br />

• Only one goal must be met during compilation.<br />

• All clauses that describe the same predicate must occur one after the other.<br />

• At most, one global predicates section may be encountered during compilation,<br />

and then only if there have been no ordinary predicates declarations earlier.<br />

• Sections containing database predicates must occur before all global and ordinary<br />

predicates declarations.<br />

Domain Declarations<br />

A domains section contains domain declarations. Four formats are used:<br />

I. name = d<br />

130<br />

This declaration declares a domain, name, which consists of elements from a standard<br />

domain type, d, which must be either integer, char, real, string, or symbol.<br />

This declaration is used for objects that are syntactically alike but are semantically<br />

different. For instance, NoOfApples and HeightlnFeet could both be represented as<br />

integers and thus be mistaken for one another. This can be avoided by declaring<br />

two different domains of integer type<br />

apples,height = integer<br />

This allows <strong>Turbo</strong> <strong>Prolog</strong> to perform domain checks to ensure that apples and<br />

heights are never inadvertently mixed.<br />

<strong>Turbo</strong> <strong>Prolog</strong> Owner's Handbook

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!