Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

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.

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

Your Answer

 
discard

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.