[e-lang] A solution for overriding __getAllegedType

Kevin Reid kpreid at mac.com
Sat May 27 09:33:51 EDT 2006


On May 22, 2006, at 1:21, Mark S. Miller wrote:
> Kevin Reid wrote:
>> It is sometimes difficult to override __getAllegedType/0
>> appropriately because there is no way to get the original value in
>> order to compute a variation of it.
>>
>> To fix this, I have added ObjectExpr#asTypeDesc/0 to E-on-CL, and I
>> propose that the same be done for E-on-Java.
>>
>> That is, the Miranda method is this, except in the presence of  
>> matchers:
>>
>>    to __getAllegedType() :any {
>>      return meta.context().getSource().asTypeDesc()
>>    }
>
> I like it. But what should we do about matchers?

Ugly, but should work:

   to __getAllegedType() :any {
     return __mergeTypeDescs(
       (def s := meta.context().getSource()).asTypeDesc(),
       makeSwitchExpr(e`["__getAllegedType", []]`,
                      s.getScript().getMatchers() + \
                        [ematcher`match _ { __emptyTypeDesc }`]) \
         .eval(meta.getState())
   }

Equivalent, but requires duplication when expressed as E source:

   to __getAllegedType() :any {
     return __mergeTypeDescs(
       meta.context().getSource().asTypeDesc(),
       switch (["__getAllegedType", []]) {
         <repeat object's matchers here>
         match _ { __emptyTypeDesc }
       })
   }

In the 'extends' case, these are equivalent to:

    to __getAllegedType() :any {
      return __mergeTypeDescs(meta.context().getSource().asTypeDesc(),
                              super.__getAllegedType())
    }

This reminds me: I need to implement __getAllegedType inheritance in  
E-on-CL.

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




More information about the e-lang mailing list