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

Actor act() and -Ytailrecommend

6 replies
eric so
Joined: 2010-03-19,
User offline. Last seen 42 years 45 weeks ago.
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
}
}
}


extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Actor act() and -Ytailrecommend

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.)

eric so
Joined: 2010-03-19,
User offline. Last seen 42 years 45 weeks ago.
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 a
reason and might do anything up to and including deleting your whole
source tree and chasing you with a stick.

Actually no, it wasn't.  Apologies. I thought you were rather recommending it here:
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/ *----------

Erik Engbrecht
Joined: 2008-12-19,
User offline. Last seen 3 years 18 weeks ago.
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:
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/
dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
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:
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.
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
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.

eric so
Joined: 2010-03-19,
User offline. Last seen 42 years 45 weeks ago.
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 we
want to make it available in case it's useful, but with zero support.

Fair enough, and point well taken.  I didn't know -Y options were taboo.  Won't ask about them again.

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