Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: BartC Newsgroups: comp.lang.python Subject: Re: Case Statements Date: Wed, 16 Mar 2016 15:00:32 +0000 Organization: A noiseless patient Spider Lines: 56 Message-ID: References: <30502a2e-0bad-4b0f-a1e8-a2b40b0d7ab9@googlegroups.com> <56E928D4.3000701@rece.vub.ac.be> <56E93ADD.9040500@rece.vub.ac.be> <87vb4md362.fsf@elektro.pacujo.net> <87mvpycx48.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 16 Mar 2016 14:57:28 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="cf45b3961a050227b1103bebc3cbc15a"; logging-data="19877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IWBMMVYNLHc64nv4eQyw7" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: <87mvpycx48.fsf@elektro.pacujo.net> Cancel-Lock: sha1:m4UyLADN1cTJkNJqHEpGHqV01xE= Xref: csiph.com comp.lang.python:105042 On 16/03/2016 14:31, Marko Rauhamaa wrote: > BartC : >> Even Ruby has one. >> case >> when this >> .... >> when that > That's a different topic. Yes but, if Ruby has it, why shouldn't Python? (Aren't they rivals or something?) >> which is exactly equivalent to if this... elif that... (when the tests >> are ordered), with one difference: > That is no different from a chained if/elif. That's what I said, but it's an interesting, more symmetric alternative. > Scheme has this: > (case (die10) > ((1 3 5 7 9) > => (lambda (n) > n)) > (else > => (lambda (n) > (/ n 2)))) > > which maps 1, 3, 5, 7 and 9 onto themselves but halves 2, 4, 6, 8 and > 10. I don't get this; what does the lambda do here? Why not just yield either n or n/2? > As for a chained if/elif, Scheme as "cond:" > (cond > ((windy?) > (fly-kite)) > ((shining? sun) > (go-out)) > ((raining?) > (play-soccer)) > (else > (read-book))) Which is like my Ruby case example. Simple and to the point. (Not sure of the significance of ?) -- Bartc