comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Question on type invariants
Date: Fri, 27 Jan 2017 10:47:49 +0100
Date: 2017-01-27T10:47:49+01:00	[thread overview]
Message-ID: <o6f505$1b9g$1@gioia.aioe.org> (raw)
In-Reply-To: 717db8c1-f6ae-4b6f-adff-d8e5c8fbfcaa@googlegroups.com

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


  reply	other threads:[~2017-01-27  9:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-25  8:38 Question on type invariants reinkor
2017-01-25 22:06 ` Randy Brukardt
2017-01-26  4:31   ` reinkor
2017-01-26  4:32   ` reinkor
2017-01-26  8:38 ` Dmitry A. Kazakov
2017-01-27  9:20   ` reinkor
2017-01-27  9:47     ` Dmitry A. Kazakov [this message]
2017-01-31  6:44       ` reinkor
2017-01-26 16:18 ` Robert Eachus
2017-01-27  5:35   ` reinkor
2017-01-27  5:47   ` reinkor
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox