ERights Home elib / capability / horton 
Back to: Testing Simplified Horton On to: Alice Frames Bob

Handling N Arguments


? pragma.syntax("0.9")

This version of Horton is like the original, but modified to handle app-level messages with any number of arguments. This allows us to simplify our example app code by getting rid of the useless argument of the hi() message.

? def c {
>     to hi() {                 # CHANGED!
>         println("hi")
>     }
> }
# value: <c>
 
? c.hi()                        # CHANGED!
# stdout: hi
#
 
? def b {
>     to foo(c) {
>         c.hi()                # CHANGED!
>     }
> }
# 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
#

This is just like the original, except that we've placed the parts that are per-argument within for-loops.

# E sample
 
def makeQuoteln := <elang:interp.makeQuoteln>
 
def makeProxy(whoBlame, stub, reportln) {
    def log := makeQuoteln(reportln,
                           `I ask ${whoBlame.getBrand()} to:`,
                           75)
    def proxy {
        to getGuts() {
            return [stub, whoBlame]
        }
        match [verb, args] {                    # CHANGED!
            log(`$verb/${args.size()}`)
            var pDescs := []
            for p2 in args {
                def [s2, whoCarol] := p2.getGuts()
                def gs3 := s2.intro(whoBlame)
                def p3Desc := [gs3, whoCarol]
                pDescs with= p3Desc
            }
            stub.deliver(verb, pDescs)
        }
    }
    return proxy
}
 
def wrap(s3, whoBob, beCarol) {
    def provide(fillBox) {
        def fill := beCarol.unseal(fillBox)
        fill(s3)
    }
    return whoBob.seal(provide)
}
 
def unwrap(gs3, whoCarol, beBob) {
    def provide := beBob.unseal(gs3)
    var result := null
    def fill(s3) {
        result := s3
    }
    def fillBox := whoCarol.seal(fill)
    provide(fillBox)
    return result
}
 
def makeStub(beMe, whoBlame, targ, reportln) {
    def log := makeQuoteln(reportln,
                           `${whoBlame.getBrand()} asks me to:`,
                           75)
    def stub {
        to intro(whoBob) {
            log(`meet ${whoBob.getBrand()}`)
            def s3 := makeStub(beMe,whoBob,targ,reportln)
            return wrap(s3, whoBob, beMe)
        }
        to deliver(verb, pDescs) {             # CHANGED!
            log(`$verb/${pDescs.size()}`)
            var args := []
            for p3Desc in pDescs {
                def [gs3, whoCarol] := p3Desc
                def s3 := unwrap(gs3, whoCarol, beMe)
                def p3 := makeProxy(whoCarol, s3, reportln)
                args with= p3
            }
            E.call(targ, verb, args)
        }
    }
    return stub
}

Unchanged from the original:

# E sample
 
def makeBrand := <elib:sealing.makeBrand>
 
def makePrincipal(label :String) {
    def reportln := makeQuoteln(println, `$label said:`, 77)
    def [whoMe, beMe] := makeBrand(label)
    def principal {
        to __printOn(out :TextWriter) {
            out.print(label)
        }
        to who() {
            return whoMe
        }
        to encodeFor(targ, whoBlame) {
            def stub := makeStub(beMe, whoBlame, targ, reportln)
            return wrap(stub, whoBlame, beMe)}
        to decodeFrom(gift, whoBlame) {
            def stub := unwrap(gift, whoBlame, beMe)
            return makeProxy(whoBlame, stub, reportln)
        }
    }
    return principal
}

Unchanged from the original:

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

Unchanged from the original:

? 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)

The output shown here is simpler than the original's because Bob is no longer uselessly introducing Carol to herself.

? a.start()                          # CHANGED!
# 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/0
#         Carol said:
#         > Bob asks me to:
#         > > hi/0
#         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: Testing Simplified Horton On to: Alice Frames Bob
Download    FAQ    API    Mail Archive    Donate

report bug (including invalid html)

Golden Key Campaign Blue Ribbon Campaign