[Grace-core] Return

Michael Homer mwh at ecs.vuw.ac.nz
Sun May 29 19:07:46 PDT 2011


Hi,
I understand that "return" inside a block should return from the
enclosing method. What if that scope has already terminated? Is it a
runtime error, or does it set the return value of Block.apply, pass
silently, or something else?

Two code examples:
  method foo() {
    return { return 1 }
  }
and:
  const a := object {
    var block
    method bar(block) {
      self.block := block
    }
    method baz() {
      self.block.apply()
    }
  }
  method foo() {
    a.bar { return 1 }
    ...
    a.baz()
    ...
  }
  foo()
  ...
  a.baz()

The second example contains both possible action at a distance and
double-return.

More generally, returning inside a block will cause execution of the
scope invoking apply() to terminate as well, along with any others in
between. Will the scopes be able to detect that?

I'm having difficulty finding an implementation strategy for this that
covers all the possibilities. What I'm considering at the moment is
roughly parallel to transforming "return x" to "block.hasReturned :=
true ; raise Returns(v)" and writing the appropriate search in the
exception handler, but that will still fall apart if the scope is
either dead already or somehow not an ancestor of the apply() call. I
have also considered providing the block with the creating scope's
notional continuation, but that seems to have even more perverse
results in these cases. I would like to be able to declare them to be
an error or have undefined behaviour and just fail in the most
convenient fashion.
-Michael


More information about the Grace-core mailing list