Chapter 5. Data-Items

Perhaps it is not a good idea just to go through the different kind of data-items without illustrating these with real examples as we do below?
We may briefly mention Boolean, Char and Float and return to these in later sections.
Also compound values and arrays may be moved to later sections.
References must be explained!

Objects may have attributes in the form of data-items that may represent properties characterizing the object. In the previous Chapters we have seen examples of data-items such as licenseNumber, kerbWeight and payLoad. In this Chapter, we further explain the kind of data-items that may be possible attributes of an object.

Basic values

Data-items such as licenseNumber, kerbWeight and payLoad holds integer values, which are examples of basic values. The data-item is therefore of type integer. In the following sections we describe other common basic values.

In Java these types are called primitive types. Shall we use the same terminology?

In some languages like TypeScript basic types also includes structure, arrays, etc.
Hmmm - seems that they have changed their terminology now they talk about everyday types and primitive types.
We should probably follow Wikipedia , which also talks about primitive types.

A data-item may be of type Boolean and such a data-item may have the value True or False.

A data-item of type Boolean may be declared as follows:

B1: var Boolean B2: val True

The data-item B2 is a constant having the value True during the whole program execution. The data-item B1 is a variable that may hold the values True or False at different point during the program execution. In the next example, B1 is assigned the value False

B1 := False

Character values

A data-item of type Char may hold a value representing a character from the UniCode character set. A character may be a letter, a digit, a special character, a blank/space or an end-of-line character. A character literal is typically written within single quotes like:

'a', 'b', 'Q', L' -- examples of letters '0', 7' -- examples of digits '.', ':'. '+', -- examples of special characters ' ' -- the blank character

An end-of-line character has no graphical form and is thus denoted as '\n'. The character '\' is a so-called escape character the implies that the next character defines a special character. The following are examples of characters defined using the escape character

'\n' -- end-of-line '\t' -- tab '\'' -- the quote character ' ...

The following example shows the declaration of data-items of type char and assigment statements:

ch1: val '!' ch2: var Char ch2 := 'Q'

The data-item ch1 is a a constant holding the exclamation mark character '!'. The data-item ch2 is a variable of type char. It may hold different character values during the program execution. Execution of the assignment statement ch2 := 'Q' has the effect that ch2 holds the character 'Q'.

Floating point values

A data-item of type Float holds a real value like 3.14. A computer can only represent a subset of the real values and the real values that can be represented are called floating point values.

Perhaps a side box saying more about reals and floating point values?

The following example shows the declaration of data-items of type float and assignment statements:

X: val 3.14 Y: var Float Y := 1.41421

References

A data-item may be a reference to another object. In the following example, we have extended class Car with a data-item owner that is a reference to a Person object:

class Car: licenseNumber: val 0 kerbWeight: val 0 payLoad: var integer owner: ref Person setOwner(ow: ref Person): pwner := ow addPassenger: payload := payLoad + 80

Class Person may be defined in the following way:

class Person: name: ref String age: var number

Compound values

Explain compound values

Easy to explain qBeta values, but we shall probably say that compound values are only supported to a limited extent in mainstream languages.

Arrays

Explain arrays.

Values, objects and references

Explain the difference between values, objects and and references. Include illustrations.

State

Explain the notion of state.