This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eliminating Parenthesis within custom internal DSL

 
Anthony Accioly
Greenhorn
Posts: 18
IntelliJ IDE Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
Java Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic