-
Notifications
You must be signed in to change notification settings - Fork 0
return
pannous edited this page Nov 27, 2025
·
5 revisions
Since everything is an expression, return statements at the end of functions and closures can be omitted.
Angle allows return type polymorphism
The return type of a function is denied by the as keyword:
fib i as int:= if i<2 : 1 else fib(i-1) + fib i-2
Interestingly if the last parameter is untyped, the as keyword also weakly hints at the parameter type.
Different list separators have different bindings: While 1,2,3 binds as one expression, 1;2;3 yields the last element as return value.
A little return top can be specified either c-style in front of the function name or swift style after the function name with the optional keyword as -> or :
// preferred wasp style:
to calculate number a, number b as real:
return a + b * 2.0
// redundant acceptable syntaxes:
real calculate(int a, real b){ // C-style
return a + b * 2.0
}
fun calculate(a: int, b: real) -> real {
return a + b * 2.0
}
fun calculate(a as int, b as real) as real {
return a + b * 2.0
}
fun calculate(a: int, b: real) : real {
return a + b * 2.0
}