? def BrandMaker := import:org.erights.e.elang.sealing.Brand # value: ? def NaN := 0.0/0.0 # value: NaN ? def ExcluderMaker(name) { > def [sealer, unsealer] := BrandMaker pair(name) > > def Issuer { > to __printOn(oo) { oo print(``) } > > to vouch(item) { > unsealer unseal(item getSealed) > } > > to makeAssay(myPrecious) { > def AssayPrivate { > to getPrecious { myPrecious } > } > def Assay { > to __printOn(oo) { > oo print(""+``) > } > to getIssuer { Issuer } > to getSealed { sealer seal(Assay) } > to getPrivate { sealer seal(AssayPrivate) } > > to transfer(src, dest) { > def srcPrivate := unsealer unseal(src getPrivate) > def destPrivate := unsealer unseal(dest getPrivate) > if (destPrivate getPrecious != null && > destPrivate getPrecious != myPrecious) { > > throw("destination not empty") > } > if (srcPrivate getPrecious != myPrecious) { > throw("precious not in src") > } > srcPrivate setPrecious(null) > destPrivate setPrecious(myPrecious) > null > } > to compareTo(otherAssay) { > def otherPrivate := unsealer unseal(otherAssay) > def otherPrecious := otherPrivate getPrecious > if (myPrecious == otherPrecious) { > true > } else if (myPrecious == null) { > -1.0 > } else if (otherPrecious == null) { > 1.0 > } else { > NaN > } > } > } > } > to makePurse { > def myPrecious := null > def PursePrivate { > to getPrecious { myPrecious } > to setPrecious(newPrecious) { myPrecious := newPrecious } > } > def Purse { > to __printOn(oo) { > oo print(""+``) > } > to getIssuer { Issuer } > to getSealed { sealer seal(Purse) } > to getPrivate { sealer seal(PursePrivate) } > > to getAssay { Issuer makeAssay(myPrecious) } > to depositFrom(src) { > def assay := Issuer vouch(src getAssay) > assay transfer(src, Purse) > assay > } > > match [verb, args] { > E call(myPrecious, verb, args) > } > } > } > } > def Excluder { > to __printOn(oo) { oo print(`<$name's Excluder>`) } > to getIssuer { Issuer } > to getSealed { sealer seal(Excluder) } > > to makeExcludable(precious) { > def purse := Issuer makePurse > def pursePrivate := unsealer unseal(purse getPrivate) > pursePrivate setPrecious(precious) > purse > } > } > } # value: ? def JoeExcluder := ExcluderMaker("Joe") # value: ? def JoeIssuer := JoeExcluder getIssuer # value: ? def xPrintlnA := JoeExcluder makeExcludable(println) # value: > ? def xPrintlnB := JoeIssuer makePurse # value: ? println("hello fundamental instrument") hello fundamental instrument # value: hello fundamental instrument ? xPrintlnA("hello derivative A") hello derivative A # value: hello derivative A ? xPrintlnB("hello derivative B") # problem: ? xPrintlnB depositFrom(xPrintlnA) # value: > ? println("hello fundamental instrument") hello fundamental instrument # value: hello fundamental instrument ? xPrintlnA("hello derivative A") # problem: ? xPrintlnB("hello derivative B") hello derivative B # value: hello derivative B ? println # value: ? xPrintlnA # value: ? xPrintlnB # value: >