Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.0-JSR-4
-
None
-
Windows, groovy-all-1.0-jsr-4
Description
Using GroovyShell, I accidently discovered the very cool feature that binding "out" to a PrintWriter means that:
print "foo"
Goes to Script.println, finds "out", and "foo" ends up there instead of System.out. For working in a servlet environment, this is indeed awesome.
However, with closures:
["a", "b"].each
{ println it }The println used is DefaultGroovyMethods.println, which does not do the same binding/property lookup for "out" and hence the output is "swallowed" into System.out.println, at least compared to the non-closure println.
So, DefaultGroovyMethods.println (IMHO) should do the same "out" binding lookup for a user-provided writer.
If "out" is too generic of a name to use for all of Groovy (instead of just people who use Script.println), a more verbose binding name like "groovy.lang.out" would be cool, but whatever, it just threw me for a loop that the in-closure println works differently from the the script-println.