How Does One Make Scala Control Abstraction in Repeat Until?

Posted by peter_pilgrim on Stack Overflow See other posts from Stack Overflow or by peter_pilgrim
Published on 2010-06-14T09:11:25Z Indexed on 2010/06/14 9:12 UTC
Read the original article Hit count: 278

Filed under:
|
|
|
|

Hi

I am Peter Pilgrim. I watched Martin Odersky create a control abstraction in Scala. However I can not yet seem to repeat it inside IntelliJ IDEA 9. Is it the 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 ) } }

}

The error message reads:

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 {

In the curried function the body can be thought to return an expression (the value of y+1) however the declaration body parameter of repeatUntil clearly says this can be ignored or not?

What does the error mean?

© Stack Overflow or respective owner

Related posts about scala

Related posts about custom