Soy Peter Pilgrim. Vi a Martin Odersky crear una abstracción de control en Scala. Sin embargo, todavía no puedo repetirlo dentro de IntelliJ IDEA 9. ¿Es IDE?¿Cómo se puede hacer Scala Control Abstraction in Repeat Until?
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) }
}
}
El mensaje de error lee:
Information:Compilation completed with 1 error and 0 warnings
Information:1 error
Information:0 warnings
C:\Users\Peter\IdeaProjects\HelloWord\src\demo\Control.scala
Error:Error:line (57)error: Control.this.repeatLoop({
scala.this.Predef.println("found y=".+(y));
y = y.+(1)
}) of type Control.this.Until does not take parameters
repeatLoop {
En la función de curry el cuerpo puede ser pensado para volver una expresión (el valor de y + 1), sin embargo el parámetro de cuerpo declaración de repeatUntil dice claramente esta puede ser ignorado o no?
¿Qué significa el error?
Agradable. Me gusta el objeto de función anónima. –
se llama tipo estructural –
¿Por qué intentar/atrapar cuando puedes 'do {body} while (! Condition)'? –