# Copyright 2005-2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ Tests of built-in slots. ? def := ; null Final ? def makeFinalSlot :DeepFrozen := # value: ? makeFinalSlot.__optUncall() # value: [, "get", ["org.erights.e.elib.slot.makeFinalSlot"]] ? def FinalSlot := makeFinalSlot.asType() # value: FinalSlot ? (makeFinalSlot(safeScope) :FinalSlot) == &safeScope # value: true ? 1 :FinalSlot # problem: the int 1 doesn't coerce to a FinalSlot ? FinalSlot[int] # value: FinalSlot[int] ? FinalSlot[int] == E.call(E, "call", FinalSlot[int].__optUncall()) # value: true ? makeFinalSlot(3) :FinalSlot[int] # value: <& 3> ? makeFinalSlot("") :FinalSlot[int] # problem: the String "" doesn't coerce to an int ? pragma.enable("call-pattern") ? def FinalSlot[x] := FinalSlot[int]; x # value: int ? def FinalSlot[x] := 1; x # problem: not a FinalSlot[_] guard ? def makeFinalSlot(x) := makeFinalSlot(1); x # value: 1 ? def makeFinalSlot(x) := def _ { to __conformTo(_) { return makeFinalSlot(1) }}; x # value: 1 ? def makeFinalSlot(x) := def _ extends makeFinalSlot(1) {} # problem: the "__main$_" <__main$_> doesn't coerce to a FinalSlot XXX test coercion by FinalSlot guard and guard call pattern makeVarSlot ? def makeVarSlot :DeepFrozen := # value: ? makeVarSlot.__optUncall() # value: [, "get", ["org.erights.e.elib.slot.makeVarSlot"]] ? def VarSlot := makeVarSlot.asType() # value: VarSlot ? def v :VarSlot := makeVarSlot(1) # value: ? v.isFinal() # value: false ? v.put(2) ? v.get() # value: 2 ? v # value: XXX readOnly/0 Guarded ? def makeGuardedSlot :DeepFrozen := # value: ? makeGuardedSlot.__optUncall() # value: [, "get", ["org.erights.e.elib.slot.makeGuardedSlot"]] ? def GuardedSlot := makeGuardedSlot.asType() # value: GuardedSlot ? makeGuardedSlot(int, null, def _(p) :any { print(p); return [p] }) # stdout: problem: the Null null doesn't coerce to an int # problem: optEjector <__main$_> returned: [problem: the Null null doesn't coerce to an int] ? def v :GuardedSlot := makeGuardedSlot(int, 1, null) # value: ? v.isFinal() # value: false ? v.put(2) ? v.get() # value: 2 ? v.put(null) # problem: the Null null doesn't coerce to an int ? v # value: Coerced A CoercedSlot is like a FinalSlot in that it has a single unchanging value; it is like a VarSlot in that it has a guard and guarantees that the value passed the guard. ? def makeCoercedSlot :DeepFrozen := # value: ? def CoercedSlot := makeCoercedSlot.asType() # value: CoercedSlot ? 1 :CoercedSlot # problem: the int 1 doesn't coerce to a CoercedSlot No parameterization yet ? CoercedSlot[int] # problem: no such method: org.cubik.cle.native.e.elib.cl-type-guard#get/1 ? makeCoercedSlot(int, null, def _(p) :any { print(p); return [p] }) # stdout: problem: the Null null doesn't coerce to an int # problem: optEjector <__main$_> returned: [problem: the Null null doesn't coerce to an int] ? def v :CoercedSlot := makeCoercedSlot(int, 1, null) # value: <& 1 :int> ? v.isFinal() # value: true ? v.getGuard() # value: int ? v == makeCoercedSlot(int, 1, null) # value: true ? (def r1 := makeCoercedSlot(any, r1, null)) == (def r2 := makeCoercedSlot(any, r2, null)) # value: true ? v.__optUncall() # value: [, "attempt", [int, 1]] ? makeCoercedSlot.attempt(int, 1) # value: <& 1 :int> ? makeCoercedSlot.attempt(float64, 1) # value: <& 1.0 :float64> ? [makeCoercedSlot.attempt(String, 1) =~ failed :FinalSlot, failed] # value: [true, <& 1>]