edu.vub.at.objects.grammar
Interface DefExternalMethod


 DefExternalMethod

The public interface to an external method definition AG element.

Example: def o.m() { body }

There are three ways to evaluate such expressions with respect to what context should be active when the method is invoked upon the object:

  1. The newly defined method is wrapped in a closure thereby fixing the lexical scope that was active at method definition/addition time, as well as the values of 'self' and 'super'. This has the advantage that within the externally added method body: a) the adding object can still access its lexical scope. b) the adding object can *not* access the scope of the object it is adding a method to. This has the disadvantage that within the externally added method body, 'self' and 'super' keep on referring to the lexically active self and super. This has the disadvantage that the newly added method cannot perform 'super sends', nor is the value of 'self' correct when the method is invoked through a child of o.
  2. The newly defined method is added as-is to the object. This has roughly the reverse effects of option 1: the adding object loses its lexical scope (error-prone and dangerous!) but the values for self and super are correct. It is as if the method was really defined in the scope of the original object.
  3. The newly defined method is wrapped in a special 'objectless' closure that captures the lexical scope of the adding object but *not* the values of 'self' and 'super'. When the added method is subsequently invoked, its lexical scope will still be that of the adding object (hence, having the benefits of option 1) while the values of 'self' and 'super' will be correct with respect to the method invocation on o (or a child of o) (hence, having the benefits of option 2.

AmbientTalk implements the third option, by means of a ClosureMethod.

Author:
tvc

Method Summary
 Expression annotationExpression()
          Example: `{ def o.m() @[Getter] { 5 } }.statements[1].annotations == `[Getter]
 Table arguments()
          Example: `{ def o.m(a, @b) { b } }.statements[1].arguments == `[a, @b]
 Begin bodyExpression()
          Example: `{ def o.m() { o.n(); 1+2+3 } }.statements[1].bodyExpression == `{o.n(); 1.+(2).+(3)}
 Symbol receiver()
          Example: `{ def o.m() { 5 } }.statements[1].receiver == `o
 Symbol selector()
          Example: `{ def o.m() { 5 } }.statements[1].selector == `m
 
Methods inherited from interface edu.vub.at.objects.AbstractGrammar
freeVariables
 
Methods inherited from interface edu.vub.at.objects.Object
super
 

Method Detail

receiver

Symbol receiver()
Example: `{ def o.m() { 5 } }.statements[1].receiver == `o

Returns:
the receiver on which the method will be defined

selector

Symbol selector()
Example: `{ def o.m() { 5 } }.statements[1].selector == `m

Returns:
the selector of the new method

arguments

Table arguments()
Example: `{ def o.m(a, @b) { b } }.statements[1].arguments == `[a, @b]

Returns:
the argument list of the new method

bodyExpression

Begin bodyExpression()
Example: `{ def o.m() { o.n(); 1+2+3 } }.statements[1].bodyExpression == `{o.n(); 1.+(2).+(3)}

Returns:
the body of the new method

annotationExpression

Expression annotationExpression()
Example: `{ def o.m() @[Getter] { 5 } }.statements[1].annotations == `[Getter]

Returns:
the annotations of the new method