From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.ada Subject: Re: project euler 26 Date: Tue, 05 Sep 2023 16:18:16 +0100 Organization: A noiseless patient Spider Message-ID: <87fs3ssl6v.fsf@bsb.me.uk> References: <878r9mudvj.fsf@bsb.me.uk> <87a5u1u1yv.fsf@bsb.me.uk> <8734ztttpc.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="2907f66c348ba0da34ad87ef57ce8447"; logging-data="2141871"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kdRKWyBnwUi5kXH4dYdMn8NxLmPu4Y+s=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Cancel-Lock: sha1:WAajG6VDWcbL58WZKcDawLyKaeE= sha1:L3npjcCMANz3SkioAvwoCz5M+Ms= X-BSB-Auth: 1.89015ecd8a8ec650a205.20230905161816BST.87fs3ssl6v.fsf@bsb.me.uk Xref: news.eternal-september.org comp.lang.ada:65597 List-Id: "Dmitry A. Kazakov" writes: > On 2023-09-05 01:16, Ben Bacarisse wrote: > >> The term "abstraction" is usually taken to be more general than that so >> as to include function (or procedural) abstraction. > > These are means of software decomposition rather than abstraction (of > something). That's not how the word is usually used. Obviously I can't (and don't want to) change your mind, but algorithms can be abstracted as well as data. I was hoping someone could how me how in for the example program I gave since that's an area of Ada I am not familiar with (but I's sure it's possible). >> Ada is good at that, but the syntax is sufficiently cumbersome that I >> think it discourages people from exploiting that part of the language. >> Mind you, I am no Ada expert so maybe it's simpler to do than I think. > > If the program does not resemble electric transmission noise, some people > call the language syntax cumbersome... (:-)) That's true. But there are also constructs that are genuinely cumbersome in some languages. Anyway, to find out more, I was hoping someone would show me what it looks like in Ada -- I outlined what I wanted to do after the code I posted. >> Here's my Ada solution: >> with Ada.Text_IO; use Ada.Text_IO; >> with Ada.Containers.Ordered_Maps; use Ada.Containers; >> procedure Euler_26 is >> function Period(Divisor: Positive) return Positive is > > You cannot use a number here because the period may have leading > zeros. The function returns the decimal period of 1/Divisor. I don't believe there is a bug, but if you think you've found one, I'd like to know about it. Of course there can be leading zeros, but my algorithm ignores the digits and determines the period using the "carry" instead. >> I know it won't make this program shorter, but it would be interesting >> to know how it might be done. > > The goal of engineering is not making programs shorter, it is to make them > understandable, safer, reusable, maintainable, extensible, integrable. Yes. That's exactly why I was asking for someone who knows Ada better to show me how to write the reusable component I described. There was boiler plate code in my program that could be abstracted out into a generic function (or package?) so that any function can be maximised over some range or, better yet, any iterable type (if that's how Ada does things). Can someone here show me how? -- Ben.