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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!goblin1!goblin.stu.neva.ru!news.astraweb.com!border6.a.newsrouter.astraweb.com!cyclone03.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!post02.fr7!fx13.fr7.POSTED!not-for-mail Message-ID: From: Mike H Reply-To: Mike Hopkins Newsgroups: comp.lang.ada Subject: Re: Pretty printing the pretty print. References: <20140104121332.22310cd2@vostro> MIME-Version: 1.0 Content-Type: text/plain;charset=us-ascii User-Agent: Turnpike/6.07-M () NNTP-Posting-Host: 83.104.138.185 X-Complaints-To: abuse@demon.net X-Trace: 1389026755 83.104.138.185 (Mon, 06 Jan 2014 16:45:55 UTC) NNTP-Posting-Date: Mon, 06 Jan 2014 16:45:55 UTC Date: Mon, 6 Jan 2014 16:37:48 +0000 X-Received-Body-CRC: 3806746329 X-Received-Bytes: 2669 Xref: news.eternal-september.org comp.lang.ada:18132 Date: 2014-01-06T16:37:48+00:00 List-Id: In message <20140104121332.22310cd2@vostro>, Oliver Kleinke writes >Do you by chance remember the task? As far as I remember the original "specification" was a requirement to split an array at an arbitrary point and re-join the two parts (first and last) in the reverse order (last then first). Spotting that what was actually required was a circular shift changed the game somewhat. By some odd coincidence, before Christmas I stumbled across the following (see below). It seems to fit the bill. I also seem to remember that turning it into a generic was not as sweet and clean as I expected. function Shift_right_circular (A : in Array_type; Places : in Natural) return Array_type is P : Natural := Places rem A'LENGTH; -- Array will be split into two slices (I1 .. I2) & (I3 .. I4) and -- re-made as (I3 .. I4) & (I1 .. I2). The values of I2 and I3 are -- derived from their position numbers, P2 and P3. P1 : Natural := Index_type'POS (A'FIRST); -- position number of I1 P2 : Natural := P1 + P - 1; -- position number of I2 P3 : Natural := P1 + P; -- position number of I3 -- -- I1 is A'FIRST I2 : Index_type := Index_type'VAL(P2); I3 : Index_type := Index_type'VAL(P3); -- I4 is A'LAST begin if Places = 0 then -- no shifting to be done return A; else return A (I3 .. A'LAST) & A (A'FIRST .. I2); end if; end Shift_right_circular; -- Mike Swim? Naturally at Severn Vale