This page is no longer maintained — Please continue to the home page at www.scala-lang.org

using continuations with for loops

2 replies
pschaus
Joined: 2012-01-15,
User offline. Last seen 33 weeks 5 days ago.

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

iron9light
Joined: 2009-07-04,
User offline. Last seen 3 years 15 weeks ago.
Re: using continuations with for loops

val i = (1 to 3).iteratorwhile(i.hasNext) {  i.next()  foo()}

Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
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:
val i = (1 to 3).iteratorwhile(i.hasNext) {  i.next()  foo()}

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland