[e-lang] Bug (0.8.35f): Scope oddities in ObjectExpr with 'extends'; Kernel-E change proposal

Kevin Reid kpreid at mac.com
Fri Mar 10 22:11:26 EST 2006


   ? e`def a {}`.staticScope()
   # value: <[] := [] =~ ["a"] + var []>

   ? e`def a extends def b {}`.staticScope()
   # syntax error: Unexpected EOF

   ? e`def a extends (def b := 1) {}`.staticScope()
   # value: <[] := ["E"] =~ ["a"] + var []>

'b' is not visible outside.

   ? e`def a implements (def b := 1) {}`.staticScope()
   # value: <[] := [] =~ ["b", "a"] + var []>

'b' is visible outside.

   ? e`def a extends (def b := 1) implements (def c := 2) {} 
`.staticScope()
   # value: <[] := ["E"] =~ ["a"] + var []>

The presence of an 'extends' clause causes the 'implements'  
expression to not be visible outside.

I think this could be fixed by a minor contortion of the ObjectExpr  
expansion:

def a := {
     def super := def b := 1
     def "$a__C" implements (def c := 2) {
         match pair__1 {
             E.callWithPair(super, pair__1)
         }
     }
}

becomes

def a := (
     def super__2 := def b := 1
     def Auditor__3 := def c := 2
     {
         def super := super__2
         def "$a__C" implements Auditor__3 {
             match pair__1 {
                 E.callWithPair(super, pair__1)
             }
         }
     }
)

However, it might be a better choice to instead specify that  
definitions in 'extends' and 'implements' are always hidden.

Besides being easier to implement 'extends' this way, doing so would  
slightly simplify analysis/auditing: the definitions visible to an  
ObjectExpr's methods would always be *outside* the ObjectExpr, and an  
ObjectExpr would never produce definitions that are visible outside.

There is precedent for this in the 'for' expression's collection  
parameter.

I haven't thought about this for very long.

Opinions?

(One of these two changes should be made, since the current situation  
is Surprisingly inconsistent.)

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




More information about the e-lang mailing list