? def BrandMaker := import:org.erights.e.elang.sealing.Brand # value: ? def MintMaker(name) { > def [sealer, unsealer] := BrandMaker pair(name) > > def Issuer { > to __printOn(oo) { oo print(`<$name bucks>`) } > > to vouch(item) { > unsealer unseal(item getSealed) > } > > to makeAssay(amount : (_ >= 0)) { > def Assay { > to __printOn(oo) { oo print(``) } > to getIssuer { Issuer } > to getSealed { sealer seal(Assay) } > > to transfer(src, dest) { > def srcIncr := unsealer unseal(src getIncr) > def destIncr := unsealer unseal(dest getIncr) > srcIncr(-amount) > destIncr(amount) > null > } > to compareTo(otherAssay) { > otherAssay := Issuer vouch(otherAssay) > amount compareTo(otherAssay getAmount) > } > to getAmount { amount } > } > } > > to makePurse { > def balance : (_ >= 0) := 0 > def incr(delta) { > balance += delta > } > > def Purse { > to __printOn(oo) { oo print(``) } > to getIssuer { Issuer } > to getSealed { sealer seal(Purse) } > > to getIncr { sealer seal(incr) } > to getAssay { Issuer makeAssay(balance) } > to getBalance { balance } > > to depositAll(src) { > def assay := Issuer vouch(src getAssay) > assay transfer(src, Purse) > assay > } > } > } > } > def Mint { > to __printOn(oo) { oo print(`<$name's Mint>`) } > to getIssuer { Issuer } > to getSealed { sealer seal(Mint) } > > to inflate(dest, amount) { > def destIncr := unsealer unseal(dest getIncr) > destIncr(amount) > } > } > } # value: ? def JoeMint := MintMaker("Joe") # value: ? def JoeCurrency := JoeMint getIssuer # value: ? def ThreeBucks := JoeCurrency makeAssay(3) # value: ? def PurseA := JoeCurrency makePurse # value: ? def PurseB := JoeCurrency makePurse # value: ? ThreeBucks transfer(PurseA, PurseB) # problem: ? [PurseA, PurseB] # value: [, ] ? JoeMint inflate(PurseA, 100) # value: 100 ? JoeMint inflate(PurseB, 200) # value: 200 ? [PurseA, PurseB] # value: [, ] ? ThreeBucks transfer(PurseA, PurseB) ? [PurseA, PurseB] # value: [, ] ? def TwoBucks := JoeCurrency makeAssay(2) # value: ? TwoBucks < ThreeBucks # value: true ? PurseA depositAll(PurseB) # value: ? [PurseA, PurseB] # value: [, ] ? def CambioMaker(inPurse, outPurse, in2out) { > > def Cambio { > to __printOn(oo) { > oo print(``) > } > to changeMoney(srcPurse) { > def inAssay := inPurse depositAll(srcPurse) > def outAssay := in2out(inAssay) > def destPurse := outPurse getIssuer makePurse > try { > outAssay transfer(outPurse, destPurse) > } catch ex { > inAssay transfer(inPurse, srcPurse) > throw ex > } > destPurse > } > } > } # value: ? def BettyMint := MintMaker("Betty") # value: ? def BettyBucks := BettyMint getIssuer # value: ? def BettyPurseA := BettyBucks makePurse # value: ? BettyMint inflate(BettyPurseA, 250) # value: 250 ? BettyPurseA # value: ? def in2out(inAssay) { > BettyBucks makeAssay((0.5 * inAssay getAmount) round) > } # value: ? def JBCambio := CambioMaker(PurseA, BettyPurseA, in2out) # value: into > ? [PurseA, BettyPurseA] # value: [, ] ? JoeMint inflate(PurseB, 23) # value: 23 ? def BettyPurseB := JBCambio changeMoney(PurseB) # value: ? [PurseA, BettyPurseA] # value: [, ] ?