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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: Generators/coroutines in future Ada? Date: Wed, 12 Jul 2017 22:49:20 +0200 Organization: A noiseless patient Spider Message-ID: References: Reply-To: nonlegitur@notmyhomepage.de Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 12 Jul 2017 20:45:27 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="2669dad841d82ebe836345bc9272eb32"; logging-data="15767"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dbD54pvSyWXpXxPrX3t6jR2eq6+Ajx/A=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Cancel-Lock: sha1:UomODY3C4+UIexMta3Gq41n3EP8= Xref: news.eternal-september.org comp.lang.ada:47390 Date: 2017-07-12T22:49:20+02:00 List-Id: On 12.07.17 09:34, Dmitry A. Kazakov wrote: >>> I don't understand what is wrong with: >>> >>> type Stateful is limited private; >>> function Generate (X : not null access Stateful) return Things; >> >> Arguably, first, a "function" lacks query/command separation: >> >> type Stateful is limited interface; >> function Current (x : Stateful) return Thing; -- (*) >> procedure Next (x : in out Stateful); > > I don't understand this example. Why Next cannot be a part of Current? Example: > > X := Stack.Pop; It didn't say it can't be. (Without query/command separation, one needs access parameters using most versions of Ada, though, because then a function (query) is not really allowed to modify _its_ parameters, unlike a procedure (command) that has an in out parameter.) Assume that the language has special generator syntax, e.g.: while X of Stack with 0 < X and X < 10 loop This is to mean that generating a value happens once per iteration, binding the result to the X before *of* and then evaluating the condition. Stack being a Stateful, it has the prim ops needed. If X, still a generator, were instead to be repeatedly evaluated, as in while 0 < X and X < 10 loop then it isn't clear how many values will be generated if, under the hood, the expression entails evaluating 0