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=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin.stu.neva.ru!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: need help learning Ada for a modula-2 programmer Date: Thu, 30 Jan 2014 10:05:32 +0100 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: <87bnytet5v.fsf@adaheads.sparre-andersen.dk> References: <878utybjxc.fsf@adaheads.sparre-andersen.dk> NNTP-Posting-Host: 109.59.34.168.mobile.3.dk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: loke.gir.dk 1391072732 29256 109.59.34.168 (30 Jan 2014 09:05:32 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 30 Jan 2014 09:05:32 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:tU3r4N5YtgDq8jqkCYXeYV7hGY4= X-Original-Bytes: 2386 Xref: number.nntp.dca.giganews.com comp.lang.ada:184602 Date: 2014-01-30T10:05:32+01:00 List-Id: Jeffrey Carter wrote: > On 01/29/2014 01:41 PM, Jacob Sparre Andersen wrote: >> >> Generalising the array index beyond type Integer takes up ten lines >> in my first take on the task. (Recursion _might_ make it shorter.) > > Mine is the same number of lines whether the index is numeric or > not. 2 of the lines differ to handle non-numeric indices. I'm curious how you're doing it. My implementation has one declaration of a constant (to manage shifts further than one array length) and one return statement (split over two lines to make it more readable). The non-numeric index version has another ten lines to make the mathematical operations used in the return statement work on a non-numeric index. Hmmm... I think I may have figured it out... Yes. Converting back and forth between type Index and integers in-line makes the return statement somewhat less readable. :-( Using Ada 2012 I can do it with exactly the requested dozen lines (two of which are blank to improve readability ;-). Greetings, Jacob PS: I'm waiting for the OP to post his/her solution before I'm going to post mine. Please hurry up. -- Never attribute to malice what can adequately be explained by incompetence.