From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!attcan!uunet!lll-winken!elroy.jpl.nasa.gov!usc!ucsd!nosc!cod!sampson From: sampson@cod.NOSC.MIL (Charles H. Sampson) Newsgroups: comp.lang.ada Subject: Re: constraint error question for language lawyers Message-ID: <2455@cod.NOSC.MIL> Date: 10 Nov 90 01:08:14 GMT References: <1802@software.software.org> Reply-To: sampson@cod.nosc.mil.UUCP (Charles H. Sampson) Organization: Computer Sciences Corporation List-Id: 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