[e-lang] Prize and Milestone as mutable state idioms
Kevin Reid
kpreid at mac.com
Wed Jul 2 19:20:50 CDT 2008
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/>
More information about the e-lang
mailing list