Like I said, without a => there's no closure. The for comprehension works because it gets converted into code containing a =>.
A block in a position where a function is expected is just a block whose value needs to be a function. Does that make sense now? I can probably find some specspeak that explains it better if not. On Jul 27, 2012 10:31 AM, "Josh Berry" <[email protected]> wrote: > On Fri, Jul 27, 2012 at 8:32 AM, Ricky Clarkson > <[email protected]> wrote: > > 1 to 10 map { println("Yo"); println } > > > > Yo gets printed once, println happens 10 times. Just because you're > > providing a function doesn't mean you're in a closure. If it was a > closure > > (and certain other magic happened to make it well-typed) you'd see Yo 10 > > times with a blank line between each. > > I'm lost. A closure simply means it captures the local environment, > right? So: > > var y = 0 > 1 to 10 map {y+= 1; println} > println(y) > > Now, I confess I am surprised that it appears this closure is called > once to get a function from Int => Any. I'm assuming it has always > been this way in Scala? > > Of course, this does as expected, and looks similar. > > for (x <- 1 to 10) {y+=1; println("hello")} > > Is this is not a closure, as well? > > -- > You received this message because you are subscribed to the Google Groups > "Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
