This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

This is probably obvious

 
Bill Dowd
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's driving me insane! I'm pretty new to groovy and programming in general, and I'm writing a simulation model using RePast, which is based on Groovy. I created a map 'schedmap' which has other maps' names as its values:



I also created an empty map called 'schedmaps1'. What follows is troubleshooting code:




I get the following output for lines 2-5 above:



So, for lines 2 and 3, I get the map printed, which is what I want. The problem is that I can't explicitly state that I want schedmaps1, because the map I need will vary from iteration to iteration, so I need to call the correct map from schedmap, based on another object's variables (line 4) or at least allow the spcID (from another class) to dictate the correct map (a la line 5). The funny thing is, I was able to call a map from a map in other code, but I am completely unable to get it to work now. I guess the ultimate question is, in lines 4 and 5, how do I get Groovy to see 'schedmaps1' as a reference instead of as final output?

Many thanks in advance!
 
Bill Dowd
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, it looks like I got it. If I get the current object and call the maps with respect to that object (i.e., scheduler.schedmaps1) it works. That doesn't make sense, but I'll run with it!
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A map of maps to values is usually a "smell" that indicates you're trying too hard to write flexible code while sacrificing clarity of purpose. Your short description alone takes a couple of re-readings to just begin to follow. I bet if you read the code you wrote a few weeks from now, you'd be scratching your head. If not two weeks, then two months from now. The point is, the logic is convoluted and that's never a good thing.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic