Functions

In Cangjie, the keyword func is used to indicate the start of a function definition, followed by the function name, parameter list, function return value type (optional), and function body. A function name can be any valid identifier. A parameter list is defined in a pair of parentheses (()), where a comma (,) is used to separate parameters. A colon (:) is used to separate the parameter list and function return value type (if specified). A function body is defined in a pair of braces ({}).

The following is an example of function definition:

func add(a: Int64, b: Int64): Int64 {
    return a + b
}

In the preceding example, a function named add is defined. Its parameter list consists of two parameters of the Int64 type: a and b. The return value type of the function is Int64. In the function body, a and b are added and then the result is returned.

For details, see Function Definition.