- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
using continuations with for loops
Fri, 2012-01-27, 10:58
Hello,
I would like to write something like
for (i <- 1 to 3) {
foo()
}
but foo() has a signature def branch(): Unit @suspendable because it
has a shift inside (using continuations).
I've read here http://www.scala-lang.org/node/4276 an answer by Tiark
Rompf explaining that we should use:
import scala.continuations.Loops._ and then use
dir.listFiles.toList.suspendable foreach { f => ... }. Making
.suspendable work for all Iterables is another item on my to-do list,
but for the moment the toList is required.
Unfortunately this package scala.continuations.Loops._ does not seem
to exist anymore :-(
Do you know if there is a replacement or another way to do it?
Thank you in advance,
Pierre
Sun, 2012-01-29, 16:21
#2
Re: Re: using continuations with for loops
That's essentially all the continuation loop support does. Take a look at the generated code though.
On Sat, Jan 28, 2012 at 12:37 PM, IL <iron9light@gmail.com> wrote:
On Sat, Jan 28, 2012 at 12:37 PM, IL <iron9light@gmail.com> wrote:
val i = (1 to 3).iteratorwhile(i.hasNext) { i.next() foo()}
val i = (1 to 3).iteratorwhile(i.hasNext) { i.next() foo()}