31.12.2013 Views

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

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.

<strong>PASCAL</strong> DATA TYPES<br />

2.3.2.2 Assigning Values to Records - To assign values to a record<br />

variable, use an assignment statement to specify a value for each<br />

field of the record. The following example shows the declaration of a<br />

record and the assignment of values to two of the fields.<br />

TYPE ROSTER - RECORD<br />

Name: PACKED ARRAY[1 •• 30J OF CHAR;<br />

Number: INTEGER;<br />

Grade:: I:::EAL..;<br />

END;<br />

VAR Student ROSTER;<br />

Testl,Test2,Test3<br />

BEGIN<br />

INTEGER;<br />

WRITEL..N ('Enter your name.');<br />

READLN (Student.Name);<br />

Stu(·.lf~'nt • G J'i:H:.h:~ : =:: (T es t 1 + T E~S t2 + T €.'S t3) / :3;<br />

If you are initializing a record with a variant clause, you must<br />

always specify a value for the tag field, even if it has no tag name.<br />

Specifying a value for the tag field, ensures that <strong>PASCAL</strong> initializes<br />

the correct variant, for example:<br />

TYPE Sex = (Male, Female);<br />

Pe rson ::;; RECORD<br />

Birthdate: RECORD<br />

Month:<br />

Day:<br />

Year:<br />

END;<br />

Ase: INTEGER;<br />

CASE s~~~< of<br />

Male:<br />

Female:<br />

1 •• 12;<br />

1 •• 31 ;<br />

INTEGER;<br />

(Bearded:BOOLEAN);<br />

(N_Children:INTEGER);<br />

END;<br />

VAR Dad: Person := «5, 15, 1921), 62, Male, TRUE);<br />

2.3.2.3 Record Type Compatibility - Two records are compatible if<br />

their types are identical or equivalent, for example:<br />

TYPE Life = RECORD<br />

:Born<br />

:Died<br />

lEND;<br />

Plantlife = Life;<br />

INTEGER;<br />

INTEGER<br />

VAR<br />

Mom, Dad : Life;<br />

Coleus : Plantlife;<br />

The record variables Mom, Dad, and Coleus are all compatible. Mom and<br />

Dad are both of type Life, which is equivalent to type Plantlife.<br />

2-19

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

Saved successfully!

Ooh no, something went wrong!