next up previous
Next: Implementation Structure Up: The Language Previous: Genetic Algorithm Definition

Function Definition

The syntax of the DARWIN functions is designed so that resemble standard C function definition syntax. As a major difference, DARWIN supports only void, float, int and char C types. As a result, the DARWIN language is capable of expressing any calculation, but on a limited set of basic types. An example DARWIN function is presented below :

function RectangleInit(TRectangle gene)
{
  gene.x = random(0, 255);
  gene.y = random(0, 255);
  gene.width  = random(0, 255-x);
  gene.height = random(0, 255-y);
}
The above function, as implied from its name, is the gene initializer moderator for a gene of type TRectangle defined in the previous subsection. Assuming that there exists a library function called ``random'' which returns a random integer in the range specified by its two parameters, then this function randomly fills up all the members of a gene. An evident syntactic difference between C and DARWIN functions is that DARWIN functions are preceded by the keyword function.

The DARWIN language recognizes most of the C statements. Currently, DARWIN supports the C if conditional statement and the while and for looping constructs.

The DARWIN syntax allows most of the C expression syntax. Since DARWIN does not support pointer types, there is no vital need for type casting and pointer arithmetics together with support for referencing and de-referencing.

As a result, the DARWIN function definition syntax can be viewed as a subset of standard C. DARWIN is equipped with a sufficient set of operations that are present in any iterative language and the DARWIN expressions are powerful enough to express any calculation.

The DARWIN functions follow closely the C language semantics. The only major difference is in the function parameter passing semantics. In DARWIN all the parameter passing is done by reference. This is a direct consequence of not supporting pointer types. All the other DARWIN constructs obey their C equivalent semantics.


next up previous
Next: Implementation Structure Up: The Language Previous: Genetic Algorithm Definition
Gokturk Ucoluk 2003-09-15