My favorites | Sign in
ect
Project Home Downloads Wiki Issues Source
Search
for
Methods  
Semantics of method-calls, best practices, and possible future modifications.
Featured
Updated Jul 19, 2009 by fehe...@gmail.com

In ECT 0.2

General method calls

Syntax

{Object}:methodname(Arg1, Arg2, ..., ArgN)

Result

The exact result is only determined at run-time:

  1. Those function are located, which are defined as method in the class or one of the superclasses of Object, and has name/arity: methodname/N+1.
  2. From these, the most lately-defined is selected. (The one that overrides all the other ones.
  3. This function is called with Object added before the first argument: XYZ:methodname(Object, Arg1, Arg2, ..., ArgN)

Superclass method calls

Syntax

Only usable in modules that define a class, and this class has a superclass.

{{Object}}:methodname(Arg1, Arg2, ..., ArgN)

Result

Similar to super.methodname(Arg1, Arg2, ..., ArgN) in Java. The call is executed like in the previous case, but with the bold italic text omitted from step 1.

Return value conventions

This is not so nice, but I the following things seem to be a good practice:

When a method does not affect fields of the object

Return any value you like. For example:

clever_method(This = #example{field1 = A}, B) ->
   A+B.

When a method does affect fields of the object

Return the updates version of the object:

clever_method(This = #example{field1 = A}, B) ->
   This#example{field1 = A+B}.

When a method does affect fields of the object, and returns a value

Return a tuple with the updates version of the object and with the calculated value:

genious_method(This = #example{field1 = A}, B) ->
   {This#example{field1 = A+B}, A*B}.

In ECT 0.3+ - possible future modifications

General method calls

Object:methodname(Arg1, Arg2, ..., ArgN)

Issues:

  • The Erlang compiler knows this kind of call, but puts Object at the end of argument list.
    • Modification of ECT language is required (to put This pointers as the last argument in methods) OR
    • Modification of Erlang compiler is required OR
    • Hacking in ECT transformation is required, to simulate for the user that the last parameter is actually the first. (This is easy to do, but it might cause confusion when debugging.)

Superclass method calls

...


Sign in to add a comment
Powered by Google Project Hosting