ERights Home elang / kernel 
Back to: Object Expression On to: Plumbing Expression

Methodical Object Expression


A methodical object expression is the normal kind of object expression -- it defines the object behavior in terms of dispatching on an incoming message to select a method. User-E's function-definition, class-definition, lambda, for-loop, and when-catch constructs all use methodical object expressions in their expansion. Since E is not statically typed, the dispatch is based only on the message's verb (the message-name) and arity (number of arguments). Unlike Java class's definition, the methodical object expression allows the recipient to generically handle messages that fall through the dispatch, making it easy to write delegation patterns in E.

In response to an incoming message, a methodical object (an instance of a methodical object expression) will first attempt to dispatch to a method with the same verb and arity as the message. If a match is not found among the methods explicitly coded in the eScript, the object will attempt to find a matching Miranda Method.

If we find a matching method, then the message becomes the specimen the parameter patterns are to be matched against, and the method is executed.

Else, if the eScript has a matcher, then the message becomes the specimen the matcher's pattern is to be matched against, and the matcher is executed.

BNF:
["/**" docComment
  "*/"] "def" (String | "_") auditors eScript
            
XML DTD:
See Object Expression
Java:
A methodical object expression compiles into a Java class that "extends EObject", and the E methodNodes and the matcher turn into Java methods.
Example:

# In directory some/path (relative to the source-root).

def makePoint(x,y) :any {
    def point {

        # The X value
        to getX :any {x}
        to getY :any {y}
    }
}
in Kernel-E:
def makePoint :any :=
    def "some.path.makePoint__C" {

        to run(x :any, y :any) :any {
            def point :any :=
                def "some.path.makePoint__C$point__C" {

                    # The X value
                    to getX :any {x}
                    to getY :any {y}
                }
            }
        }
    }
}
in XML:
Just the definition of point above:
<defineExpr>
    <finalPattern>
        <Noun>point</Noun>
        <Noun>any</Noun>
    </finalPattern>
    <objectExpr>
        <docComment></docComment>
        <String>some.path.makePoint__C$point__C</String>
        <auditors></auditors>
        <eScript>
            <eMethod>
                <docComment><Text>The X value</Text></docComment>
                <Verb>getX</Verb>
                <listPattern></listPattern>
                <Noun>any</Noun>
                <Noun>x</Noun>
            </eMethod>
            <eMethod>
                <docComment></docComment>
                <Verb>getY</Verb>
                <listPattern></listPattern>
                <Noun>any</Noun>
                <Noun>y</Noun>
            </eMethod>
        </eScript>
    </objectExpr>
</defineExpr>
in Java:
package some.path;

public class makePoint__C extends EObject {

    static public class point__C extends EObject {
        private final Object x;
        private final Object y;
        public point__C(Object x, Object y) {
            this.x = x;
            this.y = y;
        }

        /**
         * The X value
         */
        public Object getX() { return x; }
        public Object getY() { return y; }
    }

    public Object run(Object x, Object y) {
        final Object point = new point__C(x, y);
        return point;
    }
}

 

x
 
Unless stated otherwise, all text on this page which is either unattributed or by Mark S. Miller is hereby placed in the public domain.
ERights Home elang / kernel 
Back to: Object Expression On to: Plumbing Expression
Download    FAQ    API    Mail Archive    Donate

report bug (including invalid html)

Golden Key Campaign Blue Ribbon Campaign