Re: Easy question about Character manipulation



Bob Duff asked:

T = 1 .. 3;
S = 1 .. 3;

This is not a matter of type equivalence,
it is a matter of automatic type conversion on assignment
(assignment compatibility), and that IS unlike Ada, of course.

What about parameter passing? I was under the impression that one can
pass something of type T to a parameter of type S, or a parameter of
type Integer, or vice versa, in Pascal. Please correct me if I'm
wrong.

It depends on whether they are value parameters or var (-iable) parameters.
Value parameters are in effect assigned their values,
and the permissive semantics of assignment compatibility apply;
var parameters must be of equivalent types, and type-equivalence in
ISO Pascal is name-equivalence.

Caveat, type B in:

type B = A;

*is* name-equivalent to A when A is a type-identifier.
In Pascal this syntax is somewhat like:

subtype B is A;

in Ada, whereas:

type B = <type_definition>

is more like:

type B is <type_definition>

in Ada.

If I'm right on that point, then I claim that we're just arguing over
terminology: saying "so-and-so are different types, but there are all
kinds of implicit conversions" amounts to roughly the same thing as
"so-and-so are the same type".

It is unfortunate that the examples being used are subranges,
because the assignment compatibility rules for subranges are
the most lax. This complexity in the semantics of Pascal
is necessary because it lacks the concept of a subtype, and
is forced to smuggle in something of the facility by rather
ad hoc special rules. So to a small extent your claim is valid.

One of the nicest things about Ada is how it cleared this mess up.

That said, there aren't "all kinds of implicit conversions",
Pascal isn't C or PL/1!

The point is, if you say this in Ada:

type T1 is range 1..10;
type T2 is range 1..10;
X : T1;
Y : T2;

is there any equivalent in Pascal that causes "X := Y" to be illegal
(or similarly for parameter passing)?

For this example, in Pascal the assignment passes type-checking,
as would passing X to a formal value parameter of type T2,
and Y to a formal value parameter of type T1;
but X could only be passed to a formal var parameter of type T1, etc.

If instead we consider:

type T1 = record i : integer; end; {or an array, file or pointer type}
T2 = record i : integer; end; {a type that is textually the same}
var X : T1;
Y : T2;

then X and Y are neither equivalent nor compatible.

--
Bill Findlay
<surname><forename> chez blueyonder.co.uk


.