tag:blogger.com,1999:blog-7833979.post5748070619402014323..comments2024-03-03T04:09:10.348-06:00Comments on Jeffs Groovy Web Log: Interesting Groovy Loops DetailJeff Brownhttp://www.blogger.com/profile/13650645104670573315noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-7833979.post-7708102513995731112007-08-22T16:18:00.000-05:002007-08-22T16:18:00.000-05:00Fiore,I had a great time last night at the Atlanta...Fiore,<BR/><BR/>I had a great time last night at the Atlanta JUG. Thanks for having me.<BR/><BR/>I didn't say that there are any issues with Groovy's exception handling. What I did say is that in Groovy you are never forced to catch exceptions. For the scenarios where you do want to catch exceptions you can put your code inside of a try/catch block just like you can in Java. The difference is in Groovy you never have to do that, even if you are invoking a method that declares that it throws a checked exception.<BR/><BR/>I hope that all makes sense. I will drop you a note with my contact info.Jeff Brownhttps://www.blogger.com/profile/13650645104670573315noreply@blogger.comtag:blogger.com,1999:blog-7833979.post-69990454478883246312007-08-22T16:04:00.000-05:002007-08-22T16:04:00.000-05:00This comment has been removed by the author.Unknownhttps://www.blogger.com/profile/02579990744546188025noreply@blogger.comtag:blogger.com,1999:blog-7833979.post-663576129040595842007-08-08T13:33:00.000-05:002007-08-08T13:33:00.000-05:00The key is that your for loop is not making a lexi...The key is that your for loop is not making a lexical iterator. In Perl, I can make it work either way depending on whether I make the iterator lexical with the "my" keyword:<BR/><BR/> @numbers = (1,2,3);<BR/> %list_of_closures = ();<BR/> for my $number (@numbers) {<BR/> $list_of_closures{$number} = sub { print "number is $number\n" };<BR/> }<BR/> $list_of_closures{1}->();<BR/> $list_of_closures{2}->();<BR/> $list_of_closures{3}->();<BR/><BR/>yields<BR/><BR/> number is 1<BR/> number is 2<BR/> number is 3<BR/><BR/>But if I remove the "my" from the loop variable, like so:<BR/><BR/> for $number (@numbers) {<BR/><BR/>I get<BR/><BR/> number is <BR/> number is <BR/> number is <BR/><BR/>because the variable is now shared in the closures instead of lexical per closure, and the value is null after the map invocation is over.Anonymousnoreply@blogger.com