Opa is a functional language. One of its features is that functions are regular values, which means a function may be passed as a parameter or returned as a result. As such, they follow the same naming rules as any other value.
function f(x,y){ // function f with the two parameters x and y x + y + 1 } function int f(x,y){ // explicitly indicates the return type x + y + 1 }
You may notice that there is no return inside the body of a function. That's because Opa uses last expression return, which means the last expression of a function is the return value. For example:
function max(x,y){ if(x >= y) x else y }
If x
is greater than or equal to y
, then x
is the last expression and x
will be returned; if y
is greater than x
, then y
is the last expression and y
will be returned.