03.06.2013 Views

Turbo Prolog

Turbo Prolog

Turbo Prolog

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6 Tutorial IV: Arithmetic,<br />

Simple Input and Output,<br />

and Debugging<br />

<strong>Turbo</strong> <strong>Prolog</strong>'s arithmetic capabilities are similar to those provided in programming<br />

languages such as BASIC, C and Pascal. It includes a full range of arithmetic functions and<br />

standard predicates as diverse as the arctangent function, and a family of predicates for<br />

bitwise logical operations. These are described in the first part of this chapter, along<br />

with standard predicates for basic input and output of numeric and non-numeric values.<br />

The final part of this chapter resumes the discussion of debugging at the point where<br />

Chapter 2 left off. As programs become larger and more complex, you'll require more<br />

control over the amount of information produced by the various trace facilities, and this<br />

section tells how to gain that control.<br />

PROLOG CAN DO ARITHMETIC TOO!<br />

We have already seen some simple examples of <strong>Turbo</strong> <strong>Prolog</strong>'s arithmetic capabilities.<br />

<strong>Turbo</strong> <strong>Prolog</strong> can perform all four basic arithmetic operations (addition, subtraction,<br />

multiplication and division) between integer and real values, the type of the result being<br />

determined according to Table 6-1.<br />

Table 6-1 Arithmetic Operations<br />

Oeerand I Oeerator Oeerand 2 Result<br />

integer +, -, * integer integer<br />

real +, -, * integer real<br />

integer +, -, * real real<br />

real +, -, * real real<br />

integer or real integer or real real<br />

63

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

Saved successfully!

Ooh no, something went wrong!