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=-2.4 required=3.0 tests=BAYES_00,NICE_REPLY_A, REPLYTO_WITHOUT_TO_CC,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: Ada needs some modernization Date: Thu, 2 Jun 2022 07:56:53 +0200 Organization: A noiseless patient Spider Message-ID: References: <75d90749-242f-42b8-ba0b-299f7ac693e0n@googlegroups.com> Reply-To: nonlegitur@notmyhomepage.de MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 2 Jun 2022 05:56:54 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="7758ebea916138817b411546f346cd56"; logging-data="14190"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/AcaxYKYuTlSaZgTmzGacZ9T+V7+16etE=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Cancel-Lock: sha1:1WqvVr+dDQ75Um9pYtEkkzGxir4= In-Reply-To: <75d90749-242f-42b8-ba0b-299f7ac693e0n@googlegroups.com> Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:63906 List-Id: On 31.05.22 19:54, Matt Borchers wrote: > Throughout my career, I often find myself writing code similar to: > > if (A and B) or else (not A and C) then... > > and I always wished there was a better and clearer way to write this in Ada. Then along came if expressions. But, if expressions don't help that much with readablity although it is arguably simpler: > > if (if A then B else C) then... > > What amendment can we suggest to the Ada syntax so the if expression be better written when used in an if statement? I would try to fix the problem at where it is caused: ad hoc, unnamed logical predicates! Syntactic sugar won't make these go away. All those Boolean expressions have meaning, I suppose. The meanings could be given a name. There would be facts, about A, B and C, that make your statement true, some not. What does it state? Compare this assembly of variables ((A and B) or else ((not A) and C))) to a lambda expression or to a state machine's. Similar? It is the lowest level of computation using a high level language. > Again, I often find myself writing a loop to search for something and then performing one or another action depending on the success of the search. This almost always requires some externally defined variable, like: > > --assuming arr'First is not Integer'First > found := arr'First - 1; > for i in arr'Range loop > if arr(i) = match then > found := i; > exit; > end if; > end loop; Again, there is an algorithm, typically Find_the_First, that will return an index (or cursor). I'd use the return value in a conditional.