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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6f580d48a3449630 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.71.MISMATCH!xlned.com!feeder3.xlned.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Constraints in extended return Date: Tue, 22 Mar 2011 08:28:59 +0000 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx03.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="4325"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/amXBoTT+k0Z1lWJIUAwpLgnqwfquKUJk=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin) Cancel-Lock: sha1:iBLGTfftGc/HI1TihhBCzMc5gOI= sha1:XYmpdTRRV2RukBBR/xaeaLWG+Io= Xref: g2news2.google.com comp.lang.ada:19328 Date: 2011-03-22T08:28:59+00:00 List-Id: "Randy Brukardt" writes: > "Simon Wright" wrote in message > news:m2d3lngzmi.fsf@pushface.org... >> This code transposes a matrix: >> >> function Transpose (M : Complex_Matrix) return Complex_Matrix >> is >> begin >> return Result : Complex_Matrix (M'Range (2), M'Range (1)) do >> for J in M'Range (1) loop >> for K in M'Range (2) loop >> Result (K, J) := M (J, K); >> end loop; >> end loop; >> end return; >> end Transpose; >> >> This is all very well for providing a value where no constraint is >> otherwise imposed, for example as an actual in a subprogram call, but >> what about the case where there is a prior constraint? >> >> Input : Complex_Matrix (1 .. 2, 11 .. 12); >> Output : Complex_Matrix (1 .. 2, 1 .. 2); >> begin >> Input := (...); >> Output := Transpose (Input); >> >> Is there any way for the extended return to determine the constraints of >> the 'target'? I suspect not, but the language in RM6.5 is deep. > > Why do we care what the bounds are? Assignments "slide" bounds; all that is > required is that the lengths of the array dimensions match. This is true > whether this is an extended return or a regular return (at least it had > better be; it would be awful to have the semantics change depending on the > form of the return statement). > > For instance, > Output := Input; > is both a legal assignment and does not raise Constraint_Error (both > dimensions have length 2). > > Now, if you get the lengths wrong, you have a problem, but not the actual > bounds. Thanks for that (which I can confirm works just fine with GNAT). Unable to see the wood for the trees ...