Expand/Shrink

Return Statement

A return statement returns from a subroutine.
If the subroutine is a function or type then a value must also be returned. e.g.
    return
    return {50, "FRED", {}}

If you’re coming from a VisualBasic background, the last one is equivalent to a (in my opinion utterly bizzare and horrible) f = {50, "FRED", {}} statement.
(Just to be crystal clear, that might be valid syntax in VisualBasic, but it is not and there are no plans to ever make it valid in Phix.)

If you’re coming from a JavaScript background, a procedure is just like a function with no return statement (which is illegal in Phix), and if you’re coming from a C background, a procedure is just like a void function (ditto). Note that in Phix you are expected to do something with all function results, even if that is just an explicit discard along the lines of {} = somefunc(), and likewise you’ll get a compilation error should you try do so something with a procedure result, since there isn’t one.

Should there be no return statement at all in a function, you’ll get a compile-time error, but it does not have to be the last thing, for instance that could be an "end while" with a return (or two) mid-loop, and an automatic fatal (but catchable) run-time error if it somehow manages to exit that loop.

There is no explicit form of any kind of "finally" clause, however you can mimic Go’s defer handling via delete_routine() on a local variable, and that processing will be triggered either when the local variable is overwritten, or when the routine exits, as long as you haven’t stashed a reference to that data value somewhere more permanent.