A stab at the sealer in E

Marc Stiegler marcs@skyhunter.com
Wed, 3 Nov 1999 17:03:53 -0700


Well, since it looks like this sealer might actually be useful, here is a
cleaned up version that to the best of my knowledge fully implements the
kernel BrandMaker semantics.

--marcs


? def sealSystemMaker new(name) : any {
>     def privateCurrentContent := null
>     def privateContentLoaded := false
>     def sysUnsealer  {
>         to unseal(box) : any {
>             privateCurrentContent := null
>             privateContentLoaded := false
>             box offerContent
>             def content := privateCurrentContent
>             privateCurrentContent := null
>             if (!privateContentLoaded)

>                 throw(import:java.lang.Exception new("unsealer/box
mismatch"))
>             }
>             privateContentLoaded := false
>             content
>         }
>         to printOn(out) {out print("<sysUnsealer " + name + ">")}
>     }
>     def boxMaker new(message) : any {
>         def box {
>             to offerContent {
>                 privateCurrentContent := message
>                 privateContentLoaded := true
>             }
>             to printOn(out) {out print("<sysSealed by " + name + ">")}
>         }
>     }
>     def sysSealer {
>         to seal(message) : any {boxMaker new(message)}
>         to printOn(out) {out print("<sysSealer " + name + ">")}
>     }
>     [sysSealer,sysUnsealer]
> }
# value: <sealSystemMaker>

? def [sealer1,unsealer1] := sealSystemMaker new("marcs")
# value: [<sysSealer marcs>, <sysUnsealer marcs>]

? def envelope := sealer1 seal("sealed message")
# value: <sysSealed by marcs>

? unsealer1 unseal(envelope)
# value: sealed message

? def [sealer2,unsealer2] := sealSystemMaker new("BATF")
# value: [<sysSealer BATF>, <sysUnsealer BATF>]

? unsealer2 unseal(envelope)
# problem: <Exception: unsealer/box mismatch>
#
#   <statics of org.erights.e.elang.interp.Thrower>(<Exception: unsealer/box
mismatch>)
#   <sysUnsealer BATF> unseal(<sysSealed by marcs>)
#   <interp> evalPrint(e`unsealer2 unseal(envelope)`)

?