comp.lang.ada
 help / color / mirror / Atom feed
From: sampson@cod.NOSC.MIL (Charles H. Sampson)
Subject: Re: constraint error question for language lawyers
Date: 10 Nov 90 01:08:14 GMT	[thread overview]
Message-ID: <2455@cod.NOSC.MIL> (raw)
In-Reply-To: 1802@software.software.org

In article <1802@software.software.org> blakemor@software.org (Alex Blakemore) writes:
>OK, language lawyers of the world.
>This one has stumped everyone I've asked locally,  including several 
>people who have worked with Ada since there were compilers for it.
>
>Vax Ada 2.1 and two versions of Verdix (5.x and 6.0.3) all behave in the same
>(unreasonable) manner - so there must be some obscure rule at work here.
>Does anyone
>  a. know what that rule might be ?
>  b. profess to have a reasonable explanation for its existence.
>
>  [Using the following declarations, the second assignment raises a
>   constraint error.]
>  
>  type short is range 0 .. 10;
>  type data is array (short range <>) of character;
>  type var_text (len : short := 0) is
>    record
>      text : data (1 .. len);
>    end record;
>  dummy : var_text; -- unconstrained
>
>  dummy := (len => 0, text => "");
>  dummy := (len  => dummy.len + 1,
>            text => dummy.text & 'a');

     O.K., I'll give it a try, but don't expect a dazzling flood of light
on the subject, because there are still some puzzling things around.  To
begin with, I'll obscure the issue even more.  Alsys Ada 4.3 also fails.
However, both Alsys and VAX Ada 2.0 succeed (no constraint error) when
the component text is declared as string(1 .. len)!

     The root problem is the one pointed out by collard@software.org
(David Collard) in article <1809@software.software.org>: "Sliding" is
not allowed when assigning to an array component of an aggregate; the
indexes of the value and the indexes of the component must be equal.
Therefore the indexes of dummy.text & 'a' must be (1 .. 1).  If you
look at section 4.5.3 of the LRM to see what those indexes are, you see
that this case, a null string concatenated with a single component value,
has been omitted.  As Collard pointed out, using

              text => dummy.text & (1 => 'a')

works.  This is because the second component is now an array whose indexes
are (1 .. 1), not a single component value, and 4.5.3 says that the
indexes of the concatenated value are (1 .. 1), as required.  Notice that
this form will always work, because if the left operand of a concatenation
is not null, the indexes of the right operand don't matter.

     After some moderately tricky programming, I was able to verify that
Alsys and VAX Ada both consider the lower bound of

                       dummy.text & 'a'

to be 0.  When the type of text is changed to string(1 .. len), the lower
bound becomes 1.  Why?  I don't know.  Could be an accident.  Could be a
concious decision by the implementors.

     Another question: Why was this case left out of 4.5.3?  Was it an
oversight or was it a concious decision?  It could have been a concious
decision, because any value chosen in this case would be arbitrary, but
if it is I've never heard anybody discuss it.  Then, of course, there is
the underlying question to this whole flail: Why isn't sliding allowed
when assigning a value to a component of an aggregrate (and the other
cases when sliding is not allowed)?

     Now I sit back and wait for the real Ada lawyers to point out that
this problem is clearly and explicitly covered on some page of the LRM
that I would never think to look at.

                              Charlie Sampson

  parent reply	other threads:[~1990-11-10  1:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-11-08 17:18 constraint error question for language lawyers Alex Blakemore
1990-11-09 14:12 ` David Collard
1990-11-10  1:08 ` Charles H. Sampson [this message]
1990-11-17 10:12 ` Jean Pierre Rosen
  -- strict thread matches above, loose matches on Subject: below --
1990-11-09 14:36 "Norman H. Cohen"
1990-11-30 16:02 ` James THIELE
replies disabled

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