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: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Tally Date: Thu, 16 Jan 2020 14:20:13 -0600 Organization: JSA Research & Innovation Message-ID: References: <3c6f1486-293d-4eb5-a379-279b108248d8@googlegroups.com> <4967a95b-3d79-4a5b-a30d-0f04f00ebbc4@googlegroups.com> Injection-Date: Thu, 16 Jan 2020 20:20:13 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="32059"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader01.eternal-september.org comp.lang.ada:57852 Date: 2020-01-16T14:20:13-06:00 List-Id: "Brad Moore" wrote in message news:4967a95b-3d79-4a5b-a30d-0f04f00ebbc4@googlegroups.com... ... > For that matter, you could do it all in one shot and even make the map a > constant. > > Counts : constant Count_Maps.Map > := [for I in Input'Range > when (for all J in Input'First .. I - 1 => Input (I) /= Input > (J)) > use I => > [for K in Input'Range when Input (K) = Input (I)) => 1] > 'Reduce("+", 0)]; > > Using a reduction expression to count the values. > But this is definitely quite a mouthful. So Ada 202x will allow us to catch up to C++ and many other "expressive" languages by allowing us to have "guess what this code does" contests!! :-) Compared to Jere's loop, the above is impentrable. And it's hard to guess the performance of that (I'd have to expand the aggregate into its underlying operations to figure out whether it is more or less expensive than the simple loop would be). Randy.