Defining Functions
Cangjie uses the func keyword to define functions, followed by the function name, parameter list, optional return type, and function body. The parameter list is enclosed in parentheses, with multiple parameters separated by commas; the return type is separated from the parameter list by a colon; the function body is enclosed in curly braces.
Parameters are defined as name: Type, for example a: Int64 represents a parameter named a of type Int64. Function parameters are immutable and cannot be reassigned within the function body. If a function doesn't need to return a value, you can omit the return type or explicitly annotate it as Unit.
The code on the right defines three functions: add takes two integer parameters and returns their sum, greet prints a greeting without a return value, and square calculates the square of a number. Note that when calling a function, you only need to pass values without writing parameter names.
Click Run to see the result, then try modifying the add function to calculate the sum of three numbers.