comp.lang.ada
 help / color / mirror / Atom feed
* What is happening Here?Totally clueless
@ 2003-08-19 13:22 prashna
  2003-08-19 14:36 ` steveo
  2003-08-19 15:06 ` Nick Roberts
  0 siblings, 2 replies; 6+ messages in thread
From: prashna @ 2003-08-19 13:22 UTC (permalink / raw)


Hi all,
Have a look at the following program,
with text_io;
use text_io;
procedure TEST is 
type array_unconstrained is array(integer range <>) of integer;
subtype array_local is array_unconstrained(1..10);
array1 : array_local;
begin

   array1 := (others => 0);
   array1(1..2) := array_local'(others => (2));
                       ^^^^ can anybody what exactly is this?why they
are not assigning directly to 2 without doing this(Typecast????)
   put_line(Integer'image(array1(2)));
   put_line(Integer'image(array1(3)));
end TEST;

When I execute a constraint error is being raised.Can any body explain
what is going on here.
Thanks in advance,



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What is happening Here?Totally clueless
  2003-08-19 13:22 What is happening Here?Totally clueless prashna
@ 2003-08-19 14:36 ` steveo
  2003-08-19 15:06 ` Nick Roberts
  1 sibling, 0 replies; 6+ messages in thread
From: steveo @ 2003-08-19 14:36 UTC (permalink / raw)


prashna wrote:

> Hi all,
> Have a look at the following program,
> with text_io;
> use text_io;
> procedure TEST is 
> type array_unconstrained is array(integer range <>) of integer;
> subtype array_local is array_unconstrained(1..10);
> array1 : array_local;
> begin
> 
>    array1 := (others => 0);
>    array1(1..2) := array_local'(others => (2));

Warning: line 10 col 20 LRM:11.5(15), Static index lengths do not match
Constraint_Error will be raised

Warning: line 10 col 20 LRM:11.5(9), Length check will fail at run-time,
exception will be raised

>                        ^^^^ can anybody what exactly is this?why they
> are not assigning directly to 2 without doing this(Typecast????)
>    put_line(Integer'image(array1(2)));
>    put_line(Integer'image(array1(3)));
> end TEST;
> 
> When I execute a constraint error is being raised.Can any body explain
> what is going on here.
> Thanks in advance,




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What is happening Here?Totally clueless
  2003-08-19 13:22 What is happening Here?Totally clueless prashna
  2003-08-19 14:36 ` steveo
@ 2003-08-19 15:06 ` Nick Roberts
  2003-08-20  8:34   ` prashna
  1 sibling, 1 reply; 6+ messages in thread
From: Nick Roberts @ 2003-08-19 15:06 UTC (permalink / raw)


"prashna" <vashwath@rediffmail.com> wrote in message
news:d40d7104.0308190522.4b631227@posting.google.com...

>    array1 := (others => 0);
>    array1(1..2) := array_local'(others => (2));
>                        ^^^^ can anybody what exactly is this?why they
> are not assigning directly to 2 without doing this(Typecast????)

This is a qualification that it being used, as a special syntactic
construction, as an array aggregate (of a specific subtype).

> When I execute a constraint error is being raised.Can any body explain
> what is going on here.

The specific subtype in this case -- array_local -- has length 10, whereas
the destination array -- array1 -- as length 2. When assigning an array
value to an array variable (of the same type but different subtypes), the
value and variable must be of the same length.

In fact, they do not have to have the same bounds. If they are the same
length but of different bounds, the value 'slides' into the variable (the
variable's bounds do not change). An anonymous array aggregate with
indefinite length (because it contains 'others') automatically assumes the
length of the destination. Thus the following are legal declarations and
statements:

   declare
      array2: array_unconstrained(11..20);
      subtype array_small is array_unconstrained(1..5);
   begin
      array1 := array_local'(others => 0); -- slides 1..10 -> 11.20
      array1(1..2) := (others => 2); -- assumes length 2
      array2 := array1; -- slides 1..10 -> 11.20
      array2(12..16) := array_small'(others => 3); -- slides 1..5 -> 12..16
   end;

> Thanks in advance,

Hope This Helps.

--
Nick Roberts
Jabber: debater@charente.de [ICQ: 159718630]






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What is happening Here?Totally clueless
  2003-08-19 15:06 ` Nick Roberts
@ 2003-08-20  8:34   ` prashna
  2003-08-20 20:45     ` Simon Wright
  0 siblings, 1 reply; 6+ messages in thread
From: prashna @ 2003-08-20  8:34 UTC (permalink / raw)


"Nick Roberts" <nickroberts@blueyonder.co.uk> wrote in message news:<bhtedu$30am8$1@ID-25716.news.uni-berlin.de>...
> "prashna" <vashwath@rediffmail.com> wrote in message
> news:d40d7104.0308190522.4b631227@posting.google.com...
> 
> >    array1 := (others => 0);
> >    array1(1..2) := array_local'(others => (2));
> >                        ^^^^ can anybody what exactly is this?why they
> > are not assigning directly to 2 without doing this(Typecast????)
> 
> This is a qualification that it being used, as a special syntactic
> construction, as an array aggregate (of a specific subtype).
> 
> > When I execute a constraint error is being raised.Can any body explain
> > what is going on here.
> 
> The specific subtype in this case -- array_local -- has length 10, whereas
> the destination array -- array1 -- as length 2. When assigning an array
> value to an array variable (of the same type but different subtypes), the
> value and variable must be of the same length.
> 
> In fact, they do not have to have the same bounds. If they are the same
> length but of different bounds, the value 'slides' into the variable (the
> variable's bounds do not change). An anonymous array aggregate with
> indefinite length (because it contains 'others') automatically assumes the
> length of the destination. Thus the following are legal declarations and
> statements:
> 
>    declare
>       array2: array_unconstrained(11..20);
>       subtype array_small is array_unconstrained(1..5);
>    begin
>       array1 := array_local'(others => 0); -- slides 1..10 -> 11.20
>       array1(1..2) := (others => 2); -- assumes length 2
>       array2 := array1; -- slides 1..10 -> 11.20
>       array2(12..16) := array_small'(others => 3); -- slides 1..5 -> 12..16
>    end;
> 
> > Thanks in advance,
> 
> Hope This Helps.

Thanks Roberts,
 Can you tell what are the other situations where I can use this type
of aggregate?Is it that aggregates should be used only for arrays or
could it be used for any other types?Please give me link where I can
find complete, detailed description of aggregates?


Thanks,



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What is happening Here?Totally clueless
  2003-08-20  8:34   ` prashna
@ 2003-08-20 20:45     ` Simon Wright
  2003-08-20 22:00       ` chris
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Wright @ 2003-08-20 20:45 UTC (permalink / raw)


vashwath@rediffmail.com (prashna) writes:

>  Can you tell what are the other situations where I can use this
> type of aggregate?Is it that aggregates should be used only for
> arrays or could it be used for any other types?Please give me link
> where I can find complete, detailed description of aggregates?

The ARM isn't the best place to learn from -- you need a textbook or
such -- but you could start at
http://www.adaic.org/standards/95lrm/html/RM-4-3.html#I2254



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: What is happening Here?Totally clueless
  2003-08-20 20:45     ` Simon Wright
@ 2003-08-20 22:00       ` chris
  0 siblings, 0 replies; 6+ messages in thread
From: chris @ 2003-08-20 22:00 UTC (permalink / raw)


Simon Wright wrote:

> The ARM isn't the best place to learn from -- you need a textbook or
> such -- but you could start at
> http://www.adaic.org/standards/95lrm/html/RM-4-3.html#I2254

For a textbook try Adapower.  There are quite a few good free texts 
linked to there.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-08-20 22:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-19 13:22 What is happening Here?Totally clueless prashna
2003-08-19 14:36 ` steveo
2003-08-19 15:06 ` Nick Roberts
2003-08-20  8:34   ` prashna
2003-08-20 20:45     ` Simon Wright
2003-08-20 22:00       ` chris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox