[E-Lang] vouching version 3
Marc Stiegler
marcs@skyhunter.com
Tue, 27 Feb 2001 19:50:28 -0700
In my earlier email about vouching tools, I pointed out 2 design
characteristics that were independently variable, and said I'd do a third
version that combined the characteristics in a fashion I thought better than
the 2 examples I presented. I have cleaned up the code a bit (eschewing the
1-method shortcut for inspector vouch).
It will have to be modified to run with the new var/def distinction when the
var/def distinction is married to an E that has comm, but it is listed
below.
--marcs
#vouching system #3 based on synchronous private comm
#returns a private notary that offers a public inspector
#throws problem if the object being vouched is not vouchable
def notaryMaker new :any {
def unvouchedException(obj) {throw("Object not vouchable: " + obj)}
def vouchableObject := null
def inspector {
to vouch(obj) :any {
vouchableObject := null
try {
obj startVouch
if (vouchableObject == null) {
unvouchedException(obj)
} else {vouchableObject}
vouchableObject
} catch err {unvouchedException(obj)}
}
}
def notary {
to startVouch(obj) { vouchableObject := obj}
to getInspector :any {inspector}
}
}
#maker3 that offers vouching
def barMakerMaker new :any {
def notary := notaryMaker new
def barMaker {
to new :any {
def bar {
to run {println("I am a vouchable bar")}
to startVouch {notary startVouch(bar)}
}
}
to getInspector :any {notary getInspector}
}
}
#testing the third vouching system
def myBarMaker := barMakerMaker new
def myBar := myBarMaker new
myBarMaker getInspector vouch(myBar) run
def fake3 {}
try {
myBarMaker getInspector vouch(fake3) run
println("notary3 vouched falsely")
} catch err {println("notary3 spotted fake3")}