next up previous
Next: Including Libraries Up: CCL The Computation and Previous: Recursion

External Functions and Parentheses

ccli provides some externally defined functions - and you can define your own (as described later). These functions are not lambda expressions and thus they use a different syntax. For example, the file $CCL_ROOT/lib/math.ccl defines some standard math functions, like cosine and sine. To use them, you write, for example,

include math.ccl
x := sin ( 0.123 ) + 1;
but not
include math.ccl
x := ( sin 0.123 ) + 1;
which will produce a type error saying something like ``you can't apply the value sin as though it were a lambda expression''. This is because sin is declared as an external function type which means that to use it, you have to put its arguments in parentheses. Another example is the print function, which takes any number of arguments of any types and prints them:
include standard.ccl

x := 5;
y := { 1, 2 };
print ( "x = ", x, " and y = ", y, "\n" );
which does about what you would expect. Note that every expression in CCL evaluates to a value of some type. Functions like print evaluate to the type unit which ccli prints as a period ( as in ``.'' ). You aren't supposed to use the result of a print call, but it has to have a some sort of value (this is like void in C). The math library and other libraries are described in Section [*].

External functions are declared with return types are argument types. Types are denoted by type expressions (which you have seen in ccli's type error reporting. Type expressions are defined by the following grammar:

typeexpr $::=$ variable $\vert$ atomic $\vert$ listexpr $\vert$ rec $\vert$ func
variable $::=$ 'a $\vert$ 'b $\vert$ ...
atomic $::=$ unit $\vert$ bool $\vert$ int $\vert$ real $\vert$ string
listexpr $::=$ typeexpr list
rec $::=$ [ var := typeexpr, ... ]
func $::=$ typeexpr -> typeexpr
The special symbol ... may appear in record expressions and as the last expression in the list of arguments to an external function. It means there may be more arguments. For example,
external [ x := int, ... ] func ( 'a list, ... ) 
  "library.so" "func";
declares the external function func. It has a record return type that has the integer field x defined and may have other fields. It takes at least one argument, a list of any type, and may take more arguments (of any type).



Subsections
next up previous
Next: Including Libraries Up: CCL The Computation and Previous: Recursion
Eric Klavins 2003-12-03