[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

The return Statement

The return statement,

return expressionopt;

returns control to the caller of a function. If the function returns a value (that is, if its definition and declaration mention a return type), the expression must be given and it must have the same type that the function returns. If the function returns no value, the expression must generally be omitted.

However, if a function returns no value, and its last action before returning is to call another function with no value, then it can use a special form of return that names the function being called. For example:

f, g : fn (a : int);
f (a : int) {
	...
	return g(a+1);
}

is permitted. It has the same effect as:

f(a : int) {
	. . .
	g(a+1);
	return;
}

This syntax offers the compiler a cheap opportunity to recognize tail-recursion.

Running off the end of a function is equivalent to return with no expression.



[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Copyright © 1998, Lucent Technologies, Inc. All rights reserved.