Here's an interesting discussion of Tennent's Correspondence Principle, and a brief description from Neal Gafter:

The principle dictates that an expression or statement, when wrapped in a closure and then immediately invoked, ought to have the same meaning as it did before being wrapped in a closure. Any change in semantics when wrapping code in a closure is likely a flaw in the language.

Does the Groovy language follow this principle?

1 Answer 1


Not quite, but almost. All the variables accessible in the outer scope are accessible in the closure, including 'this' and class data members. However, a return statement returns from the closure, not from the enclosing function. I'm not even sure that is a violation of TCP; I don't know of any C-style language where return in a closure returns from the enclosing scope. I have had no surprises using Groovy closures.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.