代码之家  ›  专栏  ›  技术社区  ›  George

有趣的dsl,用Scala实现[[关闭]

  •  15
  • George  · 技术社区  · 14 年前

    我见过 BASIC Apache Camel Scala中的DSL非常棒。还有这样的DSL的例子吗?

    7 回复  |  直到 14 年前
        1
  •  19
  •   VonC    11 年前

    你在MEAP(早期访问)书中有一个很好的来源
    Gosh Cover
    DSL in action 来自Debasish Ghosh(博客: Ruminations of a programmer )

    scalatest 以下是DSL的经典示例:

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

    还有许多其他基于DSL的框架:

    • specs :“行为驱动设计框架”

    • internal DSLs

    • Squeryl :“一个Scala ORM和DSL,用于以最小的冗余度和最大的类型安全性与数据库交谈”

        def songCountByArtistId: Query[GroupWithMeasures[Long,Long]] =
          from(artists, songs)((a,s) =>
            where(a.id === s.artistId)
            groupBy(a.id)
            compute(count)
          )
    
        2
  •  6
  •   Joni    14 年前

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

    创建以下JSON:

    { 
      "person": {
        "name": "Joe",
        "age": 35,
        "spouse": {
          "person": {
            "name": "Marilyn",
            "age": 33
          }
        }
      }
    }
    
        3
  •  2
  •   Johannes Wachter    14 年前

    ScalaModules 是一个DSL的工作 OSGi .

    另一个有 Apache Camel 企业集成平台。

    Scala-Query Squeryl 此外,还提供用于查询数据库的dsl。

    ScalaTest

        4
  •  1
  •   Landei    14 年前

    两个很好的例子是解析器组合器和参与者的内置dsl。有一个名为DBC(尚未就绪)的SQL包装器,您可以在这里看到它的样子: http://scala.sygneca.com/libs/dbc

        5
  •  1
  •   namin    14 年前

    XML in Scala 这是另一个例子。

        6
  •  0
  •   Binil Thomas    14 年前