aspose file tools*
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
 
 
subject: Eliminating Parenthesis within custom internal DSL