ERights Home elib / capability / horton 
Back to: Eventual Horton On to: Horton with Rights Amplification

Horton with Lexical Nesting


? pragma.syntax("0.9")

Unchanged from the original:

? def c {
>     to hi(_) {
>         println("hi")
>     }
> }
# value: <c>
 
? c.hi(c)
# stdout: hi
#
 
? def b {
>     to foo(c) {
>         c.hi(c)
>     }
> }
# value: <b>
 
? b.foo(c)
# stdout: hi
#
 
? def makeA(b, c) {
>     def a {
>         to start() {
>             b.foo(c)
>         }
>     }
>     return a
> }
# value: <makeA>
 
? def directA := makeA(b, c)
# value: <a>
 
? directA.start()
# stdout: hi
#

The code from the base refactored to make use of lexical nesting:

# E sample
 
def makeQuoteln := <elang:interp.makeQuoteln>
def makeBrand := <elib:sealing.makeBrand>
 
def makePrincipal(label :String) {
    def reportln := makeQuoteln(println, `$label said:`, 77)
    def [whoMe, beMe] := makeBrand(label)

    def makeProxy(whoBlame, stub) {
        def log := makeQuoteln(reportln,
                               `I ask ${whoBlame.getBrand()} to:`,
                               75)
        def proxy {
            # as P2
            to getGuts() {
                return [stub, whoBlame]
            }
            # as P1
            match [verb, [p2]] {
                log(`$verb/1`)
                def [s2, whoCarol] := p2.getGuts()
                def gs3 := s2.intro(whoBlame)
                def p3Desc := [gs3, whoCarol]
                stub.deliver(verb, [p3Desc])
            }
        }
        return proxy
    }
     
    # as S2
    def wrap(s3, whoBob) {
        def provide(fillBox) {
            def fill := beMe.unseal(fillBox)
            fill(s3)
        }
        return whoBob.seal(provide)
    }
     
    # as S1
    def unwrap(gs3, whoCarol) {
        def provide := beMe.unseal(gs3)
        var result := null
        def fill(s3) {
            result := s3
        }
        def fillBox := whoCarol.seal(fill)
        provide(fillBox)
        return result
    }
     
    def makeStub(whoBlame, targ) {
        def log := makeQuoteln(reportln,
                               `${whoBlame.getBrand()} asks me to:`,
                               75)
        def stub {
            # as S2
            to intro(whoBob) {
                log(`meet ${whoBob.getBrand()}`)
                def s3 := makeStub(whoBob, targ)
                return wrap(s3, whoBob)
            }
            # as S1
            to deliver(verb, [p3Desc]) {
                log(`$verb/1`)
                def [gs3, whoCarol] := p3Desc
                def s3 := unwrap(gs3, whoCarol)
                def p3 := makeProxy(whoCarol, s3)
                E.call(targ, verb, [p3])
            }
        }
        return stub
    }

    def principal {
        to __printOn(out :TextWriter) {
            out.print(label)
        }
        to who() {
            return whoMe
        }
        to encodeFor(targ, whoBlame) {
            def stub := makeStub(whoBlame, targ)
            return wrap(stub, whoBlame)}
        to decodeFrom(gift, whoBlame) {
            def stub := unwrap(gift, whoBlame)
            return makeProxy(whoBlame, stub)
        }
    }
    return principal
}

Unchanged:

? def alice := makePrincipal("Alice")
# value: Alice
 
? def bob := makePrincipal("Bob")
# value: Bob
 
? def carol := makePrincipal("Carol")
# value: Carol

Unchanged:

? def gs1 := bob.encodeFor(b, alice.who())
 
? def gs2 := carol.encodeFor(c, alice.who())
 
? def p1  := alice.decodeFrom(gs1, bob.who())
? def p2  := alice.decodeFrom(gs2, carol.who())
? def a := makeA(p1, p2)

Unchanged:

? a.start()
# stdout: Alice said:
#         > I ask Bob to:
#         > > foo/1
#         Carol said:
#         > Alice asks me to:
#         > > meet Bob
#         Bob said:
#         > Alice asks me to:
#         > > foo/1
#         Bob said:
#         > I ask Carol to:
#         > > hi/1
#         Carol said:
#         > Bob asks me to:
#         > > meet Carol
#         Carol said:
#         > Bob asks me to:
#         > > hi/1
#         hi
#
 
Unless stated otherwise, all text on this page which is either unattributed or by Mark S. Miller is hereby placed in the public domain.
ERights Home elib / capability / horton 
Back to: Eventual Horton On to: Horton with Rights Amplification
Download    FAQ    API    Mail Archive    Donate

report bug (including invalid html)

Golden Key Campaign Blue Ribbon Campaign