O'Reilly logo

Groovy for Domain-specific Languages - Second Edition by Fergal Dearle

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding built-in methods

However simple our DSL might now look, the need to preface our method calls with GeeTwitter is one final piece of boilerplate code that it would be nice to remove. In some of the previous examples we have used a static import to do this, but it is still not very intuitive to a non Java/Groovy programmer why we are doing this. Since we are evaluating the DSL script ourselves, rather than allowing Groovy to do it, we still have some scope to do this.

It would certainly be nicer to be able to write:

eachFollower { 
  sendMessage it, "Thanks for taking the time to follow me!"
}

This assumes that the eachFollower method is built in to the DSL, rather than the more verbose:

GeeTwitter.eachFollower { GeeTwitter.sendMessage (it, "Thanks ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required