The Artima Developer Community
Sponsored Link

Java Buzz Forum
Tuples and Globals in Groovy

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Tuples and Globals in Groovy Posted: Jul 23, 2004 10:29 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Tuples and Globals in Groovy
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement
Tuples I am really looking forward to life with Groovy when tuples are supported. I always liked working with these guys in other languages (including Perl): my ($name, $address, @otherstuff) = parseContactsFile(); Most of the time I get around this by trying to return back real things: contact = parseContactsFile() println contact.name however for some things it can be nice... e.g. from: new File("input.txt").eachLine { line | s = line.split("\s*=\s*") println "Name: ${s[0]}" println "Value: ${s[1]}" } to: new File("input.txt").eachLine { line | (name, value) = line.split("\s*=\s*") println "Name: ${name}" println "Value: ${value}" } Globals A lot of questions from people hacking up simple Groovy scripts result from their assumptions not being met. A common one is thinking that you can create a variable at the top of a script and have it scoped so you can use it inside methods / closures somewhere down the pike. Globals are not considered to be friendly folk, but for simple scripting they can be a pleasure. I just hope that when implemented in Groovy they don't go the TCL world, so we don't see: upvar foo and global foo all over the shop!

Read: Tuples and Globals in Groovy

Topic: A good Java Open Source FAQ online Previous Topic   Next Topic Topic: Making Hay from the IM Stupid Network

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use