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!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Question on type invariants Date: Fri, 27 Jan 2017 10:47:49 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <65f79e53-a468-4b77-8ee1-440c26a09371@googlegroups.com> <717db8c1-f6ae-4b6f-adff-d8e5c8fbfcaa@googlegroups.com> NNTP-Posting-Host: vZYCW951TbFitc4GdEwQJg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:33190 Date: 2017-01-27T10:47:49+01:00 List-Id: On 27/01/2017 10:20, reinkor wrote: > On Thursday, January 26, 2017 at 9:38:21 AM UTC+1, Dmitry A. Kazakov wrote: > >> What you have described looks like a lazy evaluation scheme. > > Exactly. > > But no way to express this intention in a somehow explicite way in Ada? > The point is to produce updates only when you need it (i.e. when you read > from (use) S and A has changed since last update (of S). private type Lazy_Object is ... record Self : not null access Lazy_Object := Lazy_Object'Unchecked_Access; -- Rosen's trick Cached : Value_Type; -- Last evaluated value Queue : FIFO_Type; -- Queue of update requests end record; procedure Update (Value : in out Lazy_Object; Change : Request_Type) is begin if Value.Queue.Is_Full then Value.Flush; -- Make space end if; Value.Queue.Put (Change); end Update; function Get (Value : Lazy_Object) return Value is begin if not Value.Queue.Is_Empty then Value.Self.Flush; -- Collapse the queue end if; return Value.Cached; end Get; procedure Flush (Value : in out Lazy_Object) is begin while not Value.Queue.Is_Empty loop Value.Cached := Execute (Value.Queue.Top, Value.Cached); Value.Queue.Delete; end loop; end Flush; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de