? pragma.syntax("0.9") A simple set of application objects, shown first interacting directly: ? 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 simplified Horton code from the paper, enhanced only 1) to show the Horton objects of the various parties logging some actions for responsibility-tracking purposes, and 2) to use normal E formatting conventions, since we have room for it here: # E sample def makeQuoteln := <elang:interp.makeQuoteln> def makeProxy(whoBlame, stub, reportln) { def log := makeQuoteln(reportln, `I ask ${whoBlame.getBrand()} to:`, 75) def proxy { # as P2 to getGuts() { # 04 return [stub, whoBlame] # 05 } # as P1 match [verb, [p2]] { # 02 log(`$verb/1`) def [s2, whoCarol] := p2.getGuts() # 03 def gs3 := s2.intro(whoBlame) # 06 def p3Desc := [gs3, whoCarol] # 12 stub.deliver(verb, [p3Desc]) # 13 } } return proxy } # as S2 def wrap(s3, whoBob, beCarol) { # 10 def provide(fillBox) { # 22 def fill := beCarol.unseal(fillBox) # 23 fill(s3) # 24 } return whoBob.seal(provide) # 11 } # as S1 def unwrap(gs3, whoCarol, beBob) { # 17 def provide := beBob.unseal(gs3) # 18 var result := null # 19 def fill(s3) { result := s3 # 25 } def fillBox := whoCarol.seal(fill) # 20 provide(fillBox) # 21 return result # 26 } def makeStub(beMe, whoBlame, targ, reportln) { def log := makeQuoteln(reportln, `${whoBlame.getBrand()} asks me to:`, 75) def stub { # as S2 to intro(whoBob) { # 07 log(`meet ${whoBob.getBrand()}`) def s3 := makeStub(beMe,whoBob,targ,reportln) # 08 return wrap(s3, whoBob, beMe) # 09 } # as S1 to deliver(verb, [p3Desc]) { # 14 log(`$verb/1`) def [gs3, whoCarol] := p3Desc # 15 def s3 := unwrap(gs3, whoCarol, beMe) # 16 def p3 := makeProxy(whoCarol, s3, reportln) # 27 E.call(targ, verb, [p3]) # 28 } } return stub } Code to help establish initial Horton connectivity: # 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 } The players: ? def alice := makePrincipal("Alice") # value: Alice ? def bob := makePrincipal("Bob") # value: Bob ? def carol := makePrincipal("Carol") # value: Carol Initial connectiivity: ? 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) Here is what Whos sound like: ? 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.
|