stephansun对《Groovy for Domain-Specific Languages》的笔记(5)

stephansun
stephansun (认真你就输了...)

读过 Groovy for Domain-Specific Languages

Groovy for Domain-Specific Languages
  • 书名: Groovy for Domain-Specific Languages
  • 作者: Fergal Dearle
  • 副标题: Extend and enhance your Java applications with Domain Specific Languages in Groovy
  • 页数: 240
  • 出版社: Packt
  • 出版年: 2009
  • 第68页

    [勘误] 可能是印刷问题 本页代码中

    [1..9]* each {

    应为

    [1..9]*.each {
    ["three","two","one","liftoff"] each {

    应为

    ["three","two","one","liftoff"].each {
    2013-03-01 10:43:20 回应
  • 第254页

    勘误

    shell.evaluate("on_consume.delegate = this;onConsume()")

    应为

    shell.evaluate("onConsume.delegate = this;onConsume()")
    shell.evaluate("on_purchase.delegate = this;onPurchase()")

    应为

    shell.evaluate("onPurchase.delegate = this;onPurchase()")
    shell.evaluate("on_upgrade.delegate = this;onPurchase()")

    应为

    shell.evaluate("onUpgrade.delegate = this;onPurchase()")

    很奇怪,本章这个示例的代码风格和随书代码里面的代码风格不一样。随书代码里面都是驼峰型变量命名。而书中则是两种风格穿插着,比如书上声明的是onPurchase,结果在shell.evaluate中变成了on_purchase。随书代码中的offers/Offers.groovy中是isVideo,isNewRelease,isGame等等,而在书中则写成了,is_video,is_new_release,is_game,由于书中并没有Offers.groovy的类示例,所以我自己的代码中就改成is_video这种形式了。总之有点乱。另书中加载规则脚本是rewards/rewards.groovy,而不是offers/Offers.groovy。

    2013-03-05 10:58:26 回应
  • 第236页

    [勘误]

    // lookup account in binding
    def account = new Account()
    binding.account = account
    binding.monthSpend = account.spend
    binding.credit = Account.&credit

    应为

    // lookup account in binding
    def account = new Account()
    binding.account = account
    binding.monthSpend = account.spend
    binding.credit = account.&credit
    2013-03-05 15:52:55 1回应
  • 第259页
    void testUpgradeToPlusReward() {
         assert account.points == 120
         bbPlus.upgrade(account,  "PLUS")
         // Should have 250 for PLUS and 100 bonus
         assert account.points == 350
         bbPlus.upgrade(account,  "PREMIUM")
         // Should have 550 for PREMIUM and 100 bonus
         // from the previous upgrade
         println account.points
         assert account.points == 650
       }
    if (account.plan == "PLUS" && newPlan == "PREMIUM")
    			account.points += 300

    实在是想吐槽一下这句『Should have 550 for PREMIUM and 100 bonus from the previous upgrade』,明明是120 + 130 + 100 + 300,意思说的太含糊了。

    2013-05-16 12:42:15 回应
  • 第200页
    When we declare a Groovy method that accepts a closure as its last parameter, Groovy allows us to define the body of the inline closure immediately after the method call containing the other parameters. A method call followed by an inline closure block has all the appearance of being a named block of code. It's when we nest these method calls within each other that we get the distinctive builder-style code block.
    引自第200页
    2013-08-01 20:23:57 回应