Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interesting DSLs, Implemented in Scala? [closed]

Tags:

scala

dsl

I've seen BASIC and Apache Camel DSLs in Scala, and they're just fantastic. Any more examples of such DSLs?

like image 500
George Avatar asked Jul 06 '10 13:07

George


3 Answers

You have a good source in the MEAP (Early Access) book
Gosh Cover
DSL in action from Debasish Ghosh (blog: "Ruminations of a programmer)

Testing frameworks like scalatest are classic examples of DSL:

  test("pop is invoked on an empty stack") {     
    val emptyStack = new Stack[String]
    evaluating { emptyStack.pop() } should produce [NoSuchElementException]
    emptyStack should be ('empty)
  }

There are many others DSL-based frameworks out there:

  • specs: "Behaviour-Driven-Design framework"

  • internal DSLs

  • Squeryl: "A Scala ORM and DSL for talking with Databases with minimum verbosity and maximum type safety"

    def songCountByArtistId: Query[GroupWithMeasures[Long,Long]] =
      from(artists, songs)((a,s) =>
        where(a.id === s.artistId)
        groupBy(a.id)
        compute(count)
      )
like image 119
VonC Avatar answered Nov 24 '22 19:11

VonC


lift-json provides a DSL to generate JSON. For example the following DSL:

("person" ->
  ("name" -> "Joe") ~
  ("age" -> 35) ~
  ("spouse" ->
    ("person" ->
      ("name" -> "Marilyn") ~
      ("age" -> 33)
    )
  )
)

creates the following JSON:

{ 
  "person": {
    "name": "Joe",
    "age": 35,
    "spouse": {
      "person": {
        "name": "Marilyn",
        "age": 33
      }
    }
  }
}
like image 34
Joni Avatar answered Nov 24 '22 19:11

Joni


ScalaModules is a DSL for working with OSGi.

Another one is available with Apache Camel a platform for enterprise integration.

Scala-Query and Squeryl also provide DSLs for querying databases among other things.

ScalaTest is also an awesome example of what is possible.

like image 31
Johannes Wachter Avatar answered Nov 24 '22 21:11

Johannes Wachter