Implicit Returns
In Cangjie, the last expression in a function body is automatically returned without explicitly writing the return keyword. This style makes the code more concise, especially for simple calculation functions.
The type of the function body depends on the type of the last expression: if the last item is an expression, the function body type is that expression's type; if the last item is a variable definition or function declaration, the function body type is Unit. The compiler infers the return value based on the function body type.
The code on the right shows three functions using implicit returns: multiply returns the product of two numbers, isPositive checks if a number is positive, and describe returns a description string. The last expression of each function is the return value.
Unit.Click Run to observe the output, then try modifying isPositive to check for negative numbers.