Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer
Would be -1 if I had sufficient rep, see further in the link from OP:… – sq33G Dec 18 '11 at 8:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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