• No categories


Whiley supports first-class functions similar those found in languages like [[Python (programming language)|Python]] and [[JavaScript]], and to function pointers in C.  The following illustrates the syntax:

int f1(int x):
    return x + 1

int f2(int x):
    return x * 2

int g(int(int) func):
    return func(1234)

void ::main(System.Console console):

Here, we see that function g() accepts a parameter func of function type.  To generate values of function type, we use the “address-of” operator &.  The parameter func can be invoked inside g() as though it were a normal function.