This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Scala and the fly likes Eliminating Parenthesis within custom internal DSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Languages » Scala
Bookmark "Eliminating Parenthesis within custom internal DSL" Watch "Eliminating Parenthesis within custom internal DSL" New topic
Author

Eliminating Parenthesis within custom internal DSL

Anthony Accioly
Greenhorn

Joined: Dec 22, 2008
Posts: 16

Hi, I'm trying to write a simple temperature conversion DSL for learning purposes.
Here is my code so far:

Temperature.scala

TemperatureScale.scala

TestTemperature.scala

I think I did pretty ok for a first attempt, but I would like to eliminate the need for the extra parenthesis if possible, so that I could use the DSL like this:

Is that possible? If so, could you guys please point the way?

Cheers
Marimuthu Madasamy
Ranch Hand

Joined: Jun 07, 2007
Posts: 72

You can avoid paranthesis using this calling notation:



This is also quiet not looking natural. We can improve this further:

Adding another method in class Temperature:



with this method in 'Temperature' class, we can call like this:




- Marimuthu Madasamy
 
GeeCON Prague 2014
 
subject: Eliminating Parenthesis within custom internal DSL