The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

gomez (3) [Avatar] Offline
p. 54, Chap 3

(code,level,lat,lng) = url.toURL().text.split(',')

I am familiar with this notation from Perl days, so I marked it in an early draft. Today, I had an excuse to use it for a little project and got nothing but syntax errors. Groovy hates the paren notation for lists. I got past it with a less elegant looking code.

Just curious, but does Groovy no longer compile this code?
kenneth.kousen (57) [Avatar] Offline
Re: List operation syntax question
The "multi-return" syntax was added in Groovy 1.6, and should still work. I'll check it out, but the only change I would probably make is to add "def" in front of the parentheses.

What error did you get?
gomez (3) [Avatar] Offline
Re: List operation syntax question
(date, open, high, low, close, vol) = line.toString().split(',')

---it complains at the first comma in the line above.

expecting ')', found ',' @ line 13, column 17.
gomez (3) [Avatar] Offline
Re: List operation syntax question
OK. Upon looking more closely at your comments, the tip about Groovy 1.6 and the "multi-return" syntax was useful.

Lots of distributions such as MyEclipse have the Groovy Plugin already installed. However, the typical level is just below what you mentioned. I installed the Groovy 1.8, and the syntax issues go away.

I also note that you have the def in from of the parens on page 63. You might want to make the earlier reference consistent.

Very subtle issue going on here. I fell into the trap of thinking it was like Perl with lists---which uses parens instead of brackets for list notation---when, in reality, the notation as you use it here revolves around the def/return.

Thanks for your help.
kenneth.kousen (57) [Avatar] Offline
Re: List operation syntax question
Now that I recall, that was a 1.8 addition. Ironically, since Google stopped supporting the csv output in their geocoder, I don't use it very often any more.

The def keyword in front is required if you're not in a script. In a script, undefined variables are accessible from the caller through the binding. I cover all that in the integration chapter.

Obviously I need to add more about it at that point, though.

Thanks for the info about the Perl conventions. I'm afraid that to me, Perl is still write-only code. smilie