[E-Lang] Confusion
Marc Stiegler
marcs@skyhunter.com
Fri, 17 Aug 2001 10:06:12 -0700
Steve,
I have a useless but exact answer to your question on reusing a Vow
variable, and I have a useful but more complicated answer for answering the
slightly different but more important in practice question. I have listed
them below.
--marcs
--------Useless but exact:---------
Using the latest E syntax, in which "def" is for constants that only get
assigned a value once, but "var" is reassignable,
var xVow := server <- getX()
when (xVow) -> done(x) {
#do something with x
xVow := server <- getX()
when (xVow) -> done2(x2) {
#do something else
} catch prob2{}
} catch prob {}
----------Complex answer to related practical problem------
The practical problem is, you want to keep polling a remote site, and every
time a value changes, you want to do something about it. In traditional
immediate-call based programming, you would use a loop:
var x := server getX()
var oldX := x
while (true) {
x := server getX()
if (x != oldX) {
#do something
oldX := x
}
}
Using when-catch on remote objects, you cannot do it in a loop. The
following extremely naive passage of code creates a denial of service attack
upon itself:
var x := server <- getX()
var oldX := x
while (true) {
x := server <- getX()
when (x) -> done(newX) {
if (x != oldX) {
#do something
oldX := x
x := server <- getX()
}
} catch prob {}
}
The when clause is posted as a separate game turn to occur when this game
turn is over, the while clause never ends, which means the current game
turn never ends, and your system will continue to churn out getX() send
messages until some resource is exhausted.
To achieve the goal, you must step sideways into the funky world of Lisp and
Scheme programmers, who always use recursion instead of while loops anyway:
var x := server <- getX()
var oldX := x
def serviceServer() {
when (x) -> done (newX) {
if (x != oldX) {
#do something
oldX := x
}
x := server <- getX()
serviceServer()
}
}
serviceServer
You can find more information about this and related matters at the end of
the Distributed Computing chapter of Walnut. Start at the subsection
"Recursion for send sequencing" part of the section
http://www.skyhunter.com/marcs/ewalnut.html#SEC37
The sendValve and promiseOnlyMoreRecent patterns are also closely tied to
this general domain of working with promises, they follow shortly in the
same section
Does this help?
--marcs
----- Original Message -----
From: "steve jenson" <stevej@sieve.net>
To: "Terry Stanley" <tstanley@cocoon.com>
Cc: <e-lang@mail.eros-os.org>
Sent: Friday, August 17, 2001 1:18 AM
Subject: Re: [E-Lang] Confusion
> Quoting Terry Stanley (tstanley@cocoon.com):
>
> > At 03:02 AM 8/16/01 -0700, steve jenson wrote:
> >
> > >def counter {
> > > to incr() :any { println("counter was incr()'d"); x += 1}
> > > to getX() :any { x }
> > >}
> >
> > Realize that this println message is displayed in the server window, not
the
> > client window.
>
> Yes, that was the intended behavior. On a side note; At 2am, lack of a
> return() statement caught me when I noticed:
>
> ? xVow
> #value: 'counter was incr()\'d'
>
> being spit out by my elmer session. Yes, I had placed the println()
> behind x's increment. It was so natural for me to not think of a non
> return()'d statement's value being passed back that I blindly broke
> my own system, in a possibly subtle fashion if I had decided to munge
> with x yet again. Of course, this is only a big deal to those who don't
> properly test their systems, and to those who aren't familiar with an
> expression-oriented language.
>
> > >PS, the cap is still online (at least until I wake up tomorrow morning
and
> > >turn it off) if anybody out there wants to play with it. Not that it's
> > >super-exciting.
> >
> > This was a good idea. We were able to connect to your server in Elmer.
The
> > following updoc script is our transcript , including an example of
when-catch.
> >
> > ? introducer onTheAir()
> > # value: ["3DES_SDH_M2", "3DES_SDH_M"]
> >
> > ? def sr :=
<cap://66.92.8.63:3575/08TsZ_LYmtuAVuLZoDFX8j3Re7O6/QfWE9V6br29mY9eS27aFI9fy
Gam>
> > # value: <SturdyRef>
> >
> > ? def farCounter := sr liveRef()
> > # value: <Eventual ref>
> >
> > ? def xVow := farCounter <- getX()
> > # value: <Eventual ref>
> >
> > ? xVow
> > # value: 8
> >
> > ? def xNextVow := farCounter <- incr()
> > # value: <Eventual ref>
> >
> > ? xNextVow
> > # value: 9
> >
> > ? when (xNextVow) -> done(xNext) {
> > > println(`next: $xNext`)
> > > } catch prob {
> > > println(`oops: $prob`)
> > > }
> > # value: <Eventual ref>
> >
> > ?
> > next: 9
> > ?
> >
> > Let us know if you have any more questions.
>
> Hmm, I hadn't thought about using promises yet (although I should have
> been, thank you). I suppose my question, which I worded very poorly and
> assumed it would be obvious (which is foolish), is that I wish to know
> how to easily determine the value of my newly incremented x without
> having to def my variable mutltiple times. So, I want to know how to
> do this:
>
> ? def xNextVow := farCounter <- incr()
> #value: <Eventual ref>
>
> ? xNextVow
> # value: 9
>
> without having to keep explicitly creating xNextVow again. I think
> the following is ugly:
>
> #------
> ? def xNextvow := farCounter <-incr()
> # value: <Eventual ref>
>
> ? xNextVow
> # value: 10
>
> # now I wish to increment x again, but I have to def the object over again
> # for some reason
>
> ? def xNextVow := farCounter <- incr()
> # value: <Eventual ref>
>
> ? xNextVow
> # value: 11
> #-------
>
> How can I call incr() on the farCounter in such a way that I only have
> to def xNextVow once? Is this possible in E?
>
> In my mental E interpreter, I run code that looks like this:
>
> #-----
> ? def xNextVow := farCounter
> # value <Eventual ref>
>
> ? xNextVow <- incr()
> # value <Eventual erf>
>
> ? xNextVow <- getX()
> # value: 12
> #-----
>
>
> I think if there's one thing that my Mental E Interpreter(tm) teaches me
> is that I still think too locally.
>
>
>
> -steve
>
> ]
> --
> steve jenson <stevej@sieve.net> http://sieve.net/
> PGP fingerprint: 79D0 4836 11E4 A43A 0179 FC97 3AE2 008E 1E57 6138
> _______________________________________________
> e-lang mailing list
> e-lang@mail.eros-os.org
> http://www.eros-os.org/mailman/listinfo/e-lang
>