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 08:35:03 +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: 8bit Injection-Date: Wed, 12 Jul 2017 06:31:10 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="2669dad841d82ebe836345bc9272eb32"; logging-data="19585"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18v0o1PNVgFg6bvyI8u6NwevMItFtzarNA=" 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:YY/u2jpGROt3vxs99ynVGJIFKkg= Xref: news.eternal-september.org comp.lang.ada:47370 Date: 2017-07-12T08:35:03+02:00 List-Id: On 11.07.17 22:25, Dmitry A. Kazakov wrote: > On 2017-07-11 21:22, J-P. Rosen wrote: >> Le 11/07/2017 à 20:36, Victor Porton a écrit : >>> This state also includes the point of execution (like "We are in the second >>> loop in its second operator.") >>> >>>> This can easily be achieved with a function within a package, where the >>>> package serves to protect and hide the function's state. >>> Ada currently has no support to save such (point of execution) states. >> It has. Make your generator a task, and have an accept when the data is >> ready, which can be nested as deep as you want in any construct. >> >> A task is a perfect abstraction for a thread of control that maintains >> its own execution state! > > Except that no control is required. > > 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); If, then, so-called "elegance" of side-effect generating functions (or of some equivalent operator) is required for reasons of socially acceptable expression, to make generators visible, the above pattern should be integrated with some special iteration scheme like Ada now has in "for ... of ... loop". Not surprisingly, I think, Icon's generators are available to use in while-loops that look perfectly ordinary. If Ada requires generators to be more explicit: G : Stateful := Strings.Find (Subject => "...", Pattern => "___"); while X of G with condition (X) loop -- not Ada ... end loop; "while ... of ... with" then requires G to be a Stateful. Presence of special syntax is, as previously, HOL. __ (*) Only if the type is special this can make any sense. E.g., calling Current twice should raise an exception. That's unlikely to happen if there is special Ada syntax tied to Stateful, hence "while ... of ... with".