Case Statements

Rustom Mody rustompmody at gmail.com
Sun Mar 20 04:01:26 EDT 2016


On Wednesday, March 16, 2016 at 5:51:21 PM UTC+5:30, Marko Rauhamaa wrote:
> BartC :
> 
> > On 16/03/2016 11:07, Mark Lawrence wrote:
> >> but I still very much doubt we'll be adding a switch statement --
> >> it's a "sexy" language design issue
> >
> > That's the first time I've heard a language feature common in C
> > described as sexy.
> 
> Scheme has a "switch" statement (a "case" form). However, it is slightly
> better equipped for it than Python:
> 
>  * Scheme has an atom type ("symbol"). It corresponds to interned
>    strings and is supposed to be compared by reference.
> 
>  * Scheme has defined three equality operators: "eq?", "eqv?" and
>    "equal?". Python only has two: "is" (~ "eq?") and "==" (~ "equal?").
>    The "case" form makes use of the operator "eqv?" that is missing from
>    Python ("eqv?" compares numbers numerically but is otherwise the same
>    as "eq?").
> 
> 
> Marko

I think it needs to be mentioned:
Almost every modern functional language has pattern matching
And pattern matching is really case statements on steroids

https://www.vex.net/~trebla/haskell/crossroad.xhtml

>From those of us who regularly use functional programming, its important
to say that the things that get big press -- lambdas, monads etc -- are probably
less significant than things like pattern matching that dont

A smattering of languages that support it:

Erlang: http://erlang.org/doc/reference_manual/functions.html
Scala: https://kerflyn.wordpress.com/2011/02/14/playing-with-scalas-pattern-matching/
SML: http://www.cs.cornell.edu/courses/cs312/2004fa/lectures/lecture3.htm
Clojure : https://github.com/clojure/core.match

Scheme is an odd case: Does not have it builtin but writing a macro for that is 
an entertaining exercise



More information about the Python-list mailing list