return - pannous/warp GitHub Wiki

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.

return a, b returns several values at once (multi-value): q, r = divmod(17, 5) takes them apart, a plain call gets the list [a b].

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 : Planned: the phrase form (card phrase-typed-params) and a as int parameters (card param-as-type); the other forms work.

// 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
}

The result type after the parameters is written with as, a union with or (or |) too: def f(x) as int or text { … }, f(x) as int or text := …. -> and : keep working; -> hints toward as. A union result checks each returned value, it converts nothing; a fraction reaching an int result is an error, other results convert when nothing is lost.