小编pet*_*rim的帖子

如何在Scala中创建内部DSL?

我一直在寻找关于领域特定语言的几本书和资源.我想我想在Scala中构建一个内部DSL.

def instrument = new FXInstrument {

     provider = "EuroBase"
     instrumentOrders = List(
         new FXOrder {
             baseCcy = "GBP"
             termCcy = "EUR"
             legs = List( 
                 new FXLeg {
                    amountPrice = 100000.0
                    spotPrice = 1.56
                    requirements = List(
                        new FXRequirement {
                           baseCcy="GBP" termCcy="EUR" 
                           settlement="Banker Rain"
                        }
                    )
                 },
                 new FXLeg {
                    amountPrice = 200000.0
                    spotPrice = 1.50
                    requirements = List(
                        new FXRequirement {
                           baseCcy="GBP" termCcy="EUR" 
                           settlement="Banker Sunny"
                        }
                    )
                 }
             )

         }                  
}
Run Code Online (Sandbox Code Playgroud)

以下断言有效:

 instrument.orders(0).baseCcy should equal ("GBP")
 instrument.orders(0).termCcy should equal …
Run Code Online (Sandbox Code Playgroud)

dns dsl specifications scala

12
推荐指数
2
解决办法
4478
查看次数

如何在重复之前进行Scala控制抽象?

我是Peter Pilgrim.我看过Martin Odersky在Scala中创建了一个控件抽象.但是我似乎还没有在IntelliJ IDEA 9中重复它.它是IDE吗?

package demo

class Control {

  def repeatLoop ( body: => Unit ) = new Until( body )

  class Until( body: => Unit ) {
    def until( cond: => Boolean ) {
      body;
      val value: Boolean = cond;
      println("value="+value)
      if ( value ) repeatLoop(body).until(cond)
      // if  (cond) until(cond)
    }
  }

  def doTest2(): Unit = {
    var y: Int = 1
    println("testing ... repeatUntil() control structure")
    repeatLoop {
      println("found y="+y)
      y = y + 1
    }
    { …
Run Code Online (Sandbox Code Playgroud)

controls abstraction scala repeat

10
推荐指数
4
解决办法
2845
查看次数

标签 统计

scala ×2

abstraction ×1

controls ×1

dns ×1

dsl ×1

repeat ×1

specifications ×1