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

case statement

2 replies
Jiansen
Joined: 2011-04-27,
User offline. Last seen 1 year 10 weeks ago.

Hi,

Does someone know how case statement is implemented in Scala? Is
"case" a primitive keyword or a function in a library? It's
interesting to see that a group of case statements is an instance of
PartialFunction. I would like to know more details about its
implementation.

Thanks in advance.

Jiansen

Kevin Wright 2
Joined: 2010-05-30,
User offline. Last seen 26 weeks 4 days ago.
Re: case statement
It's all in here: http://www.scala-lang.org/sites/default/files/linuxsoft_archives/docu/files/ScalaReference.pdf
Specifically, section 8.5 (page 122)


On 27 April 2011 17:58, Jiansen <jiansenhe@gmail.com> wrote:
Hi,

Does someone know how case statement is implemented in Scala? Is
"case" a primitive keyword or a function in a library?  It's
interesting to see that a group of case statements is an instance of
PartialFunction.  I would like to know more details about its
implementation.

Thanks in advance.

Jiansen



--
Kevin Wright

gtalk / msn : kev.lee.wright@gmail.comkev.lee.wright@gmail.commail: kevin.wright@scalatechnology.com
vibe / skype: kev.lee.wrightquora: http://www.quora.com/Kevin-Wright
twitter: @thecoda

"My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra
Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: case statement

On Wednesday April 27 2011, Jiansen wrote:
> Hi,
>
> Does someone know how case statement is implemented in Scala? Is
> "case" a primitive keyword or a function in a library? It's
> interesting to see that a group of case statements is an instance of
> PartialFunction. I would like to know more details about its
> implementation.
>
> Thanks in advance.
>
> Jiansen

It's not library functionality. "case" is a reserved keyword and has
significant portions of the compiler devoted to it and its many forms.

The treatment of a block of cases (when not used with "match") as a
PartialFunction is likewise a special case of a Function literal
handled by the compiler.

The "Compiler Corner" and "Compiler Corner Reloaded" are good starting
points for information on the implementation of the Scala compiler.
It's not a simple thing...

Randall Schulz

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