[e-lang] def object extends root[self] {

Kevin Reid kpreid at attglobal.net
Sat Mar 11 12:09:04 EST 2006


Something I thought up a while ago and just added to E-on-CL.

--- root.emaker ---

# Copyright 2006 Kevin Reid, under the terms of the MIT X license
# found at http://www.opensource.org/licenses/mit- 
license.html ................

pragma.enable("easy-return")
pragma.disable("explicit-result-guard")

def EventuallyDeepFrozen := DeepFrozen."eventually"()

def root implements DeepFrozen {
/** Produces an object to serve as the root of 'extends' chains. It  
responds 'no such method' to everything, but refers to 'self' in the  
error instead of the  parent-most object. */
to get(self) {
   return def root1 implements EventuallyDeepFrozen {

     method __optSealedDispatch(brand) :any {
       if (brand == EventuallyDeepFrozen.getPeekBrand()) {
         EventuallyDeepFrozen.getPeekSealer().seal(meta.getState())
       }
     }

     to __printOn(out :TextWriter) {
       out.write("<delegation root for ")
       out.quote(self)
       out.write(">")
     }

     match [verb, args] {
       # XXX typed exception
       throw(`the ${self.__getAllegedType().getFQName()} ${E.toQuote 
(self)} does not understand $verb/${args.size()} $args`)
     }
   }
}}



--- extend.updoc ---

# Copyright 2006 Kevin Reid, under the terms of the MIT X license
# found at http://www.opensource.org/licenses/mit- 
license.html ................

'root' is used to produce more helpful no-such-method errors in  
objects using delegation. Without it, the error report uses the FQN  
of the last object in the 'extends' chain, making it more difficult  
to understand the error (especially in the presence of tail-call  
elimination).

   ? def root := <import:org.cubik.cle.root>
   # value: <root>

   ? def self; def r := root[self]; def a1 extends r {}
   # value: <a1>

   ? bind self := def a2 extends a1 {}
   # value: <a2>

   ? r
   # value: <delegation root for <a2>>

   XXX wording of message to be revised
   ? a2.aardvarks(9)
   # problem: the __main$a2__C <a2> does not understand aardvarks/1 [9]



-- 
Kevin Reid                            <http://homepage.mac.com/kpreid/>




More information about the e-lang mailing list