Re: Prize and Milestone as mutable state idioms

Kevin Reid <[email protected]>
Newsgroups gmane.comp.lang.e.general
Message-ID <[email protected]>
On Jun 30, 2008, at 19:20, Tyler Close wrote:

> For example, I was using a boolean variable to keep track of  
> whether or not the most recent JSON value had been fully and  
> successfully output. The update pattern here was that the variable  
> started out false and then transitioned to forever being true.  
> Verifying that this property was correctly implemented previously  
> required examining the full file for mentions of the boolean  
> variable to check that it was only ever assigned the value true.  
> The Milestone class encapsulates a boolean variable that can only  
> be updated in this way.

 From the problem description, I immediately think of a promise.

That is (in E),

def [p, r] := Ref.promise()
def yet() { return Ref.isResolved(p) }
def now() { r.resolve(null) }

In this case it's probably silly, as the update pattern is almost  
equally short (and, I would expect, shorter in ref-send/Joe-E),

def [yet, now] := {
   var v := false
   [v.get,
    def now() { v := true }]
}

but promises can be a nice primitive for more complex happens-once  
cases (and require no external encapsulation).

-- 
Kevin Reid                            <http://homepage.mac.com/kpreid/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.