Carapace

Function Declaration

A function declaration gives the following information about a function:

In Carapace script, this is done as follows:

    (function <returnType> <fnName> ( { <argSpec> }  )

    <argSpec> ::= ( <argumentName> <argumentType> )    |
                  <argumentName>                       |
                  ...                                   
An argument can be specified as follows: Each of the three argument descriptoins is illustrated below:
    (function Integer demo1 ( (x Integer) (b String) ) )

    (function Integer demo2 ( x   y ) )

    (function Integer demo3 ( (x Integer) ... ) )

Function Definition

A function definition includes all the information contained in the declaration but also defines the action of the function.

Carapace function definition is introduced with the keyword defun which stands for 'DEfine FUNction'.

The following is a very simple function which returns the square of its integer argument:

    (defun Integer square ( (x Integer) )

        (return (* x x))
    )

Note

Carapace does allow you to redefine a function - ie. replace a function definition with another one - but only if the function declarations match. That is, you can change a function's definition, but you can't change its declaration.


Contents Index Current topic: functions Related topics: objects