我是彼得朝圣者。我看到 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
}
{ until ( y < 10 ) }
}
}
错误消息如下:
信息:编译完成,出现 1 个错误和 0 个警告
信息:1 个错误
信息:0 个警告
C:\Users\Peter\IdeaProjects\HelloWord\src\demo\Control.scala
错误:错误:行 (57) 错误:Control.this。类型 Control.this.Until 的repeatLoop({
scala.this.Predef.println("found y=".+(y));
y = y.+(1)
}) 不带参数
repeatLoop {
在 curried 函数中,可以认为主体返回一个表达式(y+1 的值),但是 repeatUntil 的声明主体参数清楚地表明这可以忽略还是不可以?
错误是什么意思?