* Change in behavior of & operator between 83 and 9x?
@ 1994-10-05 16:04 Paul Graham
0 siblings, 0 replies; 2+ messages in thread
From: Paul Graham @ 1994-10-05 16:04 UTC (permalink / raw)
If an array type A has component type B which is itself an array type, is it
possible to concatenate two arrays of type B to produce an array of type A?
For instance:
package foo is
type my_string is array(1 .. 3) of character;
type my_string_vector is array(positive range <>) of my_string;
c1 : my_string_vector := "abc" & "def";
end;
In this example, I want the value of the concanenation to be equivalent to
("abc", "def") -- my_string_vector(1 to 2)
But it can also be interpreted as
"abcdef" -- string(1 to 6), my_string(1 to 6), ???
which does not match the type of c1.
The 83 RM (4.5.3(4)) states "if both operands are one-dimensional arrays,
the result of the concatenation is a one-dimensional array whose length is
the sum of the lengths of the operands ...". Clearly the concatenation of
two strings is always a string, and never an array of strings.
But the 9x RM defines the result of a concatenation in terms of its result
type. In the above example the result type is known to be my_string_vector.
Thus the "&" should be "&"(x, y : my_string) return my_string_vector.
Is my understanding wrong, or is this an incompatibility between the 83 and
9x versions of Ada?
Paul
--
Paul Graham graham@compass-da.com Compass Design Automation, Inc.
(speaking only for myself) "Cekoslovakyalilastiramadiklarimizdanmissiniz."
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Change in behavior of & operator between 83 and 9x?
[not found] <19941006.090935.490@vnet.ibm.com>
@ 1994-10-13 1:43 ` Keith Thompson @pulsar
0 siblings, 0 replies; 2+ messages in thread
From: Keith Thompson @pulsar @ 1994-10-13 1:43 UTC (permalink / raw)
In <19941006.090935.490@vnet.ibm.com> karthurs@vnet.ibm.com (Keith Arthurs) writes:
> In article <GRAHAM.94Oct5120449@canopus.clsi.COM>,
> on 05 Oct 1994 16:04:49 GMT,
> Paul Graham <graham@clsi.COM> writes:
> >
> >If an array type A has component type B which is itself an array type, is it
> >possible to concatenate two arrays of type B to produce an array of type A?
> >For instance:
> >
> > package foo is
> > type my_string is array(1 .. 3) of character;
> > type my_string_vector is array(positive range <>) of my_string;
> > c1 : my_string_vector := "abc" & "def";
>
> In Ada 83 'my_string_vector' would need to be constrained (1 .. 2)
> (lrm 3.6.1:6)
>
> > end;
> >
> >In this example, I want the value of the concanenation to be equivalent to
> >
> > ("abc", "def") -- my_string_vector(1 to 2)
>
> This is a correct interpretation of 'my_string_vector', it is a two
> dimensional array
A quibble: it's not a two dimensional array, it's a one dimensional array
whose component type is also a one dimensional array. (Unlike Pascal,
for example, Ada does distinguish between these two cases.)
For example:
type Array_1d is array(1 .. 3) of Integer;
type Array_1d_1d is array(1 .. 3) of Array_1d;
--
-- Array_1d_1d is a 1-d array of 1-d arrays
--
type Array_2d is array(1 .. 3, 1 .. 3) of Integer;
--
-- Array_2d is a 2-d array
--
Just to add to the confusion, both types use the same syntax for aggregates:
Obj_1d_1d: Array_1d_1d
:= (1 => (1, 2, 3),
2 => (4, 5, 6),
3 => (7, 8, 9));
Obj_2d: Array_2d
:= (1 => (1, 2, 3),
2 => (4, 5, 6),
3 => (7, 8, 9));
--
Keith Thompson (The_Other_Keith) kst@alsys.com
TeleSoft^H^H^H^H^H^H^H^H Alsys, Inc.
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
/user/kst/.signature: I/O error (core dumped)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1994-10-13 1:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-10-05 16:04 Change in behavior of & operator between 83 and 9x? Paul Graham
[not found] <19941006.090935.490@vnet.ibm.com>
1994-10-13 1:43 ` Keith Thompson @pulsar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox