Re: What does this mean ?
Clement Dourval <[email protected]> Wed, 17 Feb 2016 16:56:17 +0100
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAOziRyA6Va+fPrp6eoJRAHn4Z1=EfT856mnqN8V65Vbq05XzWA@mail.gmail.com> |
Ok thank you very much for the help. 2016-02-17 16:54 GMT+01:00 Oliver Ruebenacker <[email protected]>: > sounds right. > > On Wed, Feb 17, 2016 at 10:53 AM, Clement Dourval <[email protected] > > wrote: > >> Ok I'm begining to understand : >> the "ping ! Pong" is calling the '!' method and putting a Pong in a >> mailbox. >> And the fact that the other side is continuesly calling the receive >> method is kind of forcing the scan of the mailbox as much as possible. >> Then when the mailbox has a message in it, it feeds the message as >> argument for the partial method >> am i right ? >> >> Le mercredi 17 février 2016 16:22:41 UTC+1, Oliver Ruebenacker a écrit : >> >>> >>> Hello, >>> >>> receive {...} is a call of the "receive" method and short for >>> receive({...}) >>> >>> Best, Oliver >>> >>> On Wed, Feb 17, 2016 at 10:11 AM, Clement Dourval <[email protected]> >>> wrote: >>> >>>> But what does the fact that the "receive" word is not followed by the >>>> '=' sign is meaning ? >>>> receive is suposed to be a function here right ? >>>> is that a kind of averride without having to write the whole signature. >>>> >>>> From where i'm standing, it seems to me that receive is a function with >>>> partial cases depending on the main argument to be Ping typed or other. >>>> >>>> But there is no = sign so what does this mean ? >>>> >>>> Le mercredi 17 février 2016 15:57:49 UTC+1, Oliver Ruebenacker a écrit : >>>> >>>>> >>>>> Hello, >>>>> >>>>> The case keyword creates a partial function, e.g.: >>>>> >>>>> scala> val pf: Int => String = { case 42 => "Hello!" } >>>>> pf: Int => String = <function1> >>>>> >>>>> scala> pf(42) >>>>> res1: String = Hello! >>>>> >>>>> Best, Oliver >>>>> >>>>> On Wed, Feb 17, 2016 at 9:40 AM, Clement Dourval <[email protected]> >>>>> wrote: >>>>> >>>>>> Hi, I'm currently Learning Scala and more precisely, concurrent >>>>>> programming with scala. >>>>>> >>>>>> I found this code : >>>>>> >>>>>> class Pong extends Actor { >>>>>> def act() { >>>>>> var pongCount = 0 >>>>>> while (true) { >>>>>> receive { >>>>>> case Ping => >>>>>> if (pongCount % 1000 == 0) >>>>>> Console.println("Pong: ping "+pongCount) >>>>>> sender ! Pong >>>>>> pongCount = pongCount + 1 >>>>>> case Stop => >>>>>> Console.println("Pong: stop") >>>>>> exit() >>>>>> } >>>>>> } >>>>>> } >>>>>> } >>>>>> >>>>>> This is from a tutorial, so i'm expecting it to work, the only >>>>>> problem is I do not understand how. >>>>>> >>>>>> The main problem is, how does this code use the case keyword since >>>>>> there is no match ! >>>>>> (adress of the tutorial : http://www.scala-lang.org/old/node/242) >>>>>> >>>>>> Anyway, i understood what was the tutorial was supposed to do (with >>>>>> ping pong), I just don't understand what is written, I'd like to be able to >>>>>> write it myself. >>>>>> But it seems i'm missing some syntax subtleties >>>>>> And even if these are deprecated, i found the same synthax with the >>>>>> akka Library ! So I'm asking myself how to read this. >>>>>> >>>>>> Anyone can help ? Thanks in advance ! >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "scala-language" group. >>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>> send an email to [email protected]. >>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Oliver Ruebenacker >>>>> Senior Software Engineer, Diabetes Portal >>>>> <http://www.type2diabetesgenetics.org/>, Broad Institute >>>>> <http://www.broadinstitute.org/> >>>>> >>>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "scala-language" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> >>> -- >>> Oliver Ruebenacker >>> Senior Software Engineer, Diabetes Portal >>> <http://www.type2diabetesgenetics.org/>, Broad Institute >>> <http://www.broadinstitute.org/> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "scala-language" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Oliver Ruebenacker > Senior Software Engineer, Diabetes Portal > <http://www.type2diabetesgenetics.org/>, Broad Institute > <http://www.broadinstitute.org/> > > -- > You received this message because you are subscribed to a topic in the > Google Groups "scala-language" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/scala-language/CHHe5WO3f90/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.