I've seen BASIC and Apache Camel DSLs in Scala, and they're just fantastic. Any more examples of such DSLs?
7 Answers
You have a good source in the MEAP (Early Access) book
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"
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) )

- 1,262,500
- 529
- 4,410
- 5,250
-
Really good book. Also includes other languages so you can compare how DSLs feel in different languages. – Johannes Wachter Aug 11 '10 at 19:31
-
Excellent book. Mr. Ghosh covers Scala especially well (that's the part I read). Also, you may want to read Mr. Spiewak's educational, well-written post on Parser Combinators (critical to external Scala DSLs) - www.codecommit.com/blog/scala/the-magic-behind-parser-combinators – Kevin Meredith Jan 14 '14 at 18:47
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
}
}
}
}

- 2,779
- 23
- 17
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.

- 2,715
- 17
- 17
Two good examples are the built-in DSLs for Parser Combinators and Actors. There is a SQL wrapper called DBC (not yet ready), here you can see how it looks like: http://scala.sygneca.com/libs/dbc

- 54,104
- 13
- 100
- 195
The ScalaQL paper (PDF) describes the implementation of an interesting DSL for language integrated database queries.

- 13,699
- 10
- 57
- 70
And then there's Foursquare's Rogue http://engineering.foursquare.com/2011/01/21/rogue-a-type-safe-scala-dsl-for-querying-mongodb/