- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Actor act() and -Ytailrecommend
Fri, 2010-04-09, 21:24
I was playing around with -Ytailrecommend and was surprised it didn't warn me with @tailrecommended in the code below (taken from Odersky et al. "Programming in Scala").
I put @tailrec on act and the compiler complained. I made act final, and the compiler still complained. Ok, act can't have the tailrec optimization? Do I not need to worry about this?
I put @tailrec on act and the compiler complained. I made act final, and the compiler still complained. Ok, act can't have the tailrec optimization? Do I not need to worry about this?
object NameResolver extends Actor {
import java.net.{InetAddress, UnknownHostException}
def act() {
react {
case (name: String, actor: Actor) =>
actor ! getIp(name)
act()
case "EXIT" =>
println("Name resolver exiting.")
// quit
case msg =>
println("Unhandled message: "+ msg)
act()
}
}
def getIp(name: String): Option[InetAddress] = {
try {
Some(InetAddress.getByName(name))
} catch {
case _:UnknownHostException => None
}
}
}
Fri, 2010-04-09, 22:07
#2
Re: Actor act() and -Ytailrecommend
On Fri, Apr 9, 2010 at 1:36 PM, Paul Phillips <paulp@improving.org> wrote:
Well, I hope it's clear that "-Y" options are totally hidden for aActually no, it wasn't. Apologies. I thought you were rather recommending it here:
reason and might do anything up to and including deleting your whole
source tree and chasing you with a stick.
http://article.gmane.org/gmane.comp.lang.scala.user/23239/match=ytailrecommend
What is the last action in that method? It's not a call to act().
Follow the braces. (Starts with r, ends with t, has an act in the
middle.)
--
Paul Phillips | It's better to have gloved and tossed than never to
Stickler | have played baseball.
Empiricist |
i pull his palp! |----------* http://www.improving.org/paulp/ *----------
Fri, 2010-04-09, 22:17
#3
Re: Actor act() and -Ytailrecommend
If you can make a compiler chase programmers around with a stick, I think I know some software process folks who would love to talk to you.
On Fri, Apr 9, 2010 at 4:36 PM, Paul Phillips <paulp@improving.org> wrote:
--
http://erikengbrecht.blogspot.com/
On Fri, Apr 9, 2010 at 4:36 PM, Paul Phillips <paulp@improving.org> wrote:
On Fri, Apr 09, 2010 at 01:24:29PM -0700, eric so wrote:
> I was playing around with -Ytailrecommend and was surprised it didn't
> warn me with @tailrecommended in the code below (taken from Odersky et
> al."Programming in Scala").
Well, I hope it's clear that "-Y" options are totally hidden for a
reason and might do anything up to and including deleting your whole
source tree and chasing you with a stick.
> def act() {
> react {
> case (name: String, actor: Actor) =>
> actor ! getIp(name)
> act()
> case "EXIT" =>
> println("Name resolver exiting.")
> // quit
> case msg =>
> println("Unhandled message: "+ msg)
> act()
> }
> }
What is the last action in that method? It's not a call to act().
Follow the braces. (Starts with r, ends with t, has an act in the
middle.)
--
Paul Phillips | It's better to have gloved and tossed than never to
Stickler | have played baseball.
Empiricist |
i pull his palp! |----------* http://www.improving.org/paulp/ *----------
--
http://erikengbrecht.blogspot.com/
Fri, 2010-04-09, 22:27
#4
Re: Actor act() and -Ytailrecommend
Note that react receives a "() => Unit" (or perhaps just "=> Unit"). Your "act" is just part of a function you passed to "react". The actual last method call on "act" -- and, in fact, the only method on "act" -- is "react".
On Fri, Apr 9, 2010 at 5:24 PM, eric so <ericso2718@gmail.com> wrote:
--
Daniel C. Sobral
I travel to the future all the time.
On Fri, Apr 9, 2010 at 5:24 PM, eric so <ericso2718@gmail.com> wrote:
I was playing around with -Ytailrecommend and was surprised it didn't warn me with @tailrecommended in the code below (taken from Odersky et al. "Programming in Scala").
I put @tailrec on act and the compiler complained. I made act final, and the compiler still complained. Ok, act can't have the tailrec optimization? Do I not need to worry about this?object NameResolver extends Actor {
import java.net.{InetAddress, UnknownHostException}
def act() {
react {
case (name: String, actor: Actor) =>
actor ! getIp(name)
act()
case "EXIT" =>
println("Name resolver exiting.")
// quit
case msg =>
println("Unhandled message: "+ msg)
act()
}
}
def getIp(name: String): Option[InetAddress] = {
try {
Some(InetAddress.getByName(name))
} catch {
case _:UnknownHostException => None
}
}
}
--
Daniel C. Sobral
I travel to the future all the time.
Fri, 2010-04-09, 23:17
#5
Re: Actor act() and -Ytailrecommend
On Fri, Apr 09, 2010 at 01:51:07PM -0700, eric so wrote:
> I thought you were rather recommending it here:
There's no conflict between suggesting people use it and there being no
guarantee whatsoever about what it will do. Really the point is that we
want to make it available in case it's useful, but with zero support.
Sat, 2010-04-10, 00:07
#6
Re: Actor act() and -Ytailrecommend
On Fri, Apr 9, 2010 at 3:14 PM, Paul Phillips <paulp@improving.org> wrote:
There's no conflict between suggesting people use it and there being no
guarantee whatsoever about what it will do.
That's what my heroin dealer keeps telling me :) (sorry, that wasn't polite. maybe a little funny?)
Suggesting people use it conflicts with keeping it "well hidden".
Really the point is that weFair enough, and point well taken. I didn't know -Y options were taboo. Won't ask about them again.
want to make it available in case it's useful, but with zero support.
On Fri, Apr 09, 2010 at 01:24:29PM -0700, eric so wrote:
> I was playing around with -Ytailrecommend and was surprised it didn't
> warn me with @tailrecommended in the code below (taken from Odersky et
> al."Programming in Scala").
Well, I hope it's clear that "-Y" options are totally hidden for a
reason and might do anything up to and including deleting your whole
source tree and chasing you with a stick.
> def act() {
> react {
> case (name: String, actor: Actor) =>
> actor ! getIp(name)
> act()
> case "EXIT" =>
> println("Name resolver exiting.")
> // quit
> case msg =>
> println("Unhandled message: "+ msg)
> act()
> }
> }
What is the last action in that method? It's not a call to act().
Follow the braces. (Starts with r, ends with t, has an act in the
middle.)