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!reader02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.109.57.116.186.mobile.3.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: How to get Ada to =?windows-1252?Q?=93cross?= the =?windows-1252?Q?chasm=94=3F?= Date: Sun, 06 May 2018 18:58:36 +0200 Organization: JSA Research & Innovation Message-ID: <87o9hsu3er.fsf@jacob-sparre.dk> References: <1c73f159-eae4-4ae7-a348-03964b007197@googlegroups.com> <878t9nemrl.fsf@nightsong.com> <87h8nl50rw.fsf@nightsong.com> <87d0y97lda.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: franka.jacob-sparre.dk; posting-host="109.57.116.186.mobile.3.dk:109.57.116.186"; logging-data="21912"; mail-complaints-to="news@jacob-sparre.dk" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:fFgMTYprqTYncJ6qy+1PgnqLi0c= Xref: reader02.eternal-september.org comp.lang.ada:52043 Date: 2018-05-06T18:58:36+02:00 List-Id: Paul Rubin wrote: > Niklas Holsti writes: >> One reason is that when a function evaluates an expression that >> creates an object of a large, dynamic size (eg. an array expression) >> on the secondary stack, this object can be returned /in situ/ as the >> function's return value, without being copied. > > Ok, but that pattern is so common that allocating the space in the > primary stack before calling the function is a standard optimization > that every serious C++ compiler knows how to do. Then the function > writes the result into the primary stack and the caller can still use > it after the function returns. Could Ada not do it the same way? How would you do it with this example? with Ada.Numerics.Discrete_Random; with Ada.Strings.Fixed; with Ada.Text_IO; procedure Random_String is subtype Lengths is Integer range 10 .. 20; package Random_Lengths is new Ada.Numerics.Discrete_Random (Result_Subtype => Lengths); Generator : Random_Lengths.Generator; function Example (C : in Character) return String is use Ada.Strings.Fixed; begin return Random_Lengths.Random (Generator) * C; end Example; begin Random_Lengths.Reset (Generator); Ada.Text_IO.Put_Line (Example ('H')); Ada.Text_IO.Put_Line (Example ('e')); Ada.Text_IO.Put_Line (Example ('l')); Ada.Text_IO.Put_Line (Example ('l')); Ada.Text_IO.Put_Line (Example ('o')); end Random_String; Greetings, Jacob -- »But you have to be a bit wary of a ship that collects snowflakes.« -- Diziet Sma