Return Isn't Transparent

Howard Lovatt howard.lovatt at gmail.com
Sat Jul 17 06:46:46 PDT 2010


A return statement isn't transparent. This is well articulated in
Principles of Programming Languages R. D. Tennent (I don't have a copy
handy - but I think page 56 is one such place). Consider:

int m() {
  return 42; // To be wrapped in a lambda
}

Then imagine that you could create a lambda that encapsulated the long
return and you called it:

int m() {
  { -> return 42; }.();
  // Oops error - must return value from m
}

Therefore arguments about transparency are moot in any language that
has a return statement. The solution to this problem Tennent proposed
was the normal Pascal solution of a dummy local for return values that
has a default value, in a Javanese like language with no return
following Tennent the original would be:

int m() {
  m = 42;
}

The encapsulated form would be:

int m() {
  { -> m = 42; }.();
  // No error since m has a default value, 0
}

  -- Howard.


More information about the lambda-dev mailing list