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!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: The answer to "Can Ada replace FORTRAN for numerical computation? Date: Fri, 16 Aug 2019 22:15:17 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <3862f4a3-d3b2-4959-b6f4-08086738df2c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 16 Aug 2019 20:15:19 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="73717ac347b14a4347d1d75a60e18129"; logging-data="17015"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WSujIwyZPllPBca9g7hBbjiZPFEpUpKM=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Cancel-Lock: sha1:Fh8o8D7iX8tN7rukFzl0iD/Disc= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57071 Date: 2019-08-16T22:15:17+02:00 List-Id: On 8/16/19 9:11 PM, Norman Worth wrote: > > with ada.text_io; use ada.text_io; > procedure ar is >    type a is array(integer range <>) of integer; >    type ap is access a; >    P : ap; >    procedure da (i : in integer; j : in integer; p : out ap) is >       begin >       p := new a(1..i); >       p.all := (others => j); >       end; >    begin >    da (4, 10, P); >    put_line (P(4)'image); >    da (10, 4, P); >    put_line (P(10)'image); >    end; > > (Note that since Ada does not have a "free" verb, memory management is a bit > more complicated, requiring "uncontrolled deallocation", which is type > sensitive, to explicitly deallocate the memory for each instance of P.  But Ada > will take care of deallocation nicely when P goes out of scope at the end of the > procedure.) Like 99.9% of all problems, we can do the same thing without writing "access" or using Unchecked_Deallocation. Clearer and safer. -- Jeff Carter "Crucifixion's a doddle." Monty Python's Life of Brian 82