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!reader01.eternal-september.org!reader02.eternal-september.org!aioe.org!siG8trSPtxwtkBCOZpBn8A.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada needs some modernization Date: Tue, 31 May 2022 21:55:05 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <75d90749-242f-42b8-ba0b-299f7ac693e0n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="20500"; posting-host="siG8trSPtxwtkBCOZpBn8A.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:63892 List-Id: On 2022-05-31 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... Not same. In the former A may be computed twice. > What amendment can we suggest to the Ada syntax so the if expression be better written when used in an if statement? I newer felt it necessary. To me much more aggravating is code that combines test/allocator with renaming, i.e. if P /= null then declare X : T renames P.all; begin ... end; end if; ------------ if X in T'Class then declare XX : T'Class renames T'Class (X); begin ... end; end if; ----------- P : access T'Class := new S; X : S renames S (P.all); If one could come up with some syntax for if-then-declare and new-then-declare that would cover a lot of cases. > I know other languages support this and it often looks like A ? B : C or something similar. That's certainly not Ada-like IMO, but I can't think of something better. These same languages often also have a null check operator A ?? B (where A and B are access types of the the same Type) such that if A is not null then A is returned otherwise B is returned. So useful and helpful! Not in a strongly typed language IMO. [...] > Maybe something like: > > for i in arr'Range loop > if arr(i) = match then > --do something A > exit; > end if; > then > --do something else B > end loop; I usually use a nested function, e.g. search with a fallback: function Get_Me_Something return Element is begin for I in arr'Range loop if Arr (I) = match then return Arr (I); end if; end loop; return Defaul; end Get_Me_Something -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de