artefaktur
software engineer &        architecture

 
 
 
 

AAL Function Types

| Source Code | Preprocessor | Comments | Literals | Classes | Closures | Functions | Function Types |

Function Types are equaly to Function pointer and/or class methods pointer in C/C++.

Content of this chapter:

   Concept
   Implemenation
   Defintion
   Sample
     Initialize with Functions
     Initialize with object instance Methods
     Initialize with object
     Initialize with class
     Working with operators
   Implementation

 Concept

// case 1 static call
defun StaticCallable static void ();

class AClass 
{
  public void operator() {}
  public static void staticmethod() {}
  public void method() {}
  public void method2() {}
  String operator+(String other) { return other; }
}
class BClass
{
  public static void operator()() {}
}
AClass acls = new AClass();
StaticCallable staticcallable;
staticcallable = AClass.staticmethod; 
staticcallable = acls.method;
staticcallable = AClass;
staticcallable = acls;
staticcallable = new () { public void operator()() {} };
staticcallable = new () { public void foo() {} }.foo
staticcallable();

// case 2 object call
defun ObjectCall void ();
ObjectCall objcall;
objcall = acls.method;
objcall = acls.method2;
objcall = acls;
acls.objcall();

// case 3 statc operator calls
defun StaticStringAdder static String operator+(String s);

StringAdder sadder;
sadder = acls;
sadder = new () { public String operator+(String s) { return s; } };
sadder + "asdf";

 Implemenation

class AClass
{
  public String adder(String s) { return s; }
}

// case 1 static call
defun StaticStringAdder static String (String s);
// ->
interface StaticStringAdder
{
  public String operator()(String s);
}
// <- 

StaticCallable staticcallable;
// -> just an Interface reference

staticcallable = acls.method;
// -> 
class AClass_method_caller
      implements StaticStringAdder
{
  AClass target;
  AClass_method_caller(AClass t) : target(t) {}
  public String operator(String s) { return target.adder(s); }
}
staticcallable = new AClass_method_caller(acls);
// <-

 Defintion

  defun TypeName FunctionSignature

 Sample

 Initialize with Functions

defun FooCallable String (String s, int i);

String fooFunction(String s, int i) { return s.substr(i); }
FooCallable callable;

callable = fooFunction;
callable("Hello", 1);

 Initialize with object instance Methods

defun FooCallable String (String s, int i);

class AClass
{
  public AClass() {}
  public String bar(String s, int i) { return s.substr(i); }
}

FooCallable callable;
AClass acls = new AClass();
callable = acls.bar;
callable("Hello", 1);

 Initialize with object

defun FooCallable staticString (String s, int i);

class AClass
{
  public AClass() {}
  public String operator()(String s, int i) { return s.substr(i); }
}

FooCallable callable;
AClass acls = new AClass();
callable = acls;
callable("Hello", 1);

 Initialize with class

defun String FooCallable(String s, int i);

class AClass
{
  public static String operator()(String s, int i) { return s.substr(i); }
}

FooCallable callable;
callable = AClass;
callable("Hello", 1);

 Working with operators

defun StringShifter String operator<<(String str);

String operator<<(String s) { return str.length() << 1; }
StringShifter shifter = 

 Implementation

Freestanding function will translated into classes:
using acdk.lang;
String foo(String s, int i)
{
  return s.substr(i);

foo("Hallo", 1);

// will be translated into
class foo 
{
  public static String operator()(String s, int i)
  {
    return s.substr(i);
  }
}
foo.operator()("Hallo", 1);
 
Last modified 2005-05-08 22:33 by SYSTEM By Artefaktur, Ing. Bureau Kommer